RSS

AI for fortunes

This entry was posted on Feb 11 2012
an exposed face robot

Let's open it up and do some tweaks.

Working out what to do for the AI has been a bit interesting. I’ve never done AI for a card game before. I was initially thinking of trying to do a min-max tree but quickly came to the decision that the branching factor and uncertainty would cause that method to be a bit unwieldy.

a robot in control

So After some rethinking and discussion with James we can upon our current idea. Basically we are going to have two weighted factors to decide which card to play. One being the likelihood of the card to win the current trick and the second the strength of the hand hand that was left afterwards.

building a hand

building a strong hand

These aren’t static weights, at least they won’t be once I’ve implemented them shifting over time. In the beginning the AI will favor building a stronger hand and near the end they will care more about winning the trick immediately. This two factor AI should deal with things like not wasting a strong card when a weaker one would just as easily win the trick.

Sometimes shortcuts can be found

Sometimes shortcuts can be found

Of course with the way the rules of fortunes work I couldn’t just use the rank of the cards for how valuable it was for a hand. Since tricks can be either High or Low we have to use the distance from the center instead.

foreach(Card c in newHand){
if(c.suit != Card.suits.stars){
if(c.rank > 7)
score += c.rank - 7;
else
score += Mathf.Abs(c.rank-8);
} else {
if(c.rank > 10)
score += c.rank - 10;
else
score += Mathf.Abs(c.rank-11);
}
}

Sorry wordpress didn’t preserve my indentation. Anyway The Major Arcana are slightly more valuable since they can switch a hand from low to high or vice versa, but this is hopefully captured in the slightly higher range of values for Major Arcana from 0 to 10 instead of 0 to 7 like the minor Arcana.

Thanks for listening to me ramble about AI here. If you think I’m way off base and have a suggestion, or just have a question about what I’m doing, share in the comments below.

About Imani


I am a Georgia Tech Alum living in Philadelphia. I am a software engineer by trade and am trying to start a game company in my free time.