Advertisement

Help with card game AI

Started by November 24, 2010 11:44 AM
4 comments, last by mattmrunson 13 years, 11 months ago
Hi,

Having recently developed a sort of collectable card game in XNA for XBLIG and put into playtest, one of the main issues of the game was its lack of AI opponents and intelligent in game tips in order to help you play the game.

So I hope to add this to my game before I put it into the review process in hopes that it adds more replay value to the game.

The main aim of the game is to climb a hill constructed of cards played. Each card has a difficulty value of 2 - 9. One of the main game mechanics of the game is a random chance to climb further up the hill by rolling a six sided dice, if the value is the same or greater then the current card value your climb otherwise you fail to climb. Now your thinking..its impossible for the player to over come anything higher then a 6 value card, thats true, however the user can use a hill value card to boost their roll after they have failed. This depletes your hand and might possibly force you to use a card you wanted to use as a hill card against your opponent.

So as you can see there a many decisions to make when playing the game. So my first idea was to create a sort of a decision matrix. This matrix would be a 2 dimensional matrix, the rows would represent the possible cards or decisions to make and the columns would represent the difficulty of card to play. I would then create each matrix depending on the start of the current turn eg for the first action "Play location <as first player and first turn>" :-

2 - 3 4 - 6 7 - 9

Hill card 80 60 30

Pit card 30 10 5

Landslide 0 0 0

Boulder card 0 0 0

Leap card 0 0 0

Do nothing 0 0 0

Move Up 0 0 0

So then the computer would score each card or action by generating a random number between 0 - (number represented in the matrix) for a 2 Hill card the Random would be (0, 80). This would generate a 1 dimensional array with the length of the number of rows in the matrix. This would then give the computer a card or action to do. Again I would have to create this matrix differently for every stage in the game, would this make sense. Would this be too random and would this be played.

Anyone got any better ways to do this or implemented something similar?

Thanks for any help you can provide.


Jase

BTW I looking for a simple solution notjing involving complex NN or anything like that.
Jason--------------------------http://www.game-of-the-gods.com/sandbox/spacerocks/clientbin/spectrangle.html
For a problem like this I would recommend a basic search algorithm. In case you don't know, a search algorithm is the sort of solution that was employed in the chess program deep blue. Basically, the algorithm analyses every possible sequence of moves and then, based on that, picks the move that is most likely to lead to victory--which is the move that is followed by the highest weighted sum of winning/losing sequences (loses are -), where the weights are determined according to how early each sequence leads to a win or loss (the sooner the higher the weight).
Advertisement

Hi,

Thanks for the reply "mattmrunson". I think that I am finally coming round to this solution as I dont really know how the random decision matrix will play out (probably to random and seem stupid) and it would be quite some work trying to figure out all the possible scenarios and values. From what your saying it seems like a Minimax algorythm could be used to create a scoring system for each card based on the current cards in play and the opponents current hand. Then the card with the best positive score is played. It also seems like the deeper the algorythm goes the better the play gets (only limited by memory and speed).

So on each sequence of the play turn, each card must run a bit of logic to determine its score based of the current state of the game.

Jase

Jason--------------------------http://www.game-of-the-gods.com/sandbox/spacerocks/clientbin/spectrangle.html
Yeah, you got it. If there is a short enough limit to how long the game lasts, you should be able to achieve perfect play on the part of the AI. If the AI is too good, you can easily lower its performance by adding random weights to each card. The impairment of the AI would be proportional to the max value of the random weights.

Also, if your AI is not supposed to have access to information about the player's cards, things get trickier but are still possible.
Hi,

<quote>
The impairment of the AI would be proportional to the max value of the random weights.
</quote>

So by this do you mean that if playing a certian card that is worth 7 for example you could weight it if (easy level) 0 - 30% so it would use a random value between 0 and 30 say 24 and use that as the percentage = 1.68f?

If the computer was set to hard the value might be (60% - 100%) so random number might be 72 which would give = 5.04?

Or am I miss understanding this?

Jase
Jason--------------------------http://www.game-of-the-gods.com/sandbox/spacerocks/clientbin/spectrangle.html
your mostly right, except that instead of doing

7 * .24 = 1.68 //easy mode
7 * .72 = 5.04 //hard mode

you would do

7 * 1.24 //easy mode
7 * 1.72 //hard mode

or

7 * .76 //easy mode (100 - 24)
7 * .28 //hard mode (100 - 72)

That way you get bigger differences between the perfect weights and the randomly modified weights on the harder difficulties. And obviously you will have to play with the ranges to find what is appropriate for different difficulties.

This topic is closed to new replies.

Advertisement