Game Development Community

dev|Pro Game Development Curriculum

teaching my computer to play cards

by J Sears · 04/23/2007 (2:41 pm) · 3 comments

I finally decided to get back to work on a project I'd like to really see put out there. It's a different card game then most people are familiar with and I've put what I consider some improvements into it. I will put the rules in a future post when I get closer to finished.

So far I've been focusing on the single player aspect of the game, getting the gameplay to work and getting some decent AI in place. The gameplay is running very smoothly. The AI surprises me sometimes because in order to keep from writing a million lines of script to get it to play perfect cards (which also may not be fun for beginner players if the AI was just stomping them down) I sat around for a few days and wrote down how I think when bidding on the hand and when playing through the hand.
The trickier thing about this card game is the amount of cards delt out each time is different and the Trump suit is different each time, sometimes there is no trump and sometimes the trump is dealer's choice (if your familiar with Up and Down the River or F**k the Dealer you'll be familiar with the concept with the exception of dealers choice for trump). It actually made me wish some times I was writing AI for spades since in that one there's always the same amount of cards and with all the cards being out there you can say simply bet on any Aces bet on some Ks etc etc.

So I took my thoughts and tried to figure out some nice and hopefully easy ways to do AI (I use AI in the sense that most people do on here in that it doesn't actually think it just goes through all the ifs, cases, elses etc to find the right choice). I came up with some good rules to help define how to make their choices and broke it up between bidding and playing. On the biding it takes into consideration which position it's in (first middle last), if with his bid the number of bids will be more equal to or less then the amount of hands for the round (for middle position I figure out what the average share of the bids should be his and work off that so for instance 3 players 9 cards his average share would be 3 and then I adjust based on bid total so far etc). It then counts how many bids would be possible in a perfect situation based on his cards and adjusts based on the parts listed above.
I realised early on that the first few hands don't fall into the general rules of all the other hands so I wrote specific script for hands 1 and 2 and then from hands 3 on it uses the general rules. It's interesting really because all the script for hand 2 is longer then hand 3+ since it's so specific to all the possibilities.

Then I went into the playing part which took a lot more lines of script then the bidding. It doesn't have a specific rule for any hands like the bid does and uses the very long script based first off position then off over, even or under bid, then if he has his bid or not and then specifics.
I found the fact that there are special cards in this, I had to have specific script for the case that one of those cards is ever played by someone else. Luckily there's only a couple types of special cards.

So I wrote all this over a couple days and though man this is so generalized that it's never going to play well. Since for a human every time you bid,play a card so many thoughts go into which card to play based off everyone's bid, everyone's score and which cards have been already played, etc.
But to my surprise after running it a few times (to keep taking the way too many bugs out) it plays pretty good, and that's with me cheating because I have it set up so I can see what cards the computer players have so I can see if I agree with their choices.

Currently it's working for a 3 player game, but it won't take much adjustment for a 4, 5 ,6 person game since position 3 will become last position for any game, and most of the current position 3 or 2 script depending on the situation will copy right into the middle position section.

Eventually I think I might add card tracking into the AI so that it knows that if an A was already played it's safe to play the K now etc. I think that is perfectly fair since humans do that anyways and it will make for tighter competition. I might add that in as just a choice between beginner AI or advanced so people can play at their own level.


Now I know most of that is pretty boring but I'm happy about it. Right now I'm going to switch my focus onto making the game more pretty/closer to it's final look. Currently it's a black background and the cards are just there, there's no animation for dealing or playing a card they just pop to their new positions. I wasn't worried about those things yet since I wanted to get the gameplay down so now it's onto that.

The animations I think will be a little bit of a pain because I will want the cards to get delt from the center and go to each player and then show them getting a stack of cards and then the cards flip over for the human play once he has them all. Currently the cards already get sorted by suit on deal so that's already taken care of.
I also have to get a nice looking GUI going and some better graphics overall. Currently the gui is just the grey pulldown menu for choosing your bid and it looks very crappy.


Finally once I get single player working with 3-6 players and have it looking nice/close to finished look. I am going to add the multiplayer part. Which I'm hoping won't be that much work but we'll see. I want the person's card to always be bottom middle of the screen for every person playing so I think that will be the trickiest part.



I'm hoping some people will be interested in this when it's done. I don't think card games on the computer are exactly a big market (unless it's poker). I checked yahoo games and msn games to see how many people were online playing cards and between spades, hearts and bridge between both sites there was about 14000 people online at one time so that is promising but those are also about as well known as you can get for card games.

I'd also like to thank the people who have helped me in the forums on this, there have been many but David Higgins has popped up almost everytime I've had a question and always had a good answer.

#1
04/23/2007 (3:46 pm)
J, your very welcome, and I'm extremely eager to try this out when it's done.

#2
04/23/2007 (4:01 pm)
Sounds cool.. can't wait either to see how it comes out. Will the source be available for those who want to mod your game? Just wondering cause I know Id love to see it since I'm working on a hand and foot type game myself for my wifes red hatter group who plays it all the time. Good luck and please keep us updated...

Will
#3
04/23/2007 (8:28 pm)
Well I had to look up what hand and foot was had never heard of it, looks to be a complicated game. After I've finished this I could try and help with parts you needed. Ok I'll admit I had to look up what a red hatter group was also. Learn something new everyday