# How Can I Improve This Card-Game AI?

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!

## 1 Answer

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.

• 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. – James B Jan 16 '11 at 1:23
• 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. – Gregory Avery-Weir Jan 17 '11 at 1:18
• 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. – James B Jan 24 '11 at 3:54
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.37985166907310486, "perplexity": 1237.3165603347695}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-47/segments/1573496667767.6/warc/CC-MAIN-20191114002636-20191114030636-00247.warc.gz"}