3
\$\begingroup\$

Let me get this out there before anything else: this is a learning exercise for me. I am not a game developer by trade or hobby (at least, not seriously) and am purely delving into some AI- and 3D-related topics to broaden my horizons a bit.

As part of the learning experience, I thought I'd have a go at developing a basic card game AI. I selected Pit as the card game I was going to attempt to emulate (specifically, the 'bull and bear' variation of the game as mentioned in the link above). Unfortunately, the rule-set that I'm used to playing with (an older version of the game) isn't described. The basics of it are:

  • The number of commodities played with is equal to the number of players.
  • The bull and bear cards are included.
  • All but two players receive 8 cards, two receive 9 cards.
  • A player can win the round with 7 + bull, 8, or 8 + bull (receiving double points).
  • The bear is a penalty card.
  • You can trade up to a maximum of 4 cards at a time. They must all be of the same type, but can optionally include the bull or bear (so, you could trade A, A, A, Bull - but not A, B, A, Bull).

For those who have played the card game, it will probably have been as obvious to you as it was to me that given the nature of the game, gameplay would seem to resemble a greedy algorithm. With this in mind, I thought it might simplify my AI experience somewhat.

So, here's what I've come up with for a basic AI player to play Pit... and I'd really just like any form of suggestion (from improvements to reading materials) relating to it.

Here it is in something vaguely pseudo-code-ish ;)

While AI does not hold 7 similar + bull, 8 similar, or 8 similar + bull, do:
    1. Establish 'target' hand, by seeing which card AI holds the most of.
    2. Prepare to trade next-most-numerous card type in a trade (max. held, or 4, whichever is fewer)
    3. If holding the bear, add to (if trading <=3 cards) or replace in (if trading 4 cards) hand.
    4. Offer cards for trade.
    5. If cards are accepted for trade within X turns, continue (clearing 'failed card types').
        Otherwise:
            a. If only one card remains in the trade, go to #6.
                Otherwise:
                    i. Remove one non-penalty card from the trade.
                    ii. Return to #5.
    6. Add card type to temporary list of failed card types.
    7. Repeat from #2 (excluding 'failed card types').

I'm aware this is likely to be a sub-optimal way of solving the problem, but that's why I'm posting this question. Are there any AI- or algorithm-related concepts that I've missed and should be incorporating to make a better AI? Additionally, what are the flaws with my AI at present (I'm well aware it's probably far from complete)?

Thanks in advance!

\$\endgroup\$

1 Answer 1

7
\$\begingroup\$

What you've got there is a basic rules-based system. It's fine, but it will play the same way every time and possibly have exploitable patterns of play. The domain's simple enough that there might not be an easy pattern to exploit, but it's not a very interesting approach. :)

You may want to look into planning AIs. Instead of defining an algorithm for play, you can code the AI with the steps it can take: how to trade and what the consequences are for it. These are sometimes called "inference rules." Then you use forward or backward chaining to figure out a sequence of actions from the current state to the goal state.

Alternately, if you think you can define a good heuristic for how close you are to winning, you can use an adversarial approach like alpha-beta pruning search that allows the AI to take the state of the opponents into account. I'd guess that a good heuristic would include what the AI can know about its opponents' hands based on their previous trades.

I'm sure there are approaches that an AI expert would think of that I've missed.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks - that's certainly helped a bit... though given my complete ineptitude when it comes to AI, I suppose a little more description of/a link to a good introduction on 'planning AI' would be useful! In either case, I've +1'd, but I'd like to wait for some more replies before accepting an answer! :) Once again, thanks. \$\endgroup\$
    – James B
    Jan 16, 2011 at 1:23
  • \$\begingroup\$ en.wikipedia.org/wiki/Automated_planning_and_scheduling is a good place to start. For a more in-depth source, my introduction to AI was Russell and Norvig's Artificial Intelligence: A Modern Approach. It's a fairly standard textbook, so you might be able to get a used copy cheap. \$\endgroup\$ Jan 17, 2011 at 1:18
  • \$\begingroup\$ Whilst I was hoping for more answers to supplement yours... this has pointed me in the 'right direction' so I've accepted your answer :) Many thanks. \$\endgroup\$
    – James B
    Jan 24, 2011 at 3:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .