For my semester project I decided to make a card game called Ninety-Nine. I wanted to make the program for Android and use the Monte Carlo search algorithm for the AI.
After doing some research I decided to change my AI algorithm.
The algorithm is a simple algorithm, it sorts its hand based on the strategic value and chooses the first legal card. If the presorted hand is KH 7S 9C then the sorted hand would be 7S 9C KH, if the score plus the potential card is less than or equal to 99 then it plays it if not it moves onto the next card. If none of the cards are legal it returns the first card. After doing some testing I found that this algorithm does a fairly good job of playing the game.
At the beginning of the game, three tokens are distributed to each player. Each hand, three cards are dealt to each player, and the player to the left of the dealer takes the first turn. He chooses one of the cards in his hand, places as a discard pile, calls out its value, and then draws a new card. The player to his left then chooses one of her cards and places it on the discard pile, adds its value to the previous card and calls out the new total. If a player forgets to draw a new card before the next player plays, that player must remain one card short for the remainder of the hand. Play proceeds in this manner until a player cannot play without making the total value greater than ninety-nine. That player must turn in one of his or her tokens, all cards are then collected and a new hand is dealt. Any player without tokens loses and is out of the game, while the last player remaining with token wins.
Above is a screenshot of the current game. Player 1 is the human player and Player 2 is the AI. After each card is played it prints who played what card and updates the score. When it is the human players turn it prints out the players cards and asks them to choose a card. It will keep asking them to choose a card until it finds a matching card.
4 value is 0 and play is reversed
9 value is 0
10 value is +10 or -10
Jack and Queen values are +10
King sets the total to 99
Ace value 1 or 11
The rest are face value
I have the logic part figured out and the next thing that I want to complete is the Android side.
The picture is the concept of what I want the app to show. It displays the players name, tokens remaining, the hand (shows the cards of the human player and backs for AI), the deck, the current score, the top card of the discard pile, and an arrow showing whose turn it is.
List of things to be done with the game:
– Increase the number of players
– Allow users to pick number of opponents
– Allow users to play against friends
– Add different levels of AI difficulty
– Fine tune the easy AI algorithm
– Add different values of cards based on number of players
– Add levels of difficulty (experiment with algorithms)
The game was fun to program, but I wish that I had more time to work on it before the end of the semester. I plan to continue work on the game during the summer. I spent a little too much time trying to decide on the AI algorithm and implementing it. My source code can be found here. Unzip the file and import the project into Eclipse.
http://users.dickinson.edu/~braught/courses/cs132f01/classes/code/DeckOfCards.src.html – modified for my DeckOfCards class
http://users.dickinson.edu/~braught/courses/cs132f01/classes/code/CardSuit.src.html – used for my CardSuit class
http://users.dickinson.edu/~braught/courses/cs132f01/classes/code/CardRank.src.html – used for my CardRank class
http://users.dickinson.edu/~braught/courses/cs132f01/classes/code/PlayingCard.src.html used for my PlayingCard class modified to include the strategic value of a card
http://www.jfitz.com/cards/ used for the card images