static void Main(string[] args)
        {
            var robotsOut = new List <Guid>();

            Console.ForegroundColor = ConsoleColor.White;
            var war = new Mediator(CompetitorsFactory.GetCompetitors());

            while (war.Robots.Count(robot => robot.Health > 0) > 1)
            {
                war.NextTurn();
                war.Robots.OrderBy(robot => robot.Name).ToList().ForEach(robot =>
                {
                    if (robot.Health <= 0)
                    {
                        if (!robotsOut.Contains(robot.Id))
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"{robot.Name} is out! :(");
                            Console.ForegroundColor = ConsoleColor.White;
                            robotsOut.Add(robot.Id);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"{robot.Name} health is {robot.Health.ToString()}");
                    }
                });
                Console.WriteLine("");
                System.Threading.Thread.Sleep(400);
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"{war.Robots.SingleOrDefault(r => r.Health > 0).Name} Wins! :)");
            Console.ReadLine();
        }
Beispiel #2
0
        public void TestMethod1()
        {
            var robots = CompetitorsFactory.GetCompetitors();

            var results = robots.Select(r => new WarResults
            {
                Name = r.GetName(),
                Wins = 0
            }).ToList();

            for (int i = 0; i < 100; i++)
            {
                var robotsOut = new List <Guid>();
                var war       = new Mediator(robots);

                while (war.Robots.Count(robot => robot.Health > 0) > 1 && war.TurnCounter < 100)
                {
                    war.NextTurn();
                    war.Robots.OrderBy(robot => robot.Name).ToList().ForEach(robot =>
                    {
                        if (robot.Health <= 0)
                        {
                            if (!robotsOut.Contains(robot.Id))
                            {
                                robotsOut.Add(robot.Id);
                            }
                        }
                    });
                }

                var winningRobot = war.Robots.OrderByDescending(b => b.Health).Where(b => b.Health > 0).FirstOrDefault();
                results.SingleOrDefault(r => r.Name == winningRobot.Name).Wins++;
            }

            results = results.OrderByDescending(r => r.Wins).ToList();
        }