コード例 #1
0
        private static Direction SelectDetour(Ship ship, Direction direction, Position target)
        {
            var right_direction = DirectionExtensions.TurnRight(direction);
            var right_position  = game.gameMap.GetTargetPosition(ship.position, right_direction);
            var right_blocked   = HasBlockingShip(ship.owner.id, right_position);

            var left_direction = DirectionExtensions.TurnLeft(direction);
            var left_position  = game.gameMap.GetTargetPosition(ship.position, left_direction);
            var left_blocked   = HasBlockingShip(ship.owner.id, left_position);

            if (right_blocked && left_blocked)
            {
                return(Direction.STILL);                               // no detour avaialable
            }
            // define detour direction to cell closest to target or highest halite value.
            var detour_direction = Direction.STILL;

            if (right_blocked == false && left_blocked == true)
            {
                detour_direction = right_direction;
            }
            if (right_blocked == true && left_blocked == false)
            {
                detour_direction = left_direction;
            }
            if (right_blocked == false && left_blocked == false)
            {
                var right_distance = game.gameMap.CalculateDistance(right_position, target);
                var left_distance  = game.gameMap.CalculateDistance(left_position, target);
                if (right_distance < left_distance)
                {
                    detour_direction = right_direction;
                }
                if (left_distance < right_distance)
                {
                    detour_direction = left_direction;
                }
                if (right_distance == left_distance)
                {
                    if (game.gameMap.At(right_position).halite >= game.gameMap.At(left_position).halite)
                    {
                        detour_direction = right_direction;
                    }
                    else
                    {
                        detour_direction = left_direction;
                    }
                }
            }

            // give a continuation move to avoid coming back to current square
            if (detour_next_move.ContainsKey(ship.id.id))
            {
                detour_next_move.Remove(ship.id.id);
            }
            detour_next_move.Add(ship.id.id, direction);

            return(detour_direction);
        }