Making an RPS bot to compete in the Battle of Wits.
Ingredients:
|
When you import rps
the cgi handling will be done for you,
and you get:
rps.turns
- the number of turns to throw.
rps.play(n)
- play 0, 1, or 2; the opponent's move is returned.
rps.beat(n)
- the throw that beats n; that is, (n + 1) % 3.
rps.loseto(n)
- the throw that loses to n;
that is, (n - 1) % 3.
For example, here is a simple RPS bot that beats the last move.
#!/usr/bin/env python import rps, random last = random.randrange(3) for turn in xrange(rps.turns): last = rps.play(rps.beat(last)) |
Maybe it lacks genius. But it is devious!
Now, quick - make your own bot. Then enter your bot's URL into the Battle of Wits and fight to the death. If you can't post your bot on a web server, you can run your bot on the command-line, although we won't rank your bot that way. See below for more details.
More bots can be found here. It is rumored that almost nobody has survived a battle against iocaine, even after reading the code. Beware.
It is fair game to use a random number generator, although a perfectly random player is guaranteed to lose as much as it wins. I hope you win.
If you do use random numbers, it is good form to use the RNG seed that is set up by the rps module so that your bot can play reproducibly if needed in a tournament. It is also in good form to share the source code for your bot: the rps module will show the source code if your bot is invoked without CGI parameters.
|
Feel free to use the arena to test your unfinished RPS bots. If you don't follow the protocol, the arena will time-out your game after a few seconds with an error message, no harm done. To help testing CGI scripts, I have posted a few dummy match URLs that simulate simple opponent play; you can hit your script with "?url=http://216.92.235.213:8088/rock&turns=100"; or use "/random" or "/neo".
If you choose to use python, the python rps module has a couple convenient features to help with testing. First, it lets your CGI script run on the command line; if you invoke your rps bot on the command line with no args, it is pitted against a random opponent for 100 throws. Second, it lets you run on the command line against a web opponent, so if you invoke your bot with, say, http://davidbau.com/rps/iocaine as the command-line argument, it will play against iocaine for 100 turns.
The idea for the RPS Battle of Wits comes from Darse Billings' First and Second International RoShamBo Programming Competition. Darse's discussion of those contests are worth a read, as is Dan Egnor's explanation of Iocaine Powder, the winner and #3 in the first and second competitions - even though in the second competition all 64 entries were done by programmers who had access to the source of iocaine. The competition hasn't been held since 2000. It is now 2007, and it has been far too long to go without trying again.
Fame and notoriety await all who play.
Have fun storming the castle!
- David