![]() |
|
#1
|
|||
|
|||
Poker program code problemI must write a program that will figure out the value of a hand of 3 cards. I can use if statements, and if else, and other things of that nature. I must generate three random numbers, for the 3 cards, while making sure they are not duplicates....then i must find a way to label the cards by rank and suit somehow, from 1 - 52. The program should function like a poker game, the user is dealt three random cards, and it should tell the user what type of hand they have (straight, flush, etc.)....And I must loop the whole thing so the user can elect to play again.
I am a beginner so i do not kno much about c++, and im struggling with this one greatly, i have to get it done within 24 hours, and im lost right now. What i have been able to do: write if statements that print to the screen saying, card 1 is this suit, and then later saying, card 1 is this rank. i dont know how to combine them saying, card1 is a 2 of hearts, etc. I thought i would have trouble with determining the different hands, such as straights and stuff, but i havent even got that far...i just have a mess of code testing the waters to see wut i kno how to do.... if necessary, i will post my code, but i wont unless asked because it is not close in any manner to being what i want it to be. Please, some advice? clues? Im really lost, and time is of the essence. Thanks in advance for all those who will be helping me here. |
|||
|
#2
|
|||
|
|||
Re: Poker program code problemQuote:
I recently wrote a PlayingCard class implementation for representing a playing card. For brevity and simplicity, I combined everything into a single file, but it may be helpful for you to see it. CPP / C++ / C Code:
Comparing cards in a "HandEvaluator" class is not difficult. Let me know if you need more help. In this code, if you want to add a random hand generator, simply: CPP / C++ / C Code:
Output: Code:
:davis: |
|
#3
|
|||
|
|||
Re: Poker program code problemthe second coding sections was more my speedin terms of technique. the first part is way too advanced for me. Thats part of the problem, its this huge complicated program, and all we can use is the very basic stuff like if or if else statements. And on top of that, once we get the hands like you did, we have to tell what type of hand it is somehow, like a straight, or 3 of a kind, etc.
thanks for your initial post....any advice? |
|
#4
|
|||
|
|||
Re: Poker program code problemQuote:
I understand the requirements. My advice is to plan better so that you have more time (than 24h) to solve the problem...I can write the code easily using nothing but simple coding techniques and just a single character per card. The logic for evaluating a hand is relatively simple, but you can not have a straight in 3 cards, since a straight is 5 cards...unless you want to modify the rules of poker to accept that only 3 cards are used for all hand qualifications. An easy approach is to decide whether or not a hand is a straight, flush, straight-flush, three of a kind (no four of a kind, full house or two pair possible in 3 cards), pair or high card or tie. The key is in setting up your "filtering" so that you assign a value to each hand that corresponds to a possible hand. Then you compare whether or not the hands of the other players exceed, are equal to or are less than the value of one of the player hands working through until you get the best hand (or a tie) between all of the players/possible hands that must be evaluated. It isn't very difficult. I can easily write it, but probably not within the next few hours or maybe not even today as I have other things that I need to do very soon. I would expect such a simple implementation to start out something like: CPP / C++ / C Code:
...though an multi-dimensional array for the number of players would also work well and probably make the evaluation operation easy to write. :davis: |
|
#5
|
|||
|
|||
Re: Poker program code problemthanks davis, i got it done (hopefully its correct haha)..
i appreciate the response |
|
#6
|
|||
|
|||
Re: Poker program code problemQuote:
Well then, let's see it! :davis: |
|
#7
|
|||
|
|||
Re: Poker program code problemkeep in mind, some things could have been completed much easier using other techniques, but i was forced to use if statements haha
Code:
|
|
#8
|
|||
|
|||
Re: Poker program code problemQuote:
Card1 is an ace of clubs Card2 is a jack of clubs Card3 is a nine of hearts Second card is the high card Play again? (Type 1 for yes) ...oh well, close :davis: |
|
#9
|
|||
|
|||
Re: Poker program code problemo jeez, i forgot...thats bad....i forgot to code in there that ace can be high or low...
|
|
#10
|
|||
|
|||
Re: Poker program code problemQuote:
Don't be put-off by such a bug...I have a hand-held Texas Hold'em device that constantly out-ranks: A-2-3-4-5 ..over: 2-3-4-5-6 That is, a "baby straight" is higher than a higher-card straight due to the ace. It is an incredibly annoying bug considering that this is a commercial product, but then again, so is Windoze! :davis: |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to sort random access file? | wmmccoy0910 | C Programming Language | 12 | 04-Sep-2006 03:40 |
| Bloodshed Dev C++ Project Options | JdS | C++ Forum | 6 | 11-Nov-2005 17:23 |
| Problem with int mixed with char,... | leitz | C++ Forum | 17 | 07-Dec-2004 20:56 |
| problem with the program under Borland | awmp-jansen | C Programming Language | 3 | 01-Jul-2004 17:05 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The