Rummy's plays are rather multi-dimensional which can make for complicated AI.
First I'd start by creating the game, THEN create the AI.
Better would be to create a game with simpler plays. Lets say for instance 'go-fish'. Create a 'go-fish' game, then write the AI for that which is rather 1-dimensional (just looking for pairs, remembering what cards have been requested).
Rummy AI is going to basically work like this though...
first you'll have the rules defined for what is a successful play. Those plays will be ranked by score (how many points they earn).
Now every time the AI takes a turn it'll analyze its hand and look for potential plays with in its hand. Each card that has a potential for a play with in its hand gets ranked, the more plays it can be part of the higher its rank. The card with the lowest rank will be the discard for that turn (this card might change over the turn).
Now the AI will analyze the discard row (depending on rules of game, some people have different rules for Rummy). It will again rank each card, as it descends down the row the rank of the card is reduced. Ranks can increase if multiple plays can be had by picking up it with cards before it. The random draw card gets a constant rank, whichever with the highest is drawn.
Analyze hand again with new cards in hand. Lowest ranking will be discard... but first.
When a play is actually available in hand it too will be ranked. All plays in hand will be ranked with the highest being played. Note, to create some realism with the AI you might compare play ranks to potential play ranks. For example the ace is worth more played as QKA than played as A23. If the AI notices it has a KA and a A23, you might rank the KA higher than A23 so that it actually holds out on that play until a Q is available.
Oh and you should probably put in analyzing played cards as well to reduce rankings of each card and play. A ranking of a AA pair would turn 0 if the other two aces are already played (no chance of a 3 of a kind). Or there's no reason to hold out for that queen in the KA scenario if the queen is already played.
Perform plays that are available and ranked high.
Reanalyze yet again (hand has changed).
Discard lowest ranked card.
- come read my blog!
If you want to know how to program, take a math class, take a lot of math classes!
Last edited by lordofduct; 05-28-2012 at 02:59 PM.