Advertisement

Making PC "think" (card game)

Started by November 20, 2009 07:01 AM
15 comments, last by Marcius 15 years, 2 months ago
Hey guys! I'm creating a card game and I've just faced the part of my project, where I need to develop some sort of AI. I'm not going to start explaining all the rules etc in order to save you some time, but instead, I'm gonna give a simplified problem, and hopefully with your help I would be able to pick it up from there. Let's say we have a game made by three contracts: tricks (rules: do not take tricks),jacks (do not take jacks) and queens (do not take queens). We have three players (one of which is a human player). Deck: 32 (7 to A). You must follow suit..if you don't have it - you can play any card. Highest card takes the trick. Everyone gets 10 cards each (2 is left out, but let's not bother ourselves with that now). Ok, so a computer player must pick a game from one of those three contracts. Where do I start off from? I know I have to develop some sort of a formula, by which computer could estimate the value of it's cards and choose the best contract to play. I'm not asking for an actual code here, but maybe some general guidelines, logical steps to begin with or something.. So, I'd appreciate anything that could get me on track. (sorry for my English, it's not my first language)
The best place to start would be to learn how to play this game yourself (I'm unfamiliar with it - did you make it up?) Then simply write down the decisions _you_ yourself would make in a certain situation. There's no way to make the computer "think" - it will only be as good at the game as you are. I know that's not the response you're looking for but you'll get the same from everyone else. Unless it's a well-known card game then you won't find a lot of help.
Advertisement
I disagree with _Sauce_. My chess program and my checkers program are both better at those games than I am, and I don't know what would make this not possible for this game.

I would use a Monte Carlo method to pick a contract. In order to do that, you can first ignore the contract selection and focus on making a program that plays the trick-taking part of the game. Make it so your program can play very very quickly, even if it's not very good. Once you have that, you can make the program simulate a few thousand games with each contract and pick the contract that gives it the most wins. If you are not happy with the results, try to refine the policy for playing the trick-taking part of the game.



Thanks guys, I was barely hoping to get any reply here.
_Sauce_, I think I'm quite good at this game, I've been playing it since forever. It's not something I made up (I've simplified the rules in my post above to make thing less complicated), this game is called "The King", it's fairly popular. Only that the rules of this game vary a little from country to country.
What I've tried to do at first was drawing a decision tree, just like you mentioned..but it turned out to be much more difficult that I thought it would be. When I play this game live, I usually pick a contract very easily, but I find it hard to implement that "logic" I use into a program, only because I'm not able to distinguish my decision making process.
alvaro, I would be more than happy if I could make my program to play this game at least as good as I do. As regards Monte Carlo method, while I get the concept and I think it's quite good, I don't think I'd be able to make it work right though.. I don't have enough programming experience to make this process smooth. I'd probably spend less time figuring out decision making than applying Monte Carlo method.
Anyway, I don't really know if all this helps or not. But after some time spent on this forum, checking out some links, reading some stuff, it really got me going somewhere, so hopefully I'll make it work right.
Thanks again for your thoughts :)
While we're still on this, I have a simple question, but I can't figure it out in the way I'd like to. Let's say you get dealt a random number of cards each time (from 1 to 8 cards), always of the same suit, for instance: 7s 10s As, 8h Jh or 9d Qd Kd Ad etc. The deck is still from 7 to A..if you get 2 spades (which you obviously can see), your opponents have 6 spades (hidden). Or if you get 5 hearts, your opponents have 3 hearts. Question: how to determine, how many tricks you will take? This is the question, which must be solved by a program of course.
I feel this post might be a little tricky, so if there's any uncertainty - just ask, I'll try to explain more clearly.
Don't we need to know the actual rules of game to answer that?
Advertisement
Actually, you don't. That's not even the matter of the game itself, it's only an independent part of it. Maybe one thing you need to know is that the highest card takes the trick, and the goal is not to take any tricks. Focus only on this: just imagine you have, let's say, 9s 10s and Qs, and your two opponents have the rest of spades (7,8,J,K and A). Now, when I see these three cards, I know, that I have a good chance to take only two tricks. Another example: 7h 9h Kh and Ah. In this case, I will take two tricks as well, with king and ace. 7 is the lowest card, so I'm definitely safe with this one. And 9, well..it's two opponents, so one of them must have a higher card. Let's say you have all the clubs: in this case, either you take all the tricks or none, depending who's playing first. Now, it's easy to say, but I can't find a decent way to code it. I wish my English was better, so I could explain it in more obvious way...
Sorry if I'm just confusing you, I never played similar games, so I don't quite understand the concept.

Do I understand correctly that you only predict approximately the number of tricks you'll take? In your example:
Quote:
Original post by Marcius
Another example: 7h 9h Kh and Ah. In this case, I will take two tricks as well, with king and ace.

Sounds reasonable, but maybe you'll have a chance to dump that Kh or Ah when you can't follow suit. In which case you'll only take one trick or even none? Can this happen, or am I still missing something about the rules?
You're totally right Gil, you can dump those cards if you can't follow suit. The problem is, that at the very beginning you're not able to tell weather this will happen or not (except if you have something like 7 8 9 K A, then you're good). And I just need a raw, approximate calculation. If I could do this in other, more accurate way - I would. But now it looks a little too difficult for me..maybe when I have the "core", I will be able to upgrade it, make it more precise.
You can either brute force it with Monte Carlo techniques (which I'm not a fan of), or you can apply some sort of iterative play-through technique (like a chess-tree search) but applying Bayesian uncertainty to it all.

I'm a Bridge player and that's the way I would have solved that. One of the big issues with Bridge (and with the example you showed above) is that the order you and your opponents play your cards often makes a lot of difference in who will win. You can force things out of someone's hand, finesse them out (an actual Bridge term), or you/they can play things at the wrong time just because they make an error in assumption about where another card may be. It's not a trivial problem. In fact, I believe that trick-based card games fall under NP-hard problems. Good luck.

I do have to agree that it will be far easier for people to get their heads around this problem if you were to explain the rules. Alternately, shift your question to a domain that people are familiar with like Bridge, Spades, Hearts, etc. in order to get the answers you need and then do the translation into your own game later.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement