Rock, Scissors and Paper Contest
My other hat is writing the About C, C++ and C# website for– the New York Times owned website. I’m one of their 600 guides who write for them.

One of the interesting things I’ve been doing there is running the Rock, Scissors and Paper (RSP) contest– it’s free and open to anyone and new players can join anytime between now and Christmas. It’s not the easiest to let developers use all three languages to write bots to play RSP but I managed it.

Each week, every bot in the contest plays every other bot in a 100 hand match. All wins are totalled up and that determines the ranking.

What I did was develop a C# Winforms application that uses a dll for each bot. I’ve done the hard bit and provided a full skeleton dll for C, C++ and C# that anyone can download and flesh out; just fill in the function bodies, the move logic goes in the GetMove() function. I wrote a C# wrapper for the C and C++ bots which wraps the dll calls in a class- it looks like this:

   public class bot
      public const int botnum = 1;
      const string dll = “c:\ongoing\dlls\skeleton1.dll”;

      CallingConvention = CallingConvention.Cdecl)]
      public static extern string GetBotName(); // returns name of your Bot

      CallingConvention = CallingConvention.Cdecl,CharSet=CharSet.Ansi)]
      public static extern char
         GetMove([MarshalAs(UnmanagedType.LPStr)]String S,
         [MarshalAs(UnmanagedType.LPStr)]String S2); // return move

.. others trimmed for shortness

Note the marshalling attributes – the dlls use cdecl, it’s ansi chars (8 bit as C# uses Unicode) and the strings are passed as lpstr. A string in C is just an array of 8 bit chars.

This function GetMove passes in the previous hands (in this match against one bot) so you can see what your bot played and what the opponent played. After each week I publish the results and a file containing all bots moves- eg this was the match between bot 1 and 5. 1 won 29 times, 5 won 33. Below this are the strings which I’ve trimmed to fit this.

1 v 5 29 33

You can see the full file this came from: Week 6 results It’s just a text file, generated by the application.

So if you fancy entering- remember it’s free just follow this link:
Rock, Scissors and Paper Contest