Card game AI
Hello all. I'm working on a card game. The game itself is pinochle which was our family game and now that I'm out on my own I'd kind of like to be able to play it myself which is the impetus to making the game.
The non-ai aspects of the project are coming along nicely. However, I have zero experience with ai theory, practice, or programming. I'm assuming from wandering about the archives here and a few google searches that the type of implementation I might be looking toward is a Finite State Machine (as does seem to make sense as there are finite situations to be involved in in a card game).
My knowledge is so limited that I don't have any specific questions at the moment. However, I would generally like to ask if the FSM is the type of thing I'm looking for and can ya'll point me in the direction of a few decent websites/tutorials? I've found a few places but I thought I'd ask and see if you guys had strong recommendations or if there's stuff I've missed.
Less importantly but if someone feels like spending the time I would ask how something like an FSM is generally implemented within the program and are there any examples I could have a gander at?
Thanks for your help.
i'm actually not too familiar with that game but most card games will either require a minimax algorithm, probability, or both.
you won't be needing a finite state machine. i say that still not knowing how to play that game but i think it's safe to assume that for most card games. FSM's are more for creating complex character behavior. in this case, you are just making a computer make moves for a game, not stalking and killing an enemy...that sort of thing.
you won't be needing a finite state machine. i say that still not knowing how to play that game but i think it's safe to assume that for most card games. FSM's are more for creating complex character behavior. in this case, you are just making a computer make moves for a game, not stalking and killing an enemy...that sort of thing.
I'll look into that, thank you. I am sadly ignorant regarding this entire area. The problem I'm having finding information is that I don't really know what I'm looking by name or implementation, etc. Any push in the right direction is helpful.
i google'd pinochle real quick and found the description that it was a trick taking game. that could probably be done by pure probability and some hard coding. depending on how many decks you are playing with, you could teach the AI to count cards and base the probability that the next card he lays will be beat.
to learn more about minimax just google it. you can find real simple tutorials with its use on tic-tac-toe. but it is even complex enough to be used in a game like chess.
is this game similar to the game pitch? if so i could probably give you some pseudo-code. i play pitch all the time.
to learn more about minimax just google it. you can find real simple tutorials with its use on tic-tac-toe. but it is even complex enough to be used in a game like chess.
is this game similar to the game pitch? if so i could probably give you some pseudo-code. i play pitch all the time.
Quote: Original post by wordsmith
My knowledge is so limited that I don't have any specific questions at the moment. However, I would generally like to ask if the FSM is the type of thing I'm looking for and can ya'll point me in the direction of a few decent websites/tutorials? I've found a few places but I thought I'd ask and see if you guys had strong recommendations or if there's stuff I've missed.
Less importantly but if someone feels like spending the time I would ask how something like an FSM is generally implemented within the program and are there any examples I could have a gander at?
FST are extremely easy to implement using simple "switch" or "if" statements. I assume you are asking about FSTs and transition tables similar to these:
http://staff.washington.edu/~jon/z/fsm.html
Suppose we have a transition table with STATES (A,B,C,D) and EVENTS (1,2,3,4) like this:
EVENT: 1 2 3 4STATEA - B - CB C - - DC - - - -D A - C -
To code this you just need a current STATE, an EVENT, and a list of RULES. The list of rules will just be a switch statement. I'll implement the table above:
int EVENT;char STATE = 'A';while(1) // loop continually to process events{ // get next event switch(EVENT) { case 1: if(STATE=='B') STATE='C'; else if(STATE=='D') STATE='A'; break; case 2: if(STATE=='A') STATE='B'; break; case 3: if(STATE=='D') STATE='C'; break; case 4: if(STATE=='A') STATE='C'; else if(STATE=='B') STATE='D'; break; } // check if we are done? then exit loop}
Anyway, nothing too complex at all. At each state change you want the AI to do something. If you like you can store your state machine as a text file so you can change the game AI without recompiling.
Card games are something a computer player can do better than a human player. The AI can remember all cards on the table, and deduce all cards and combinations/point-taking tricks that could be in opponant's hand.
--"I'm not at home right now, but" = lights on, but no ones home
Quote: Anyway, nothing too complex at all. At each state change you want the AI to do something. If you like you can store your state machine as a text file so you can change the game AI without recompiling.
Thanks for the advice, link, etc. I will poke around and experiment with some stuff. See what I can come up with.
Quote:
is this game similar to the game pitch? if so i could probably give you some pseudo-code. i play pitch all the time.
I checked out the wikipedia article for pitch but frankly I have a heck of a time understanding card games just be reading the rules. So, a brief run down on Pinochle.
There are variations of course but I'm thinking of a four handed game with two partnerships.
There is bidding.
Melding is the next step. (These are combinations of cards in your hand that are worth various amounts of points toward making your bid.)
Whoever won the bid (called "opening") selects trump and places the first card. Play then continues in succession. Whoever wins the trick has the lead to play the first card of the next one. Everyone must follow the suit of the lead if they can. If they cannot then they play a trump. If they have no trump then they can just toss any old card on there.
Pinochle is played with a deck of 48 cards. The cards are Ace (high) - 9. There are two of each card in the deck. The order of superiority goes from Ace-10-King-Queen-Jack-Nine. Only the Ace, Ten, and King cards are worth points in the trick toward making your bid. If two cards of the same rank are played in the same trick whichever card was played first will count toward determining who wins the trick.
I hope that was vaguely comprehensible. Thanks to both of you for your time. Much appreciated.
i also have trouble trying to understand card games by just reading the rules online. is there any card switching or drawing from the deck in your version of the game?
i read up a little bit more on it and i can see that different combinations are worth different points, different ranks if you will. this is similar to poker in the fact that your strategy should be based on the odds that you have the best hand, or if not the best hand, the odds of the cards you can get to make the best hand.
if you want to get started on it, have the computer keep track of a 2d array. 4 rows by however many cards each player gets (i.e. if each player gets 6 cards the array should be a 4 X 6). this is so that the computer can count cards if you choose to allow the computer to do that. if you want to make the computer "dumber" you can have it remember 3 random cards from each player...or only remember who has cards of high value and which cards they are.
secondly, you should develop a function to determine the odds that your hand is the best hand (for bidding purposes). for an example in texas hold'em poker, if i hold pocket 7's before the flop and there are 3 people in the game i would create a function to determine if my odds are better than 33% (if i just wanted to act based on having a higher advantage) or better than 50%, or better than x%. you can make the x variable so that the computer adds variance to its strategy.
that's all i can offer you right now without ever playing the game.
i read up a little bit more on it and i can see that different combinations are worth different points, different ranks if you will. this is similar to poker in the fact that your strategy should be based on the odds that you have the best hand, or if not the best hand, the odds of the cards you can get to make the best hand.
if you want to get started on it, have the computer keep track of a 2d array. 4 rows by however many cards each player gets (i.e. if each player gets 6 cards the array should be a 4 X 6). this is so that the computer can count cards if you choose to allow the computer to do that. if you want to make the computer "dumber" you can have it remember 3 random cards from each player...or only remember who has cards of high value and which cards they are.
secondly, you should develop a function to determine the odds that your hand is the best hand (for bidding purposes). for an example in texas hold'em poker, if i hold pocket 7's before the flop and there are 3 people in the game i would create a function to determine if my odds are better than 33% (if i just wanted to act based on having a higher advantage) or better than 50%, or better than x%. you can make the x variable so that the computer adds variance to its strategy.
that's all i can offer you right now without ever playing the game.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement