Exemple #1
0
        public void MakeDecision()
        {
            var copy = new List <Vector2>(Players.Clone());
            var bros = copy.OrderBy(x => x.Distance(BallPosition)).Select(IndexOfClosest).ToList();

            var closest = bros[0];
            var atk1    = bros[1];
            var atk2    = bros[2];
            var def1    = bros[3];
            var def2    = bros[4];

            if (!HasBall) // SEEK
            {
                NewPositions[closest] = new Vector2(BallPosition);

                NewPositions[atk1] = new Vector2(NewPositions[closest]);
                NewPositions[atk2] = new Vector2(NewPositions[closest]);

                NewPositions[def1] = new Vector2(25, 20);
                NewPositions[def2] = new Vector2(25, 45);
            }
            else // ATTACK
            {
                if (Players[closest].X <= 60)
                {
                    var next = NextBuddy(Players[closest]);
                    if (next != null)
                    {
                        Attacking = true;
                        Attack    = new Vector2(next);
                    }
                }

                if (Players[closest].X > 83)
                {
                    var shift = Random.Next(15) - 8;
                    Attacking = true;
                    Attack    = new Vector2(100, NewPositions[closest].Y + shift);
                }

                NewPositions[closest] = new Vector2(100, Players[closest].Y);

                NewPositions[atk1] = new Vector2(NewPositions[closest].AverageWith(new Vector2(100, Players[atk1].Y)));
                NewPositions[atk2] = new Vector2(NewPositions[closest].AverageWith(new Vector2(100, Players[atk2].Y)));

                NewPositions[def1] = new Vector2(50, Players[def1].Y);
                NewPositions[def2] = new Vector2(50, Players[def2].Y);
            }
        }
Exemple #2
0
        private Vector2 NextBuddy(Vector2 myPos)
        {
            var copy = new List <Vector2>(Players.Clone());

            foreach (var p in copy.OrderBy(x => - x.X).Where(x => x.X > myPos.X + 0.1))
            {
                if (p.IsClose(myPos))
                {
                    continue;
                }
                if (NoEnemiesBetween(p, myPos))
                {
                    return(p);
                }
            }
            return(null);
        }