The Windows Azure team is holding a contest, and The Code Project is helping to support it. As part of this contest, you can get free Azure compute time by signing up with the code CP001 here. The contest is simple – Rock, Paper, Scissors, with bots, and with 2 new moves: Dynamite, which beats Rock, Paper, or Scissors, and Water Balloon, which beats Dynamite. The catch: you only have a limited supply of dynamite.
Get Started Here:
My bot placed 4th out of about 50 in last week’s contest (look for ardalis, the same as my twitter handle). I’m hoping to be in the top 3 this week. I thought I’d share some tips to help you get started.
Countering an Expected Move
If you think you can predict what the other bot is going to do, then it’s a relatively simple matter to counter that move. Calculating the move to use to counter that move is fairly straightforward. In my initial design, I had a simple method that achieved this, but as my basic bot class grew in size, I refactored this out into its own simple class that follows the Single Responsibility Principle:
Note that this will never return Dynamite as a counter move – I’m assuming that you’ll have your own special logic for determining when you’d like to use your Dynamite.
Tracking Game State
The MakeMove method accepts two IPlayer instances and a GameRules instance that pretty much just includes constants (like how much Dynamite each player has). The player instances will let you know their last move, points, whether they have Dynamite remaining, etc., but notably will not provide you with a complete history of the game, except as a text log. Thus, if you’re interested in knowing the current state of the game, or how your opponent reacted when faced with similar game state in the past, you’ll need to track this yourself. The simplest thing you can do is create a couple of arrays or lists of moves for yourself and your opponent, but eventually you have enough game state tracking logic that it makes sense to move it to its own class as well. Thus, you might find something like the GameState class useful. This class lets me inspect my own move history, my opponent’s move history, how many of a given move my opponent has made, and also what my opponent’s response was to a given Tie scenario, such as tied once, tied twice, tied three times, etc.
Countering a Particular Bot
If you find that one particular bot is foiling your primary strategy, you can target that bot specifically. For instance, at one point early in the contest last week I reviewed the log of a match I’d lost to a player named mitchmilam. After looking at the log, I noticed that his bot simply countered whatever move I made previously. Knowing this, I thought I’d test out a bot that countered the counter of whatever move it had just made – the CounterCounterBot was born. However, I didn’t want to run this bot against everybody – only against mitchmilam (and perhaps later against any bot I determined to be a CounterBot). To make this work, I simply added this case to my MakeMove() method:
and then wrote this method:
The result? In the next matchup between our bots, my bot won 1000 to 2. Later, this bot updated its strategy a bit…
If you’re interested in getting started with Windows Azure or just want to try your skill at creating a simple AI bot to play a very simple game, give the contest a go. There are some prizes if you’re in the top 3 in a given week (only for US residents, I’m afraid), but it’s also a fun test of skill and if you get your friends to play you can earn some bragging rights. Good luck!