My next task in my Artificial Opponents class is to construct an AI for Gin and Rummy. If you haven’t played Gin and Rummy, it’s a card game that can be a bit much to grasp at first – but gets really easy once you pick it up. For the unacquainted, you can familiarize yourself with the game’s terms and rules here: https://cardgames.io/ginrummy/
The General Plan
I plan to use a value based AI, where I construct an algorithm that sees the possible options available to it, assigns a value to them, and then proceeds to pick the option that has the highest value. Gin and Rummy has two different actions the player has to worry about – choosing whether to draw from the deck or discard pile, and choosing which card to discard.
Step 1 – Drawing
There are two main things I want to look out for in this phase. First of all, I want to check if the card in the discard pile contributes to any of my potential matches. If it does, I will most likely want to add it to my hand.
That Jack might help.
However, if a lot of turns have passed, I may not want to add a card to my hand if it’s value is too high unless it fully completes a match in my hand. I’d hate to be waiting on a third jack, get knocked, and have to give up a lot of points that I could’ve discarded earlier. Keeping track of what cards have already been discarded will definitely play a part in this as well.
Step 2 – Discarding
For this step, the higher the value is, the more I want to discard the card. Any cards that are part of a match will most likely have the lowest value. Any cards that are forming part of a match will probably be somewhere in the middle, depending on how many points that card is worth (the more points a card is worth, the more dangerous it is to have in your hand). Lastly, any cards that aren’t really contributing at all will probably have a very high value and be the first ones to be discarded. It’s worth noting that keeping track of the discard pile will probably have an effect on calculating the values of the card.
Gin and Rummy is a very luck based game, so writing the perfect AI for it isn’t really possible. However, I think my general plan of prioritizing matches, while keeping track of the discard pile in order to calculate the likelihood of forming a match with a particular card will hopefully get my AI a pretty decent win rate.