예제 #1
0
        static void Main(String[] args)
        {
            int aWin   = 0;
            int bWin   = 0;
            int cWin   = 0;
            int number = 0;
            //This variable allows us to skip aarons first shot
            bool skip = true;

            do
            {
                Duelist aaron   = new Duelist("Aaron", true, 3333);
                Duelist bob     = new Duelist("Bob", true, 5000);
                Duelist charlie = new Duelist("Charlie", true, 9950);
                int     alive   = 3;
                do
                {
                    if (!(skip))
                    {
                        alive -= aaron.shootAtTarget(bob, charlie);
                    }
                    else
                    {
                        skip = false;
                    }
                    alive -= bob.shootAtTarget(aaron, charlie);
                    alive -= charlie.shootAtTarget(aaron, bob);
                } while (alive != 1);

                if (aaron.IsAlive)
                {
                    aWin += 1;
                }
                if (bob.IsAlive)
                {
                    bWin += 1;
                }
                if (charlie.IsAlive)
                {
                    cWin += 1;
                }
                number += 1;
            } while (number != 100000);
            Console.WriteLine("Aaron won " + aWin + "/100000 times");
            Console.WriteLine("Bob won " + bWin + "/100000 times");
            Console.WriteLine("Charlie won " + cWin + "/100000 times");
        }
예제 #2
0
        public int shootAtTarget(Duelist otherGuy1, Duelist otherGuy2)
        {
            Random rnd    = new Random();
            int    number = rnd.Next(10000);
            int    kill   = 0;

            if (number <= skill && isAlive)
            {
                kill = 1;
                if (otherGuy1.Skill >= otherGuy2.Skill && otherGuy1.isAlive)
                {
                    otherGuy1.IsAlive = false;
                }
                else if (otherGuy2.isAlive)
                {
                    otherGuy2.IsAlive = false;
                }
                else
                {
                    otherGuy1.IsAlive = false;
                }
            }
            return(kill);
        }
예제 #3
0
        static void Main(string[] args)
        {
            int aaronWins, bobWins, charlieWins = 0;

            for (int i = 0; i < 10000; i++)
            {
                Duelist aaron   = new Duelist("Aaron", 0.33);
                Duelist bob     = new Duelist("Bob", 0.5);
                Duelist charlie = new Duelist("Charlie", 0.995);
                int     count 3; // shooters alive

                while (count > 1)
                {
                    if (aaron.Alive)
                    {
                        if (charlie.Alive)
                        {
                            aaron.ShootAtTarget(charlie);
                            if (!charlie.Alive)
                            {
                                count--;
                            }
                        }
                        else
                        {
                            aaron.ShootAtTarget(bob)
                            if (!bob.Alive)
                            {
                                count--;
                            }
                        }
                    }
                    if (bob.Alive)
                    {
                        if (charlie.Alive)
                        {
                            bob.ShootAtTarget(charlie);
                            if (!charlie.Alive)
                            {
                                count--;
                            }
                        }
                        else
                        {
                            bob.ShootAtTarget(aaron);
                            if (aaron.Alive)
                            {
                                aaronWins++;
                            }
                        }
                    }
                    if (charlie.Alive)
                    {
                        if (bob.Alive)
                        {
                            charlie.ShootAtTarget(bob);
                            if (!bob.Alive)
                            {
                                count--;
                            }
                            else
                            {
                                charlie.ShootAtTarget(aaron);
                                if (!aaron.Alive)
                                {
                                    count--;
                                }
                            }
                        }
                    }
                    if (aaron.Alive)
                    {
                        aaronWins++;
                    }
                    else if (bob.Alive)
                    {
                        bobWins++;
                    }
                    else
                    {
                        charlieWins++;
                    }
                }
                Console.WriteLine("Aaron won {0} times.", aaronWins);
                Console.WriteLine("Bob won {0} times,", bobWins);
                Console.WriteLine("Charlie won {0} times.", charlieWins);
            }
            Console.ReadLine();
        }