Exemplo n.º 1
0
        public override Position GetMove(RadarScan scan)
        {
            var myPos    = scan.MyPosition;
            var enemyPos = scan.EnemyPositions;

            List <int> i = new List <int>();

            i.Add(myPos.X - enemyPos[0].X);
            i.Add(enemyPos[0].X - myPos.X);
            i.Add(myPos.Y - enemyPos[0].Y);
            i.Add(enemyPos[0].Y - myPos.Y);

            int indexMax = i.IndexOf(i.Max());

            switch (indexMax)
            {
            case 0:
                return(ConvertDirectionToPosition(Direction.Left));

            case 1:
                return(ConvertDirectionToPosition(Direction.Right));

            case 2:
                return(ConvertDirectionToPosition(Direction.Up));

            case 3:
                return(ConvertDirectionToPosition(Direction.Down));

            default:
                return(ConvertDirectionToPosition(Direction.Up));
            }
        }
Exemplo n.º 2
0
        public override Position GetMove(RadarScan scan)
        {
            var mostSpace = new int[]
            {
                scan.Up,
                scan.Down,
                scan.Left,
                scan.Right
            }.OrderByDescending(x => x).First();

            Direction direction;

            if (scan.Up == mostSpace)
            {
                direction = Direction.Up;
            }
            else if (scan.Down == mostSpace)
            {
                direction = Direction.Down;
            }
            else if (scan.Left == mostSpace)
            {
                direction = Direction.Left;
            }
            else
            {
                direction = Direction.Right;
            }

            return(ConvertDirectionToPosition(direction));
        }
Exemplo n.º 3
0
        public override Position GetMove(RadarScan scan)
        {
            var closestWall = new int[]
            {
                scan.Up,
                scan.Down,
                scan.Left,
                scan.Right
            }.OrderBy(x => x).First();

            if (this.CurrentDirection == null)
            {
                if (scan.Up == closestWall)
                {
                    CurrentDirection = Direction.Up;
                }
                else if (scan.Down == closestWall)
                {
                    CurrentDirection = Direction.Down;
                }
                else if (scan.Left == closestWall)
                {
                    CurrentDirection = Direction.Left;
                }
                else
                {
                    CurrentDirection = Direction.Right;
                }
            }

            var rangeFromWall = GetWallInDirection(scan, this.CurrentDirection.Value);

            if (rangeFromWall <= 2)
            {
                switch (CurrentDirection)
                {
                case Direction.Up:
                    CurrentDirection = Direction.Right;
                    break;

                case Direction.Right:
                    CurrentDirection = Direction.Down;
                    break;

                case Direction.Down:
                    CurrentDirection = Direction.Left;
                    break;

                default:
                    CurrentDirection = Direction.Up;
                    break;
                }
            }

            return(ConvertDirectionToPosition(CurrentDirection.Value));
        }
Exemplo n.º 4
0
        public override Position GetMove(RadarScan scan)
        {
            if (!this.RemainingMoves.HasValue || this.RemainingMoves.Value <= 0)
            {
                var previousDirection = this.Direction;
                this.Direction = this.Random.Next(0, 3);
                if (this.Direction == 0 && previousDirection == 1)
                {
                    this.Direction = 2;
                }
                if (this.Direction == 1 && previousDirection == 0)
                {
                    this.Direction = 3;
                }
                if (this.Direction == 2 && previousDirection == 3)
                {
                    this.Direction = 0;
                }
                if (this.Direction == 3 && previousDirection == 2)
                {
                    this.Direction = 1;
                }

                var spaceArray = new int[]
                {
                    scan.Up,
                    scan.Down,
                    scan.Left,
                    scan.Right,
                };

                var maxSpace = spaceArray.ElementAt(this.Direction);

                this.RemainingMoves = this.Random.Next(Math.Min(30, maxSpace));
            }

            this.RemainingMoves--;
            switch (this.Direction)
            {
            case 0:
                return(new Position(this.Position.X, this.Position.Y - 1));

            case 1:
                return(new Position(this.Position.X, this.Position.Y + 1));

            case 2:
                return(new Position(this.Position.X - 1, this.Position.Y));

            default:
                return(new Position(this.Position.X + 1, this.Position.Y));
            }
        }
Exemplo n.º 5
0
        protected int GetWallInDirection(RadarScan scan, Direction value)
        {
            switch (value)
            {
            case Direction.Up:
                return(scan.Up);

            case Direction.Right:
                return(scan.Right);

            case Direction.Down:
                return(scan.Down);

            default:
                return(scan.Left);
            }
        }
Exemplo n.º 6
0
        public override Position GetMove(RadarScan scan)
        {
            switch (this.Direction)
            {
            case 0:
                return(new Position(this.Position.X, this.Position.Y - 1));

            case 1:
                return(new Position(this.Position.X, this.Position.Y + 1));

            case 2:
                return(new Position(this.Position.X - 1, this.Position.Y));

            default:
                return(new Position(this.Position.X + 1, this.Position.Y));
            }
        }
Exemplo n.º 7
0
        public override Position GetMove(RadarScan scan)
        {
            if (!CurrentDirection.HasValue)
            {
                CurrentDirection = Direction.Up;
                this.StepsNeeded = 1;
            }
            else
            {
                if (this.GetWallInDirection(scan, this.CurrentDirection.Value) < 2)
                {
                    var desiredDirection = GetDesiredDirection(this.CurrentDirection.Value);
                    var range            = GetWallInDirection(scan, desiredDirection);
                    int i = 0;
                    while (range < 3 && i < 5)
                    {
                        desiredDirection = GetDesiredDirection(this.CurrentDirection.Value);
                        range            = GetWallInDirection(scan, desiredDirection);
                        i++;
                    }

                    this.CurrentDirection = desiredDirection;
                    this.StepsTaken       = 0;
                    this.StepsNeeded      = 1;
                }
                if (StepsNeeded == StepsTaken)
                {
                    this.CurrentDirection = GetDesiredDirection(this.CurrentDirection.Value);
                    if (this.CurrentDirection == Direction.Down || this.CurrentDirection == Direction.Up)
                    {
                        StepsNeeded++;
                    }
                    this.StepsTaken = 0;
                }
            }

            this.StepsTaken++;
            return(ConvertDirectionToPosition(this.CurrentDirection.Value));
        }
Exemplo n.º 8
0
 public abstract Position GetMove(RadarScan scan);