예제 #1
0
long MainPlayer::potentialMobilityHeuristic(const GameBoard &gameBoard, Tile tile) {
    long potentialMobility = 0;
    auto gameSize = gameBoard.getGameSize();
    auto enemyTile = gameBoard.getEnemyTile(tile);

    for (size_t row = 0; row < gameSize; ++row) {
        for (size_t column = 0; column < gameSize; ++column) {
            Cell here(row, column);
            if (gameBoard.getAt(here) != tile) {
                continue;
            }
            for (int offsetRow = -1; offsetRow < 2; ++offsetRow) {
                for (int offsetCol = -1; offsetCol < 2; ++offsetCol) {
                    if (offsetCol == 0 && offsetRow == 0) {
                        continue;
                    }
                    Direction direction(offsetRow, offsetCol);
                    auto neighbor = here;
                    neighbor.move(direction);
                    if (gameBoard.isCorrect(neighbor)
                        && gameBoard.getAt(neighbor) == enemyTile) {
                        ++potentialMobility;
                    }
                }
            }
        }
    }
    return potentialMobility;
}
예제 #2
0
long MainPlayer::evaluateGameBoard(const GameBoard &gameBoard, Tile tile) const {
    long value = 0;
    auto gameSize = gameBoard.getGameSize();
    auto enemyTile = gameBoard.getEnemyTile(tile);
    if (gameBoard.getEmptyCount() < 10) {
        edgeStabilityHeuristic(gameBoard, tile);
    }

    if (gameBoard.isGameOver()) {
        Score score = gameBoard.calculateScore();
        if (gameBoard.whoWins() == tile) {
            return 77777 + score.playersScore(tile) * 100;
        }
        if (gameBoard.whoWins() == enemyTile) {
            return -77777 - score.playersScore(enemyTile) * 100;
        }
    }

    long cornerValue = 0;
    for (size_t row = 0; row < gameSize; ++row) {
        for (size_t column = 0; column < gameSize; ++column) {
            if (gameBoard.getAt(row, column) == tile) {
                cornerValue += worth[row][column];
            }
        }
    }
    if (gamePhase == GAME_BEGIN) {
        value = (long) (cornerValue * 2 + 1 * mobilityHeuristic(gameBoard, tile) +
                        edgeStabilityHeuristic(gameBoard, tile) * 0.5);
    }
    if (gamePhase == GAME_MIDDLE) {
        value = cornerValue * 2 + mobilityHeuristic(gameBoard, tile) + edgeStabilityHeuristic(gameBoard, tile);
    }
    if (gamePhase == GAME_PREEND || gamePhase == GAME_END) {
        value = (long) (cornerValue + 0.5 * mobilityHeuristic(gameBoard, tile) +
                        edgeStabilityHeuristic(gameBoard, tile) * 1.5);
    }
    return value;
}