示例#1
0
 /// <summary>
 /// public method that attaches weapons to robots on the production line.
 /// </summary>
 public void AttachWeapons()
 {
     Robots?.ForEach(robot =>
     {
         weaponAttacherMachine.AttachWeapons(robot);
     });
 }
示例#2
0
 /// <summary>
 /// public method that paints robots on the production line.
 /// </summary>
 public void PaintRobots()
 {
     Robots?.ForEach(robot =>
     {
         paintMachine.Paint(robot);
     });
 }
示例#3
0
 public virtual void Initialize(IEngine engine, RobotSettings[] robotSettings)
 {
     Engine   = engine;
     Settings = ParseSettings(HelloPackage);
     Robots   = robotSettings.Select(x => x.IsBot ? CreateBot(x.Number) : CreateRobot(x.Number)).OrderBy(x => x.Number).ToList();
     Score    = new ScoreCollection(RobotCount);
     Engine.Initialize(Settings);
     Robots.ForEach(x => x.Init());
 }
示例#4
0
 private void UpdateRobots(float deltaTime)
 {
     try
     {
         Robots.ForEach(robot => robot.Update(deltaTime));
     }
     catch
     {
         return;
     }
 }
示例#5
0
        public void NextTurn()
        {
            if (TurnCounter == Robots.Count)
            {
                Robots.ForEach(r => { r.LastTurn = new DateTime(1900, 1, 1); });
                RandomizeStartOrder();
            }
            var robot       = Robots.Where(r => r.Health > 0).OrderBy(r => r.LastTurn).FirstOrDefault();
            var competitors = Robots.Where(r => r.Health > 0 && r.Id != robot.Id).Select(r => new RobotAction
            {
                Health  = r.Health,
                Name    = r.RobotImplementation.GetName(),
                Attacks = 0,
                Id      = r.Id
            }).ToList();
            var attacks = new List <RobotAction>();

            try
            {
                attacks = robot.RobotImplementation.MyTurn(competitors);
                if (attacks.Sum(attack => attack.Attacks) > 10)
                {
                    // Tough luck, robot tried to cheat so forefits their turn
                    attacks.Clear();
                }
            }
            catch (Exception)
            {
                // Tough luck, there was an error so the robot forefits their turn.
            }
            attacks.ForEach(attack =>
            {
                var robotToAttack = Robots.SingleOrDefault(r => r.Id == attack.Id);
                if (robotToAttack != null)
                {
                    robotToAttack.Health = robotToAttack.Health - attack.Attacks;
                }
                else
                {
                    // Tough luck, robot tried to manipulate the id's, cheating so firefits this attack
                }
            });

            Robots.ForEach(r =>
            {
                r.RobotImplementation.UpdateHealth(r.Health);
            });

            robot.LastTurn = DateTime.Now;

            TurnCounter++;
        }
示例#6
0
 public Mediator(List <IRobot> robots)
 {
     Robots = robots.Select(r => new Robot
     {
         Health = 100,
         RobotImplementation = r,
         Id       = Guid.NewGuid(),
         LastTurn = DateTime.Now,
         Name     = r.GetName()
     }).ToList();
     Robots.ForEach(r =>
     {
         if (Robots.Count(b => b.Name == r.Name) > 1)
         {
             throw new Exception("Duplicate robots exist.");
         }
     });
     RandomizeStartOrder();
 }