Quelques modifications mineures

This commit is contained in:
2006-04-29 01:25:12 +00:00
parent ed438e593a
commit 1a54cfd06f
5 changed files with 55 additions and 16 deletions

View File

@ -80,7 +80,7 @@ public class ComputerPlayer {
return Board.WHITE_WINS;
}
} else {
int bestMoveIndex=0;
ArrayList<Integer> bestMoveIndex=new ArrayList<Integer>();
int currentScore;
int bestScoreSoFar;
if (bitboard.getCurrentPlayer()==Piece.BLACK) {
@ -89,9 +89,12 @@ public class ComputerPlayer {
Board boardCopy = new Board(bitboard);
boardCopy.doMove(allLegalMoves.get(i));
currentScore=MinMax(boardCopy,currentDepth+1);
if (currentScore < bestScoreSoFar) { //black tries to minimise his score
bestScoreSoFar = currentScore;
bestMoveIndex = i;
if (currentScore <= bestScoreSoFar) { //black tries to minimise his score
if (currentScore<bestScoreSoFar) {
bestScoreSoFar = currentScore;
bestMoveIndex.clear();
}
bestMoveIndex.add(i);
}
}
} else { //white piece
@ -100,13 +103,20 @@ public class ComputerPlayer {
Board boardCopy = new Board(bitboard);
boardCopy.doMove(allLegalMoves.get(i));
currentScore=MinMax(boardCopy,currentDepth+1);
if (currentScore > bestScoreSoFar) { //white tries to maximise his score
bestScoreSoFar = currentScore;
bestMoveIndex = i;
if (currentScore >= bestScoreSoFar) { //white tries to maximise his score
if (currentScore>bestScoreSoFar) {
bestScoreSoFar = currentScore;
bestMoveIndex.clear();
}
bestMoveIndex.add(i);
}
}
}
bestMove = allLegalMoves.get(bestMoveIndex);
//select one of the best moves randomly
Random generator = new Random();
bestMove = allLegalMoves.get(bestMoveIndex.get(generator.nextInt(bestMoveIndex.size())));
return bestScoreSoFar;
}
}