Exemple #1
0
 private void sendMovesToService(Move tank1Move, Move tank2Move)
 {
     if (tank1Move != null && tank2Move != null)
     {
         _service.setActions(tank1Move.Action, tank2Move.Action);
     }
     else if (tank1Move != null)
     {
         _service.setAction(tank1Move.Tank, tank1Move.Action);
     }
     else if (tank2Move != null)
     {
         _service.setAction(tank2Move.Tank, tank2Move.Action);
     }
 }
Exemple #2
0
        public Move GetBestMove(ChallengeService.game game, BoardCell[][] board, ChallengeService.player me, ChallengeService.player enemy)
        {
            Move move = null;
            ChallengeService.unit tank = findTankInPlayer(_tankId, me);

            if (tank == null)
            {
                return null;
            }

            if (tank.x != _lastX || tank.y != _lastY)
            {
                _hasShotFromLastPosition = false;
            }

            var bulletInAir = checkIsBulletInAir(board, me, tank);
            var stuckLastTurn = checkStuckLastTurn(tank);

            var enemyBase = enemy.@base;

            var pastMidpoint = (Math.Abs(enemyBase.y-tank.y) < (board[0].Length / 2));

            if (stuckLastTurn && (tank.direction == ChallengeService.direction.UP || tank.direction == ChallengeService.direction.DOWN) && enemyBase.x != tank.x)
            {
                _targetX = tank.x + (pastMidpoint!=(tank.x > enemyBase.x) ? +1 : -1);
            }

            if (_checkForOpenPathToMiddle && !_headingToMiddle && tank.x != enemyBase.x)
            {
                _headingToMiddle = testPathToMiddleIsOpen(board, tank, enemyBase);
            }
            else if (_checkForOpenPathToMiddle && _headingToMiddle && tank.x == enemyBase.x)
            {
                _headingToMiddle = false;
            }

            ChallengeService.direction chosenDirection =
                _headingToMiddle ?
                (
                    tank.x > enemyBase.x ?
                    ChallengeService.direction.LEFT :
                    ChallengeService.direction.RIGHT
                ) :
                (
                    tank.y != enemyBase.y ?
                    (
                        _targetX.HasValue && _targetX != tank.x ?
                        (
                            tank.x > _targetX ?
                            ChallengeService.direction.LEFT :
                            ChallengeService.direction.RIGHT
                        ) :
                        (
                            tank.y > enemyBase.y ?
                            ChallengeService.direction.UP :
                            ChallengeService.direction.DOWN
                        )
                    ) :
                    (
                        tank.x > enemyBase.x ?
                        ChallengeService.direction.LEFT :
                        ChallengeService.direction.RIGHT
                    )
                );

            if (chosenDirection != tank.direction || bulletInAir || _headingToMiddle)
            {
                move = MoveInDirection(tank.id, chosenDirection);
            }
            else
            {
                move = new Move(tank.id, ChallengeService.action.FIRE);
                _hasShotFromLastPosition = true;
            }

            _lastX = tank.x;
            _lastY = tank.y;
            _lastAction = move.Action;

            return move;
        }