Design Card Games: AI Theory

Discussion in 'Game Design, Development And Publishing' started by SilentxxBunny, Jan 7, 2020.

  1. SilentxxBunny

    SilentxxBunny Epsilon

    Joined:
    Jun 21, 2016
    Posts:
    136
    Hey everybody,

    I wanted to spark up a discussion about AI Theory, as it pertains to card games. As I understand it: AI Players ("Computers") will basically perform actions in a sequence, as do Human Players.

    That sequence depends entirely on the game (and I don't want to pidgeon-hole this discussion to "Casino Games" or "Playing Card" games) but for the sake of an example:
    1. Draw a Card
    2. Bet
    3. Play a Card
    Easy, right?

    What I'm having trouble working through is how to design an AI which is realistic/fun to play against. I can comprehend a "dumb AI" which makes decisions at random. I can also comprehend a "smart AI" which analyzes the options available to it, and makes the best move that it possibly can (in order to win the game.) Neither of these seem like they would be much fun to play against, and both have a critical flaw...

    How would you (yes, you) go about designing an AI to make decisions in a realistic way. Make mistakes, but also try to win. There's surely 1,000 ways to do this, so let's talk design.
     
  2. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    830
    From what I can remember without doing more research, one approach is to build the AI that analyzes all possible decisions, but then limit the depth of the search. For example, make it so that it can only make estimates up to 2 or 3 moves ahead. It will chose a good move based on the current situation, but it will often not make the most optimal decision.

    Another concept is to make an optimal AI, then randomize the weights by some amount. Thus each iteration of the AI will choose with some bias, not perfectly, and each one would have different bias meaning if done well, the player could identify their weakness and play against that.

    Then of course, you can make something like a deep-learning AI, and train it with imperfect human data. The output may be good, but it wouldn't be perfect.
     
    SilentxxBunny, devKathy and MaxLos like this.
  3. devKathy

    devKathy Member

    Joined:
    Dec 31, 2019
    Posts:
    19
    @Cloaked Games - that is a good approach, and reminds me of an algorithm called alpha-beta pruning. That one doesn't look at all possible next states; instead it trims down states that don't pass a certain "threshold". In general, it seems to eliminate states that most rational players wouldn't voluntarily enter into (i.e. betting all your chips every time). If the game is complex enough, and you want an even higher depth search, this is often preferable.

    To do what either I or Cloaked Games is talking about - minimax in his case, alpha-beta in mine, you need to score each state of the card game that will be entered into by the player(s). This is called a heuristic. Many heuristics have a "worst score" of 0 and increase from there. If you want a more "realistic" AI, you can create one such that the other player's hand is unknown to the AI. Then, we could only score the next state based on our current hand against all other possible hands, and (possibly) the behavior of the other player (i.e., would she behave this way if she had a bad hand, etc.).
     
    SilentxxBunny and Cloaked Games like this.
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,064
    I've read only very little about AI decisionmaking, but I recall minimax algorithm is commonly used in simple decisionmaking situations, good example being tic-tac-toe, and not suitable to complex stuff like chess.
     
    SilentxxBunny likes this.
  5. Coded Games

    Coded Games Member

    Joined:
    Jun 20, 2016
    Posts:
    438
    I played around with a few different methods of AI decision making in my game DRAW!!.

    1. Enemies with a fixed sequence of cards. These enemies were actually pretty fun to play against because if you figured out the pattern you could completely destroy them. The challenge relied around you making the right decisions to play around the cards you knew were going to be played. Although replayability was not that good because the same thing would happen every time.
    2. Enemies that played cards completely randomly. These were definitely the least fun and were the most difficult. Because there is no way to predict what the enemy was going to do the player's choices felt like they did not matter as much.
    3. Enemies that played a fixed sequence of "plays." These enemies had a fixed sequence of moves but there were not fixed to specific cards. For example the first enemy in the game's pattern is dodge, shoot, dodge, shoot, dodge, shoot.... For example if it was the "shoot" phase, the enemy would always shoot at the player instead of a random direction (DRAW!! had different cards for shooting different directions). These enemies had a good balance of feeling dynamic while also giving the player the ability to predict the majority of their attacks.
    4. Enemies that played a fixed sequence of "plays" with a random chance to make mistakes. In DRAW!! enemies never actually had their own hand of cards or a deck. Instead, I would create enemy patterns like in #3, if these patterns were too good I would add a chance that the AI would make a mistake. This is actually a very common thing in all sorts of games. For example in a lot of FPS games enemies will always miss their first shot to give the player a chance to react. I think this is my preferred method of AI as it gives enemies predictability, while also making it seem like they are making natural plays with occasional mistakes.

    Hope this helps! If you want to play my game you will actually be able to see all these types of decision making in action.
     
    SilentxxBunny likes this.
  6. SilentxxBunny

    SilentxxBunny Epsilon

    Joined:
    Jun 21, 2016
    Posts:
    136
    [1] Interesting approach. I was working through this conceptually, and couldn't figure out how to simulate the feeling of "running through moves in your head, and making one after ~6 seconds" which is how I often feel while playing a TCG or Poker. This is helpful. Thank you.

    [2]
    This was (to me) the most obvious solution, but it didn't sit right with me... Although, I have considered the idea of having different levels ("difficulties") and that this may be the best way to accomplish that. Huh.

    [3] This is waaay above my abilities as a programmer, but it would certainly be interesting... having AI that "gets to know you" as a regular in a virtual casino.

    If anyone here wants to "break it down" for us: I'm curious as to how that would work. I'm not asking for code, as much as a "10,000 foot overview" conceptually... Well, unless you have code to share. I'm certainly not discouraging that. ;)
    This is great information to have. Sometimes the hardest thing about the "research phase" of design is knowing what to search for.

    Alpha-beta pruning
    and minimax are things I will be looking into. Gracias.

    Gotcha.

    1. Might be good for a tutorial, though.
    2. This sounds awful. I agree.
    3. I hadn't considered this at all. That might work for a card-game I'm meditating on. It's based on a board-game I played as a kid, but I've made something nearly-original out of it. This sounds like something I could pull off. Very duly noted.
    4. That's greasy, but I can see how it would "feel" the best.

    Very interesting. Thanks for sharing!

    I've played DRAW! (very fun, reminds me of a mini-game from the original Kirby) but haven't checked out Decks of Dexterity, yet. I'll make sure to do so.

    - - -

    To contribute something to the discussion, here are a few videos from my collection of tutorials:




     
    Last edited: Jan 8, 2020
    devKathy likes this.
  7. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,178
    A common form of AI design is to first make an AI that is perfect and always make the best move (it's often surprisingly easy, since your game logic has access to all the state information while your players don't) and then "dumb it down" by adding randomness to either its accuracy or its decisions (e.g. 10% of the time, it makes a suboptimal move instead of picking the best). The drawback of this approach is that in a turn-based game where decisions are discrete in nature, it's a lot easier for a player to spot when someone that was acting nail-bitingly hard just a moment ago suddenly does something really stupid.

    When I made the AI for Shattered World, I tried to achieve this effect by having case-to-case bonuses to the AI priorities. (A major reason I picked that approach was that making the full priority grid took so much time, I had to reuse some of the data for all enemies instead of recomputing it for each enemy). Enemies try to move as close to as many players as possible, but cells that are exactly their movement range away from a player gets a x10 multiplier - this makes ranged enemies end up trying to stay out of your attack range.

    Enemies try to make a certain number of random actions out of the ones they are able to do (basic attacks, support skills, attack skills) - as in, pick a random skill, then pick a random target within its range - and then those are ranked based on how many friendly vs hostile targets they hit (with the ranking inversed for support skills since they're MEANT to hit friendly targets). All the action the enemy consider are added to a priority queue, and then when the max number of considered actions is hit, the highest-priority action is selected and performed. A random number which can be both positive and negative is added to the priority as well (to keep things varied even when there's not a lot of skills the enemy can do), but it's so small that a very good tactical option will always win even if it gets the worst possible random bias.
     
    devKathy and SilentxxBunny like this.
  8. rogonow

    rogonow Member

    Joined:
    Dec 24, 2019
    Posts:
    14
    It has also a difficulty for an AI strategy game. I did next solution.
    Bot level 1: make 1 move
    Bot level 2: make 2 moves
    Bot level 3: make 2 moves + 1chance out of 5 to make a 3th move.
     
    Last edited: Jan 15, 2020

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice