Ejemplo n.º 1
0
        public void RunTest(ulong Times)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            bool  LizardPlusSpock = true;
            ulong RepeatCount     = Times;

            for (ulong i = 0; i < RepeatCount; i++)
            {
                Objects MyChoose = Objects.Rock;

                int ComputerChoose;

                if (LizardPlusSpock)
                {
                    ComputerChoose = RandomNumber.Between(0, 4);
                }
                else
                {
                    ComputerChoose = RandomNumber.Between(0, 2);
                }


                MyChoose = GameRPS.ConvertToObject(ComputerChoose);

                Objects pcChoose;

                bool YouWin = GameRPS.Play(MyChoose, LizardPlusSpock, out pcChoose, out string error);

                //if remis
                if (MyChoose == pcChoose)
                {
                    Console.WriteLine($"Remis! {MyChoose} vs {pcChoose}");
                    RemisCount++;
                }
                else
                {
                    if (YouWin)
                    {
                        Console.WriteLine($"You Win! {MyChoose} vs {pcChoose}");
                        WinCount++;
                    }
                    else
                    {
                        Console.WriteLine($"You Lose! {MyChoose} vs {pcChoose}");
                        LoseCount++;
                    }
                }


                //Thread.Sleep(250);
            }

            sw.Stop();

            Thread.Sleep(1000);
            Console.Clear();

            double WinRate   = (double)WinCount / (double)RepeatCount;
            double LoseRate  = (double)LoseCount / (double)RepeatCount;
            double RemisRate = (double)RemisCount / (double)RepeatCount;

            Console.WriteLine($"Summary: WinCount: {WinCount} (Rate: {WinRate.ToString("P5")}), LoseCount: {LoseCount} (Rate: {LoseRate.ToString("P5")}), RemisCount: {RemisCount} (Rate: {RemisRate.ToString("P5")})");
            Console.WriteLine($"Total elapsed time: {sw.Elapsed}");
        }
Ejemplo n.º 2
0
        public static bool Play(Objects choose, bool LizardPlusSpock, out Objects pc, out string ErrorCode)
        {
            //Thread.Sleep(250);

            //random object
            Objects ComputerChooseObject = Objects.Rock;

            int ComputerChoose;

            if (LizardPlusSpock)
            {
                ComputerChoose = RandomNumber.Between(0, 4);
            }
            else
            {
                ComputerChoose = RandomNumber.Between(0, 2);
            }


            ComputerChooseObject = ConvertToObject(ComputerChoose);


            pc        = ComputerChooseObject;
            ErrorCode = String.Empty;

            if (!LizardPlusSpock)
            {
                if (choose == Objects.Lizard || choose == Objects.Spock)
                {
                    ErrorCode = "Lizard Or Spock is not allowed in this mode.";
                    return(false);
                }
            }

            //check who wins
            if (choose == Objects.Rock)
            {
                if (ComputerChooseObject == Objects.Scissors || ComputerChooseObject == Objects.Lizard)
                {
                    return(true);
                }
            }
            else if (choose == Objects.Paper)
            {
                if (ComputerChooseObject == Objects.Rock || ComputerChooseObject == Objects.Spock)
                {
                    return(true);
                }
            }
            else if (choose == Objects.Scissors)
            {
                if (ComputerChooseObject == Objects.Paper || ComputerChooseObject == Objects.Lizard)
                {
                    return(true);
                }
            }
            else if (choose == Objects.Lizard)
            {
                if (ComputerChooseObject == Objects.Paper || ComputerChooseObject == Objects.Spock)
                {
                    return(true);
                }
            }
            else if (choose == Objects.Spock)
            {
                if (ComputerChooseObject == Objects.Rock || ComputerChooseObject == Objects.Scissors)
                {
                    return(true);
                }
            }

            return(false);
        }