Skip to content

Instantly share code, notes, and snippets.

@andylshort
Created October 29, 2018 16:39
Show Gist options
  • Save andylshort/a47466465c5d2e03d234d7210f0eab66 to your computer and use it in GitHub Desktop.
Save andylshort/a47466465c5d2e03d234d7210f0eab66 to your computer and use it in GitHub Desktop.
Small C# implementation of RSPLS
using System;
using System.Threading;
namespace RockPaperScissorsLizardSpock
{
class Program
{
static void Main(string[] args)
{
int[,] WinMatrix = new int[5, 5]
{
// R P Sc L Sp
{ 0, -1, 1, 1, -1 }, // R
{ 1, 0, -1, -1, 1 }, // P
{ -1, 1, 0, 0, 0 }, // Sc
{ -1, 1, -1, 0, 1 }, // L
{ 1, -1, 1, -1, 0 } // Sp
};
string[] Options = new string[] { "Rock", "Paper", "Scissors", "Lizard", "Spock" };
Console.WriteLine("Options: Rock(0), Paper(1), Scissors(2), Lizard(3), Spock(4)");
Random Random = new Random();
if (!int.TryParse(Console.ReadLine(), out int Option) || (Option < 0 || Option > 4))
{
Console.WriteLine("You dope.");
Thread.Sleep(1250);
return;
}
int OtherOption = Random.Next(0, Options.Length);
Console.WriteLine($"{Options[Option]} vs. {Options[OtherOption]}");
switch (WinMatrix[Option, OtherOption])
{
case -1: Console.WriteLine("You lose"); break;
case 1: Console.WriteLine("You win"); break;
default: Console.WriteLine("Draw"); break;
}
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment