Rock Paper Scissors Bot Kitchen

Making an RPS bot to compete in the Battle of Wits.

Ingredients:

  1. The python rps.py module, from here.
  2. Your own web server for running python cgi scripts. (optional)
  3. A pinch of audacity, deception, and genius.

When you import rps the cgi handling will be done for you, and you get:

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.

Etiquette and Protocol

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.

If you want to substitute your own rps client implementation, the protocol is described below. Note that, on the wire, we don't transmit integers, but we actually use the text strings "rock", "paper" and "scissors".

  1. To begin a match, your bot is given three CGI parameter values.
    url is the URL for your match, something like "http://216.92.235.213:8088/rps/4f2sr".
    turns is the number of turns to play, like 100 or 1000.
    seed is optional and is a number for seeding your RNG.
  2. Your bot should return the plain text "rps" to indicate that it is an actual RPS bot. Any other output will be considered an error and will produce diagnostics in the arena.
  3. To throw one turn, send an HTTP request of the form "http://216.92.235.213:8088/rps/4f2sr?play=rock" (of course, using the acutal match URL instead of this example one). The response body will be the text "rock" or "paper" or "scissors", which is your opponent's throw.
  4. Repeat step #3 for the required number of turns, and emerge victorious.

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