AI enhancement
This commit is contained in:
parent
ea340e5cda
commit
fa8ce856f1
|
@ -66,13 +66,13 @@ public class MaurizioAI implements Player {
|
|||
return moves1.peek();
|
||||
}
|
||||
|
||||
//copy moves that do not loose
|
||||
LinkedList<Integer> moves2 = new LinkedList<Integer>();
|
||||
for(int i : moves1){
|
||||
moves2.add(i);
|
||||
}
|
||||
|
||||
//find the best of the non losing move
|
||||
//look for two move wins
|
||||
//look for two move wins among the non-loosing moves
|
||||
LinkedList<Integer> removes = new LinkedList<Integer>();
|
||||
for(int i : moves2){
|
||||
int[][] boardNew = makeMove(board, i, id);
|
||||
|
@ -83,6 +83,7 @@ public class MaurizioAI implements Player {
|
|||
int[][] boardNewNew = makeMove(boardNew, j, enemyID);
|
||||
for(int k=0;k<Game.GAME_COLUMNS;k++){
|
||||
if(boardNewNew[k][0] == 0 && checkWin(boardNewNew, k, id)){
|
||||
// if opponent plays move j than we have a winning move
|
||||
winner2 = true;
|
||||
break;
|
||||
}
|
||||
|
@ -93,6 +94,8 @@ public class MaurizioAI implements Player {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// winner1 == false means that the opponent had a reply after which we couldn't
|
||||
// directly win
|
||||
if(!winner1){
|
||||
removes.add(i);
|
||||
}
|
||||
|
@ -149,7 +152,7 @@ public class MaurizioAI implements Player {
|
|||
while (pos < (board[0].length - 1) && board[choice][pos + 1] == 0) {
|
||||
pos++;
|
||||
}
|
||||
// Change the board accordingl
|
||||
// Change the board accordingly
|
||||
int[][] boardNew = copyBoard(board);
|
||||
boardNew[choice][pos] = id;
|
||||
return boardNew;
|
||||
|
@ -169,7 +172,7 @@ public class MaurizioAI implements Player {
|
|||
return ((x>=0 && x < Game.GAME_COLUMNS) && (y>=0 && y < Game.GAME_ROWS));
|
||||
}
|
||||
/**
|
||||
* checks whether the last Move closed any lines on the board
|
||||
* checks whether the last move closed any lines on the board
|
||||
*/
|
||||
private boolean checkWin(int[][] board, int col, int iD){
|
||||
// find row of last move -- assuming the move was legal
|
||||
|
|
Loading…
Reference in a new issue