Ejemplo n.º 1
0
        //Methods
        public void ShootAtTarget(Duelist target)
        {
            Random num  = new Random();
            double shot = num.NextDouble();

            if (shot <= ShootingAcc)
            {
                target.Alive = false;
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Duelist aaron       = new Duelist("Aaron", .33, true);
            Duelist bob         = new Duelist("Bob", .50, true);
            Duelist charlie     = new Duelist("Charlie", .995, true);
            int     aaronWins   = 0;
            int     bobWins     = 0;
            int     charlieWins = 0;
            int     total       = 0;


            for (int i = 0; i <= 10000; i++)
            {
                aaron.Alive   = true;
                bob.Alive     = true;
                charlie.Alive = true;

                do
                {
                    if (aaron.Alive && charlie.Alive)
                    {
                        aaron.ShootAtTarget(charlie);
                    }
                    else if (aaron.Alive && charlie.Alive == false && bob.Alive)
                    {
                        aaron.ShootAtTarget(bob);
                    }
                    else if (aaron.Alive && charlie.Alive == false && bob.Alive == false)
                    {
                        //Console.WriteLine("Aaron Wins!");
                        aaronWins++;
                        break;
                    }

                    if (bob.Alive && charlie.Alive)
                    {
                        bob.ShootAtTarget(charlie);
                    }
                    else if (bob.Alive && charlie.Alive == false && aaron.Alive)
                    {
                        bob.ShootAtTarget(aaron);
                    }
                    else if (bob.Alive && charlie.Alive == false && aaron.Alive == false)
                    {
                        //Console.WriteLine("Bob Wins!");
                        bobWins++;
                        break;
                    }

                    if (charlie.Alive && bob.Alive)
                    {
                        charlie.ShootAtTarget(bob);
                    }
                    else if (charlie.Alive && bob.Alive == false && aaron.Alive)
                    {
                        charlie.ShootAtTarget(aaron);
                    }
                    else if (charlie.Alive && bob.Alive == false && aaron.Alive == false)
                    {
                        //Console.WriteLine("Charlie Wins!");
                        charlieWins++;
                        break;
                    }
                } while (aaron.Alive || bob.Alive || charlie.Alive);
                total = i;
            }

            Console.WriteLine("That was " + total + " duels");
            Console.WriteLine("Aaron won " + aaronWins + " duels");
            Console.WriteLine("Bob won " + bobWins + " duels");
            Console.WriteLine("Charlie won " + charlieWins + " duels");
        }