Exemplo n.º 1
0
        public void ShootAtTarget(Duelist target)
        {
            double random = new Random().NextDouble();

            if (random <= accuracy)
            {
                target.alive = false;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] arguments)
        {
            Duelist[] duelists = new Duelist[3];
            duelists[0] = new Duelist("Aaron", 0.333);
            duelists[1] = new Duelist("Bob", 0.5);
            duelists[2] = new Duelist("Charlie", 0.995);

            for (int i = 0; i < 10000; i++)
            {
                SimulateDuel(duelists, false);
            }

            foreach (Duelist duelist in duelists)
            {
                double percentage = Math.Round(duelist.Wins / 100.0, 2);

                Console.WriteLine($"{duelist.Name} won {duelist.Wins}/10000 duels or {percentage}%");
            }
        }
Exemplo n.º 3
0
        static void SimulateDuel(Duelist[] duelists, bool skipFirst)
        {
            foreach (Duelist duelist in duelists)
            {
                duelist.Alive = true;
            }

            int round = 0;

            while (CountAlive(duelists) > 1)
            {
                for (int shooterIndex = 0; shooterIndex < 3; shooterIndex++)
                {
                    if (round == 0 && shooterIndex == 0 && skipFirst)
                    {
                        continue;
                    }
                    Duelist shooter = duelists[shooterIndex];
                    Duelist target  = GetBestTarget(duelists, shooterIndex);

                    if (shooter.Alive)
                    {
                        shooter.ShootAtTarget(target);
                    }
                }
                round++;
            }

            foreach (Duelist duelist in duelists)
            {
                if (duelist.Alive)
                {
                    duelist.Wins++;
                }
            }
        }
Exemplo n.º 4
0
 public bool Equals(Duelist other)
 {
     return(name.Equals(other.name));
 }