Beispiel #1
0
        public static string GetWhereToGo(string direction, Game game)
        {
            foreach (var target in game.Targets)
            {
                target.Distance = game.GetDistance(game.MyPosition, target.Position);
            }

            var primTarget = game.Targets.OrderBy(o => o.Distance).FirstOrDefault(d => d.Distance < 4);

            if (primTarget != null)
            {
                direction = GetOrientation(game.MyPosition, primTarget);
            }

            var compass = new CanGo();

            if (compass.UpTwo(game.MyPosition) && direction == Move.Up)
            {
                direction = Move.Up;
            }
            else if (compass.RightTwo(game.MyPosition) && direction == Move.Right)
            {
                direction = Move.Right;
            }
            else if (compass.DownTwo(game.MyPosition) && direction == Move.Down)
            {
                direction = Move.Down;
            }
            else if (compass.LeftTwo(game.MyPosition) && direction == Move.Left)
            {
                direction = Move.Left;
            }
            else
            {
                if (compass.UpTwo(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.RightTwo(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.DownTwo(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.LeftTwo(game.MyPosition))
                {
                    direction = Move.Left;
                }
                else if (compass.Up(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.Right(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.Down(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.Left(game.MyPosition))
                {
                    direction = Move.Left;
                }

            }
            return direction;
        }
Beispiel #2
0
        public static string GetWhereToGo(string direction, Game game)
        {
            foreach (var target in game.Targets)
            {
                target.Distance = game.GetDistance(game.MyPosition, target.Position);
            }

            var primTarget = game.Targets.OrderBy(o => o.Distance).FirstOrDefault(d => d.Distance < 4);


            if (primTarget != null)
            {
                direction = GetOrientation(game.MyPosition, primTarget);
            }

            var compass = new CanGo();

            if (compass.UpTwo(game.MyPosition) && direction == Move.Up)
            {
                direction = Move.Up;
            }
            else if (compass.RightTwo(game.MyPosition) && direction == Move.Right)
            {
                direction = Move.Right;
            }
            else if (compass.DownTwo(game.MyPosition) && direction == Move.Down)
            {
                direction = Move.Down;
            }
            else if (compass.LeftTwo(game.MyPosition) && direction == Move.Left)
            {
                direction = Move.Left;
            }
            else
            {
                if (compass.UpTwo(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.RightTwo(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.DownTwo(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.LeftTwo(game.MyPosition))
                {
                    direction = Move.Left;
                }
                else if (compass.Up(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.Right(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.Down(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.Left(game.MyPosition))
                {
                    direction = Move.Left;
                }
            }
            return(direction);
        }