1 Replies - 2301 Views - Last Post: 23 September 2008 - 01:44 AM Rate Topic: -----

#1 nwd5015  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-September 08

Reading poker hands in from text file and determining winner

Posted 22 September 2008 - 09:40 PM

I have been working on this and I'm not sure how I can use what I take from my .txt file and use it in the rest of the code. The specifics for what I am trying to do are.... reads poker hands 2 at a time, and determines which player has a better hand. I feel comfortable figuring out how to write the code determining which player has a better hand but I am unsure how to get the actual card values from my .txt file. Here is what I have.....

public class Main 

	private static void OpenFile()
		// will store the cards read from the file
		 List<String> Hands = new ArrayList<String>();
		 BufferedReader br = null;
			// attempt to open the Hands file
			 br = new BufferedReader( new FileReader( "Hands.txt" ) );
			 String card;

			// loop and read a line from the file as long as we dont get null
			 while( ( card = br.readLine() ) != null )

			// add the read card to the Hands
			 Hands.add( card );
		 catch( IOException e ) 
				// close the file
			 catch( IOException ex ) 

		// initialize a new string array equal to the size of the hand
		 String[] cards = new String[ Hands.size() ];

		// call the Hands's toArray method to and transfer items from
		// Hands to our string array cards
		 Hands.toArray( cards );

		// loop and display each card from the cards array
		 for( int i = 0; i < cards.length; i++ )
			 System.out.println( cards[ i ] );

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Reading poker hands in from text file and determining winner

#2 Unknown Hero  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 51
  • Joined: 04-September 07

Re: Reading poker hands in from text file and determining winner

Posted 23 September 2008 - 01:44 AM

First of all, you have to know what you have written in that .txt file. You can have written 13-Spades for king of spades, or you can have it written in 10 other ways. Now that you know how the cards are written (you can determine which card is in a string), you can make new class representing a single Player.

Now, you'll have:
Player[] players = new Player[numberOfPlayers];
for (0 TO nrOfPlayers)
players[i] = new Player(cards);

Now you can for each player determine how strong cards he has. You must remember the number of player that has the strongest cards and what cards are those.

How to determine which player has strongest cards?
Start with first player and by elimination from Royal Flash to One Pair (or High Card), try to find what does the player have in hand.

Hope I helped...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1