This post originated from an RSS feed registered with .NET Buzz
by Sascha Corti.
Original Post: CodeZone Duel
Feed Title: Console.WriteLine("Hello World");
Feed URL: http://www.corti.com/WebLogSascha/blogxbrowsing.asmx/GetRss?
Feed Description: A technology blog with a focus on the .NET framework, the Visual Studio .NET tools and the Windows server platform with of course the normal weblog-noise on what's happening in the industry and reviews of the latest geeky gadgets.
The local web service development contest held at CodeZone.ch was a big success. Although the game that we used for the contest (rock, paper, scissors) appeared to be too simple at first, it turned out to be very good for the contest as simple programs, put together in a few minutes, based on a simple random function could participate equally as more sophisticated algorithms that tried to predict the next move of the opponent, as the participating services played 25 rounds against the same opponent in a row. At first, I only mentioned rock, paper scissors as possible game for the contest to illustrate my idea of how competing web services with a central game web service would work and never meant for it to be used in the real contest... :)
Congratulations to Frigidor who won the contest!
I had a chance to talk to him and ask him for the algorithm he used and was pleased to hear, that we both used somewhat similar ones (even though my service didn't compete as I wasn't allowed to play).
Here is my code:
using System; using System.IO; using System.Data; using System.Diagnostics; using System.Security.Cryptography;
int r = Convert.ToInt32(ds_row["RockPlayed"]); int p = Convert.ToInt32(ds_row["PaperPlayed"]); int s = Convert.ToInt32(ds_row["ScissorsPlayed"]);
if ( r > p ) { if ( r > s ) o = Enums.GameOptions.Paper; else { if ( r == p & p == s ) o = GetRandom(); else o = Enums.GameOptions.Rock; } } else { if ( p > s ) o = Enums.GameOptions.Scissors; else { if ( r == p & p == s ) o = GetRandom(); else o = Enums.GameOptions.Rock; } }
ds_row["LastTurnPlayed"] = o.ToString();
SaveData();
return o; }
publicvoid ReceiveTurnFeedback(Enums.GameOptions opponentOption) { Enums.GameOptions o; string s = "";
DataRow ds_row = ds.Player1Table.Rows[0];
switch ( ds_row["LastTurnPlayed"].ToString() ) { case "Rock": o = Enums.GameOptions.Rock; break; case "Paper": o = Enums.GameOptions.Paper; break; default: o = Enums.GameOptions.Scissors; break; }
if ( opponentOption == Enums.GameOptions.Rock ) { ds_row["RockPlayed"] = Convert.ToInt32(ds_row["RockPlayed"])+1;
if ( o == Enums.GameOptions.Rock ) s = "0"; if ( o == Enums.GameOptions.Paper ) s = "+"; if ( o == Enums.GameOptions.Scissors ) s = "-"; } if ( opponentOption == Enums.GameOptions.Paper ) { ds_row["PaperPlayed"] = Convert.ToInt32(ds_row["PaperPlayed"])+1;
if ( o == Enums.GameOptions.Rock ) s = "-"; if ( o == Enums.GameOptions.Paper ) s = "0"; if ( o == Enums.GameOptions.Scissors ) s = "+"; } if ( opponentOption == Enums.GameOptions.Scissors ) { ds_row["ScissorsPlayed"] = Convert.ToInt32(ds_row["ScissorsPlayed"])+1;
if ( o == Enums.GameOptions.Rock ) s = "+"; if ( o == Enums.GameOptions.Paper ) s = "-"; if ( o == Enums.GameOptions.Scissors ) s = "0"; }