Testing Shock AI

Here are the bad news: there were fundamental problems in the AI demonstrated in the previous posts. The fact that it succeeded in shocking me was a mix of

  • luck (based around the order in which choices were tried)
  • the fact that basically it was trying everything, thus playing every cards…

Now, the good news is that I reworked part of the minimax algorithm to fix these problems. To help me ensure that the AI always works as intended, I introduced automated tests. Here is one example of a test:

[Test]
public void Test_Shocking_showdown()
{
    AddCard(m_playerA, m_game.Zones.Hand, "10E", "Shock");
    AddCard(m_playerA, m_game.Zones.Hand, "10E", "Shock");
    AddCard(m_playerA, m_game.Zones.Hand, "10E", "Mountain");
    AddCard(m_playerA, m_game.Zones.Hand, "10E", "Mountain");
    AddCard(m_playerA, m_game.Zones.Hand, "10E", "Mountain");

    AddCard(m_playerB, m_game.Zones.Hand, "10E", "Shock");
    AddCard(m_playerB, m_game.Zones.Hand, "10E", "Shock");
    AddCard(m_playerB, m_game.Zones.Hand, "10E", "Mountain");
    AddCard(m_playerB, m_game.Zones.Hand, "10E", "Mountain");
    AddCard(m_playerB, m_game.Zones.Hand, "10E", "Mountain");

    SetupGame();

    Play_until_all_players_pass_and_the_stack_is_empty(m_playerA);

    Assert.AreEqual(16, m_playerA.Life);
    Assert.AreEqual(16, m_playerB.Life);
}

This test puts 2 shocks and 3 mountains in the hand of two AI players, gives priority to player A and runs the game until the stack is empty and everyone passed. It then ensures that both players played both their Shock by checking the life of each player. This is a somewhat high-level/system test, as it doesn’t check the order in which cards are played on a per-choice basis. It doesn’t care whether all the mountains were played before the shocks or if the AI played mountains and shocks in an alternate fashion. Also, keep in mind that I did not implement the “one land per turn” rule. I will have to rework these tests when I do!

Quiz time: Can you spot a major logical flaw in the test? Click on “Continue reading…” for the answer.

Answer: The test would pass if both AI players shocked themselves instead of their opponent! I have another test where I give Shocks to only one of the players that test for this behavior.

In my next post, I will present the different optimizations I made or I plan to make to reduce the time it takes for one “AI choice”. See you there!

Advertisements

About fparadis2

Lead Game programmer
This entry was posted in Mox. Bookmark the permalink.

One Response to Testing Shock AI

  1. frwololo says:

    Wow, unit tests for the AI? I hate you, this looks so cool!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s