Skip to content

Commit

Permalink
Added defence against 123 move
Browse files Browse the repository at this point in the history
  • Loading branch information
vaquierm committed Apr 4, 2019
1 parent e6c8d5a commit c27269d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
64 changes: 33 additions & 31 deletions src/student_player/CustomPentagoBoardState.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,37 +679,6 @@ private int computePatternValuesForPiece(Piece piece, boolean offensiveMode) {
overallScore += computeBonusSamePatternInDiffQuad(patternPresent, i);
}

// Calculate the game ending triplet moves
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (i == j)
continue;

for (int k = 0; k < 4; k++) {
if (k == j || k == i)
continue;

for (int s = 0; s < gameEndingTriplet.length; s++) {
// The triplet exists
if ((quadrantValues[i] & gameEndingTriplet[s]) == gameEndingTriplet[s]) {
// A corresponding double exists
if ((quadrantValues[j] & correspondingDouble[s][0]) == correspondingDouble[s][0]
|| (quadrantValues[j] & correspondingDouble[s][1]) == correspondingDouble[s][1]
|| ((quadrantValues[j] & correspondingSingle[s]) == correspondingSingle[s]
&& (quadrantValuesOpponent[j] & (correspondingSingle[s] ^ gameEndingTriplet[s])) == 0)) {
// A corresponding single exists with no blocking from opponent
if ((quadrantValues[k] & correspondingSingle[s]) == correspondingSingle[s]
&& (quadrantValuesOpponent[k] & (correspondingSingle[s] ^ gameEndingTriplet[s])) == 0) {
return Integer.MAX_VALUE;
}
}
}
}
}
}
}


return overallScore;

}
Expand Down Expand Up @@ -848,6 +817,39 @@ else if (board[i][BOARD_SIZE - i - 1] != piece) {
}
}

int[] quadrantValues = getQuadrantIntValue(piece);
int[] quadrantValuesOpponent = getQuadrantIntValue(opponent);

// Calculate the game ending triplet moves
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (i == j)
continue;

for (int k = 0; k < 4; k++) {
if (k == j || k == i)
continue;

for (int s = 0; s < gameEndingTriplet.length; s++) {
// The triplet exists
if ((quadrantValues[i] & gameEndingTriplet[s]) == gameEndingTriplet[s]) {
// A corresponding double exists
if ((quadrantValues[j] & correspondingDouble[s][0]) == correspondingDouble[s][0]
|| (quadrantValues[j] & correspondingDouble[s][1]) == correspondingDouble[s][1]
|| ((quadrantValues[j] & correspondingSingle[s]) == correspondingSingle[s]
&& (quadrantValuesOpponent[j] & (correspondingSingle[s] ^ gameEndingTriplet[s])) == 0)) {
// A corresponding single exists with no blocking from opponent
if ((quadrantValues[k] & correspondingSingle[s]) == correspondingSingle[s]
&& (quadrantValuesOpponent[k] & (correspondingSingle[s] ^ gameEndingTriplet[s])) == 0) {
return true;
}
}
}
}
}
}
}

return false;
}

Expand Down
21 changes: 11 additions & 10 deletions src/student_player/MonteCarloTreeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,17 @@ else if (boardState.getWinner() == Board.DRAW) {
else {
returnStatus = Status.PROGRESS;

for (PentagoMove nextMove : boardState.getAllLegalMovesWithSymmetry()) {

int leadsTo = moveLeadsToDeepLoss(nextMove, boardState, player);
if(leadsTo == 1) {
returnStatus = Status.LOSS;
boardState.revertMove(move);
return new Pair<>(returnStatus, returnVal);
}
else if (leadsTo == 2) {
returnStatus = Status.CRITICAL;
if (boardState.getTurnNumber() >= 2) {
for (PentagoMove nextMove : boardState.getAllLegalMovesWithSymmetry()) {

int leadsTo = moveLeadsToDeepLoss(nextMove, boardState, player);
if (leadsTo == 1) {
returnStatus = Status.LOSS;
boardState.revertMove(move);
return new Pair<>(returnStatus, returnVal);
} else if (leadsTo == 2) {
returnStatus = Status.CRITICAL;
}
}
}

Expand Down

0 comments on commit c27269d

Please sign in to comment.