{"id":25,"date":"2007-09-22T08:05:00","date_gmt":"2007-09-22T08:05:00","guid":{"rendered":"http:\/\/dhbolton.com\/blog\/?p=25"},"modified":"2007-09-22T08:05:00","modified_gmt":"2007-09-22T08:05:00","slug":"rock-scissors-and-paper-contest","status":"publish","type":"post","link":"https:\/\/dhbolton.com\/blog\/about-c\/rock-scissors-and-paper-contest\/","title":{"rendered":"Rock, Scissors and Paper Contest"},"content":{"rendered":"<p><a href=\"http:\/\/cplus.about.com\/od\/programmingchallenges\/a\/onchallenge1.htm\" title=\"Link to Rock, Scissors and Paper Contest\"><img decoding=\"async\" src=\"http:\/\/z.about.com\/d\/cplus\/1\/0\/U\/2\/-\/-\/rsplogo.gif\" border=\"0\" alt=\"http:\/\/cplus.about.com Rock, Scissors and Paper Contest\"><\/a><br \/>My other hat is writing the <a href=\"http:\/\/cplus.about.com\/\">About C, C++ and C#<\/a> website for <a href=\"http:\/\/about.com\/\">About.com<\/a>&#8211; the New York Times owned website. I&#8217;m one of their 600 guides who write for them.<\/p>\n<p>One of the interesting things I&#8217;ve been doing there is running the <a href=\"http:\/\/cplus.about.com\/od\/programmingchallenges\/a\/onchallenge1.htm\">Rock, Scissors and Paper (RSP) contest<\/a>&#8211; it&#8217;s free and open to anyone and new players can join anytime between now and Christmas. It&#8217;s not the easiest to let developers use all three languages to write bots to play RSP but I managed it.<\/p>\n<p>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.<\/p>\n<p>What I did was develop a C# Winforms application that uses a dll for each bot. I&#8217;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:<\/p>\n<p> \u00a0\u00a0   public class bot <br \/>  \u00a0\u00a0  \u00a0\u00a0  \u00a0\u00a0            {<br \/> \u00a0\u00a0  \u00a0\u00a0         public const int botnum = 1;<br \/> \u00a0\u00a0  \u00a0\u00a0         const string dll = &#8220;c:\\ongoing\\dlls\\skeleton1.dll&#8221;;<\/p>\n<p> \u00a0\u00a0  \u00a0\u00a0         [DllImport(dll,<br \/> \u00a0\u00a0  \u00a0\u00a0         CallingConvention = CallingConvention.Cdecl)]<br \/> \u00a0\u00a0  \u00a0\u00a0         public static extern string GetBotName();    \/\/ returns name of your Bot<\/p>\n<p> \u00a0\u00a0  \u00a0\u00a0         [DllImport(dll,<br \/> \u00a0\u00a0  \u00a0\u00a0         CallingConvention = CallingConvention.Cdecl,CharSet=CharSet.Ansi)]<br \/> \u00a0\u00a0  \u00a0\u00a0         public static extern char <br \/> \u00a0\u00a0  \u00a0\u00a0    \u00a0\u00a0         GetMove([MarshalAs(UnmanagedType.LPStr)]String S,<br \/> \u00a0\u00a0  \u00a0\u00a0 \u00a0\u00a0                    [MarshalAs(UnmanagedType.LPStr)]String S2);  \/\/ return move<\/p>\n<p>.. others trimmed for shortness<br \/> \u00a0\u00a0  \u00a0\u00a0 }<\/p>\n<p>Note the marshalling attributes &#8211; the dlls use cdecl, it&#8217;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.<\/p>\n<p>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&#8217;ve trimmed to fit this. <\/p>\n<p>1 v 5  29  33<br \/>1 SSSRSSSRSRRRSSRSRRRRRRRRR&#8230;..PPSPSRSS<br \/>5 PSSPRRSPSSPPRSPSSSPSSSSPP&#8230;..SSSRSSRP<\/p>\n<p>You can see the full file this came from: <a href=\"http:\/\/cplus.about.com\/library\/downloads\/challenges\/ongoing\/week-six-matches.txt\">Week 6 results<\/a> It&#8217;s just a text file, generated by the application.<\/p>\n<p>So if you fancy entering- remember it&#8217;s free just follow this link:<br \/><a href=\"http:\/\/cplus.about.com\/od\/programmingchallenges\/a\/onchallenge1.htm\">Rock, Scissors and Paper Contest<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My other hat is writing the About C, C++ and C# website for About.com&#8211; the New York Times owned website. I&#8217;m one of their 600 guides who write for them. One of the interesting things I&#8217;ve been doing there is running the Rock, Scissors and Paper (RSP) contest&#8211; it&#8217;s free and open to anyone and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[4,9,10,38,50],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-about-c","category-bot","category-cand-c","category-rock-scissors-and-paper","category-writing"],"_links":{"self":[{"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhbolton.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}