My approach for this project is going to be a bit different from how I approached the Minesweeper project. Instead of learning about algorithms for the game and basing how I play on those, I’ve spent some time just playing game after game of Gin Rummy and will be translating what I’ve learned from there into an algorithm.
There are two major decisions that need to be made each turn in Gin Rummy. I plan on making my AI focused on two major ideas: choosing what to discard and choosing from which pile to draw.
The containing class I write for the AI will have at minimum:
- A list of cards in hand
- Each will have a value associated with it based on how many deadwood points it’s worth, and how close to a meld it currently is
- A list of cards in the discard
- This will allow me to toss melds that I have less/no chance of making
- A list of cards still in the deck
- This allows for decisions to be made based on probability of drawing a card that completes a meld
- Two major decision making functions
- One for choosing which pile to draw from
- One for choosing what card to discard
The decision to discard a card should be simple as long as the AI keeps up with the current game state, as each card in hand will have a value associated with it based on how many points it will cost to still have as deadwood, and how likely it is to be used in a meld.
Drawing should also be simple, I just need to check for each card still in the deck, if on average, it yields a better result than taking the top card from the discard pile.
If you want to keep up with current progress in the AI, feel free to check out the github project.