Showing posts with label Gin Rummy. Show all posts
Showing posts with label Gin Rummy. Show all posts

Friday, October 21, 2016

Gin Rummy Postmortem Analysis Post

The Gin Rummy tournament happened on 10/21/16. I wanted to win the whole tournament, but I only thought my AI would get to the final four. I took second place in the competition. Second place is good but I only lost by 3 points, so my AI and my opponent's AI were very close in skill.

The day of the tournament I had high hope that my AI would be a contender. I was right because the first match, my AI shutout the opponent. I kinda feel bad for that, but I made my AI to be as best as possible.

I think the only way I could have tried to improve my AI is to improve what card it discards. It first checks a vector is to see if there are any useless cards in my hand. This would include a 6 of clubs, if it had nothing that can use that card. Then it checks to see if it has any cards in the discarded vector. This would include if it had a two pair and the other cards are in the discard pile. It can't use them so it will discard them. If both those vectors are empty. It starts to discard the highest valued card form the incomplete run vector. Then the highest value card of the two pair vector. So maybe if the AI picked the highest value card that was in a combined incomplete run/two pair vector. This way my hand would always try to have the lowest score. Although it might just mess up my algorithm and loss more often.

Monday, October 10, 2016

Gin Rummy Code Report

When making a Gin Rummy AI, there are two ways to go, make it simple or make it complex. I chose the latter. There are really only two choices to make, what pile to pick up from and what card to discard. It is hard to test to see how good the AI actually runs because the default AI just throws out the highest value card. Although my AI did beat it.

The AI algorithm I used was very similar to the one I mentioned in the planning post. The first decision that the AI has to make is what pile to pick up from. Using the knowledge of the top card in the discard pile. It can make the intended choice. In my algorithm my AI will only pick up from the discard pile. If the card will complete or continue a completed run/set. This way if the opponent is trying to use probability on my hard. It would be useless. It is also better to pick from the deck instead of the discard pile. It could give you and your opponent potentially more helpful cards. These cards are unknown unlike all the known cards of the discard pile

The second decision my AI has to make is what card to discard. It am utilizing a vector to keep track of all the cards in the discard pile. This way it can make logical decisions. It won't try to keep two kings if the other two are in the discard pile. This vector is the most important part of my discard algorithm. 

When it calls the function to decide a card to discard. It removes all the completed sets/runs first. Then it checks to see if it has two cards of a set. If it has two cards it checks to make sure the other needed cards aren't in the discard pile. If they are, it adds the cards to the potential discard vector. If they aren't in the discard pile. It adds the cards to the two card set vector. When it is finished going through all the cards in the hand, excluding completed runs/sets, it removes the two card set vector from its hand. It then go through the same process looking for runs. It is a little bit different because the AI has to see if the card it is missing is in the front, middle or end. Once it runs through all of the cards in the hand,excluding completed runs/sets, it removes the valid two card runs from its hand. 

Then it picks the card with the highest point value from the remaining cards. If there is no remaining cards left in the hand after removing the completed run/sets and the almost completed run/sets. Then it picks the highest value from the potential discard vector. If that vector has zero elements. Then it checks the two cards run/sets vectors. If those fail, the AI probably has gin rummy but my AI knocks as soon as the total hand score is less than 10.

Sunday, September 25, 2016

Gin Rummy Planning Post

For this assignment we have to make an AI to play gin rummy. Since I have never played gin rummy, I had to look at tutorials. I have however played rummy and rummy 500 before so I knew the basics of these types of card games. 

The AI will use a vector to keep track of all the cards in the discard pile. It will mostly pick up from the deck, it will only pick up from the discard if that card completes a run/set or adds to a completed run/set. In gin rummy games, picking up from the discard pile is not advised because it tells the other player more cards in your hand. So instead of having ten unknown cards you only have nine. Using this knowledge, your opponent can make educated guesses on what cards you are looking for or what cards you hold and alter the cards that he or she will discard. Since I don't know if other peoples AIs will using this knowledge to their benefit. My AI will only be picking up cards that are guarantee to help.

Since my AI is keeping track of the discard pile it can make educated decisions with what card to discard.  Since a game of gin rummy can end at any time, it would be wise to keep the lowest score in your hand at all times. So it will discard the highest valued, useless card. An example would be my hand is [King of hearts, King of diamonds, Jack of spades, 10 of diamonds, 5 of hearts, 4 of spades, 4 of hearts, 2 of spades, 2 of clubs, 2 of diamonds]. Providing that there is no kings in the discard pile, my highest values useless card is the jack, then the 10. If the discard piles has 6 of hearts and a 3 of hearts it will discard the 5 of hearts if it is the highest useless card. Then if the total number of deadwood in my hand is less than 10, the AI will knock ending the game.