Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace RockPaperScissors
- {
- class Program
- {
- static void Main()
- {
- var rand = new Random();
- var HumanChoices = string.Empty;
- char[] GameChoices = {'R', 'P', 'S'};
- var HumanWins = 0;
- var ComputerWins = 0;
- while (true)
- {
- Console.WriteLine("Human Totals\tComputer Totals\tHuman\tComputer");
- Console.Write("------------\t---------------\t-----\t-------- ");
- while (HumanWins < 101 && ComputerWins < 101)
- {
- var ComputerChoice = rand.Next(1, int.MaxValue) % 3;
- var SetOfMovesLength = 2;
- if (HumanChoices.Length >= SetOfMovesLength + 1)
- {
- var LastSetOfMoves = HumanChoices.Substring(HumanChoices.Length - SetOfMovesLength);
- int count = 0;
- for (var i = 0; i <= HumanChoices.Length - LastSetOfMoves.Length - 1; i++)
- {
- if (HumanChoices.Substring(i, LastSetOfMoves.Length + 1) == LastSetOfMoves + "0") count++;
- }
- var NumRocks = count;
- count = 0;
- for (var i = 0; i <= HumanChoices.Length - LastSetOfMoves.Length - 1; i++)
- {
- if (HumanChoices.Substring(i, LastSetOfMoves.Length + 1) == LastSetOfMoves + "1") count++;
- }
- var NumPapers = count;
- count = 0;
- for (var i = 0; i <= HumanChoices.Length - LastSetOfMoves.Length - 1; i++)
- {
- if (HumanChoices.Substring(i, LastSetOfMoves.Length + 1) == LastSetOfMoves + "2") count++;
- }
- var NumScissors = count;
- var tempMax = NumRocks;
- var l = new List<int>();
- if (tempMax < NumPapers) tempMax = NumPapers;
- if (tempMax < NumScissors) { tempMax = NumScissors; l.Add(2); }
- if (tempMax == NumPapers) l.Add(1);
- if (tempMax == NumRocks) l.Add(0);
- ComputerChoice = (l[0] + 1) % 3;
- if (l.Count > 1) ComputerChoice = (l[(rand.Next(1, int.MaxValue) % l.Count)] + 1) % 3;
- }
- //10% chance of a random choice
- if (rand.Next(1, int.MaxValue) % 10 == 1) ComputerChoice = rand.Next(1, int.MaxValue) % 3;
- Console.Write("Enter Choice(R/P/S) ");
- ConsoleKeyInfo temp;
- do
- {
- temp = Console.ReadKey(true);
- }
- while (temp.Key.ToString().ToUpper() != "R" &&
- temp.Key.ToString().ToUpper() != "P" &&
- temp.Key.ToString().ToUpper() != "S");
- Console.WriteLine(temp.Key.ToString().ToUpper());
- var HumanChoice = temp.Key.ToString() == "R" ? 0 : temp.Key.ToString() == "P" ? 1 : 2;
- if (HumanChoice == ComputerChoice - 1 || (HumanChoice == 2 && ComputerChoice == 0)) ComputerWins++;
- else if (HumanChoice - 1 == ComputerChoice || (HumanChoice == 0 && ComputerChoice == 2)) HumanWins++;
- HumanChoices += HumanChoice.ToString();
- Console.Write(HumanWins.ToString().PadLeft(7) + "\t\t" + ComputerWins.ToString().PadLeft(9) + "\t" +
- GameChoices[HumanChoice] + "\t" + GameChoices[ComputerChoice] + "\t ");
- }
- if(HumanWins>ComputerWins) Console.WriteLine("Human Wins!");
- else Console.WriteLine("Computer Wins!");
- Console.WriteLine();
- Console.WriteLine("To Play Again Press The Spacebar Or Any Other Key To Quit.");
- if (Console.ReadKey(true).Key.ToString() != "Spacebar") break;
- Console.WriteLine();
- HumanWins = 0;
- ComputerWins = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement