In the past days, I commited the code that allows the AI to block attackers. I don’t like saying “the blocking AI” because it doesn’t in anyway specify whether the AI should or should not block in a given situation. What it does is simply make it possible for the generic AI code to consider blocking. Before, the AI didn’t know that there was any other possible action than to pass on the declare blockers step. Now, it’s gonna evaluate all the possible blocking situations.

Speaking about that, the number of possible blocking combinations grows very fast with the number of creatures available in play. I hope I can get away with evaluating all of them. If not, I’ll have to insert a very biased heuristic in an otherwise generic minimax algorithm!

When writing some functional tests, I stumbled upon an interesting case. If a player A has two 1/1 creatures while player B has only one 1/1 creature. Should player A attack player B? The answer is “it depends“.

  • If player B has 1 life left, then by all means attack, you have a great chance of  winning.
  • If player B has 20 life left, then you shouldn’t attack, you’ll just lose one of your creature and the opponent will still have 19 life. It’s just not worth it.

Now, where does the switch happens? Would you do the trade if player B had 2 life? 3 life? 5 life? This example made me realize that the value of life actually depends on how much you have. The more life you have, the less each “unit” of life is worth. And I realized that my heuristic method did not take that into account. So I changed my heuristic: it is now proportional to log(life). This function has the properties we are looking for:

  • It’s continously increasing (which basically means more life is better).
  • It’s derivative is continuously decreasing and tends to 0 (meaning that life is less and less worthy the more you have).

Using that heuristic, going from 2 life to 1 life is considered much more hurtful than going from 20 life to 19 life, as you would expect.

The exact parameters (constants) are very hard to tweak as there are many more factors to consider (creatures, lands, etc). Nevertheless, I expect that the heuristic computation will be a great way to make different kinds of AI with different behaviors and strengths (i.e. AIs that value creatures more than spells, suicidal AIs, etc…).


About fparadis2

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

2 Responses to Tradeoffs

  1. JimmyBean says:

    I don’t know If I said it already but …Excellent site, keep up the good work. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, 🙂

    A definite great read..Jim Bean

  2. Kyle says:

    One thing to note is that if I have 2 1/1 creatures, I will almost always attack into a single 1/1 defender. 1/1 creatures are easily outclassed, so most likely this is the best time to turn one of them into 1 damage.

    If I know something about our matchup, such as his creatures are better and I will want chump blockers later, that will of course change my decision.

    I figure that for a simple AI, having them fight wars of attrition are more favorable because it makes it easier for them to calculate combat. I would probably want my AI calculating choices for 2 creatures instead of 5, so every chance I have to make a fair trade would benefit the AI.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s