Created
September 4, 2010 13:59
-
-
Save casparkleijne/565209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static Random r = new Random(DateTime.Now.Millisecond); | |
// names of the "moves" | |
private static string[] rps = { "PAPER", "ROCK", "SCISSORS"}; | |
// result feedback string to be formatted | |
private static string[] feedback = { "{1} Beats {0}, You Loose!","{0} Equals {1}, Draw!", "{0} Beats {1}, You Win!" }; | |
// solution matrix ( 0 = loose ; 1 = draw ; 2 = win // array1: for paper; array2: for rock; array3: for scissors; ) | |
private static int[,] solution = {{1, 2, 0},{0, 1, 2},{2, 0, 1}}; | |
/// <summary> | |
/// Rock Paper scissors solution w/o calculation or if/case/else/ | |
/// </summary> | |
/// <param name="args">dummy.</param> | |
static void Main(string[] args) | |
{ | |
// simulate the players move | |
int player = r.Next(3); | |
// simulate the computers move | |
int computer = r.Next(3); | |
// retrieve the result from the matrix | |
int result = solution[player, computer]; | |
//write the result of the match | |
Console.WriteLine(String.Format("you : {0} vs {1} : computer", rps[player], rps[computer])); | |
Console.WriteLine(String.Format(feedback[result], rps[player], rps[computer])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment