AI sees two move loosing tricks
This commit is contained in:
parent
5605076dbf
commit
37d9f8da73
|
@ -82,12 +82,44 @@ public class MaurizioAI implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//no 2-move winning moves, then choose a non-loosing move
|
//copy moves
|
||||||
if(moves1.isEmpty()){
|
LinkedList<Integer> moves2 = new LinkedList<Integer>();
|
||||||
|
for(int i : moves1){
|
||||||
|
moves2.add(i);
|
||||||
|
}
|
||||||
|
// avoid 2-move losses
|
||||||
|
for(int i : moves1){ // I make a move
|
||||||
|
int[][] board1 = makeMove(board, i, id);
|
||||||
|
for(int j=0;j<Game.GAME_COLUMNS;j++){ // opponent makes a move
|
||||||
|
if(board1[j][0] != 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int[][] board2 = makeMove(board1, j, enemyID);
|
||||||
|
for(int k=0;k<Game.GAME_COLUMNS;k++){ // I make another move
|
||||||
|
if(board2[k][0] != 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int[][] board3 = makeMove(board2, k, id);
|
||||||
|
//have to make sure that no move of my opponent wins
|
||||||
|
int move = winningMove(board3, enemyID);
|
||||||
|
if(move != -1){
|
||||||
|
moves2.remove((Object) i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!moves2.isEmpty()){
|
||||||
|
this.ran = new Random();
|
||||||
|
int choice = ran.nextInt(moves2.size());
|
||||||
|
return moves2.get(choice);
|
||||||
|
} else {
|
||||||
|
if(!moves1.isEmpty()){
|
||||||
this.ran = new Random();
|
this.ran = new Random();
|
||||||
int choice = ran.nextInt(moves1.size());
|
int choice = ran.nextInt(moves1.size());
|
||||||
return moves1.get(choice);
|
return moves1.get(choice);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return moveRandom(board); // can't be reached
|
return moveRandom(board); // can't be reached
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue