I have started trying to make a simple poker game, but have hit a big problem, i have no idea how to make it recognise the different hands in poker and then say which is best, this is easier for ones like high card, but for things like straight flush i have no clue. Please help
Offline
Hm - I have no idea what kinds of hands are involved in Poker, but I'd imagine it's something like Yahtzee. Take a look at my Yahtzee project for some quick reference, but be warned that cards are a largely different media.
Offline
I would represent each card as a two-letter pair, i.e. QS for queen of spades or 7C for seven of clubs. Each of these card strings (which could be put into lists to represent a hand) contains both the suite and value of the card, identifiable using the (letter () of []) block. I would recommend sorting the list lowest to highest -- this could be tricky but you should be able to look at Jens' project Sort for examples. Now, finding pairs and threes-of-kind should be pretty easy; just look for duplicates in the hand list. With a straight, just keep checking the next card in the list to see if it is one higher than the last. A flush is simple: take the first card in the list and make sure the rest of the cards are of the same suite. Finally, you should store all this info for when it comes time to check who has won. I hope this post made some sort of sense -- I'm typing on my iPod so it's do
Ifficult to be coherent.
Offline
Maybe if you put a special color code on each of the cards and made a sensor or a couple that went over each of the cards in your hand, it could determine what your hand is. For example, the cards from 2 to Ace each have seperate colors, so the system knows if it's touching red white and blue for example, you've got these 3 cards in your hand. It'd be tricky though if you have doubles. Maybe have a 3 of a kind censor, a 4 of a kind censor and a regular censor somehow? Also having something to arrange the cards in order from lowest to highest in your hand might work.
Offline