diff --git a/src/game/Game.java b/src/game/Game.java index 37985ab..c4e1973 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -154,13 +154,13 @@ public class Game { if(output){ System.out.println(other(currentP).getP().getName() + " wins."); } - return other(currentP).getID(); // TODO this only works if the players hav IDs 1 and 2 + return other(currentP).getID(); // TODO only works if the players have IDs 1 and 2 } } // Uninstall Jansi AnsiConsole.systemUninstall(); System.out.println("BUG!"); - return checkState(false); // this is impossible to reach this, but it makes the compiler happy ;) + return checkState(false); // can't be reached } /** diff --git a/src/player/maurizio/MaurizioAI.java b/src/player/maurizio/MaurizioAI.java index 7ccb57f..5fc3e07 100644 --- a/src/player/maurizio/MaurizioAI.java +++ b/src/player/maurizio/MaurizioAI.java @@ -30,9 +30,9 @@ public class MaurizioAI implements Player { public int move(int[][] board){ // check for one move wins int m1 = winningMove(board, id); - if(m1 != -1){ - return m1; - } + if(m1 != -1){ + return m1; + } // create a list of all legal moves LinkedList moves1 = new LinkedList(); @@ -46,10 +46,10 @@ public class MaurizioAI implements Player { for(int i=0;i allMoves(){ + LinkedList ret = new LinkedList(); + for(int i=0;i moves){ + for(int i : moves){ + if(board[i][0] != 0){ + continue; + } + int[][] boardNew = makeMove(board, i, id); + boolean winner1 = true; + for(int j=0;j moves){ + if (moves.isEmpty()) { + return -1; // empty list + } + if(moves.contains(3) && board[3][0] == 0){ + return 3; + } + if(moves.contains(2) && board[2][0] == 0){ + return 2; + } + if(moves.contains(4) && board[4][0] == 0){ + return 4; + } + if(moves.contains(1) && board[1][0] == 0){ + return 1; + } + if(moves.contains(5) && board[5][0] == 0){ + return 5; + } + if(moves.contains(0) && board[0][0] == 0){ + return 0; + } + if(moves.contains(6) && board[6][0] == 0){ + return 6; + } + + return -1; // Can' t happen + } + private int[][] makeMove(int[][] board, int choice, int id) { // Check his choice against the current board. if (choice < 0 || choice > Game.GAME_COLUMNS || board[choice][0] != 0) {