예제 #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;
}