I have programmed a TicTacToe game. I created a list for checking if the game is over or still going on (checkGameOver). And the other one looks similiar but it is for checking who has won and it should print out, that player 1 or player 2 had won. When I run the game and when I play the top row fields 1 2 3. The computer print the message that the process is finished. But when I play the fiels 4 5 6 or anyother else the game do not finish.
Please let me know if you know the problem than I could send you the whole code.
*public static boolean checkGameOver(char [][] gameBoard){
List topRow = Arrays.asList(1, 2, 3);
List midRow = Arrays.asList(4, 5, 6);
List botRow = Arrays.asList(7, 8, 9);
List leftCol = Arrays.asList(1, 4, 7);
List midCol = Arrays.asList(2, 5, 8);
List rightCol = Arrays.asList(3, 6, 9);
List cross1 = Arrays.asList(1, 5, 9);
List cross2 = Arrays.asList(7, 5, 3);
List<List> gameOver = new ArrayList<List>();
gameOver.add(topRow);
gameOver.add(midRow);
gameOver.add(botRow);
gameOver.add(leftCol);
gameOver.add(midCol);
gameOver.add(rightCol);
gameOver.add(cross1);
gameOver.add(cross2);
for(List l : gameOver) {
if(playerPositions.containsAll(l) || computerPositions.contains(l)) {
return true;
} else {
return false;
}
}
return false;
}
public static String checkWinner(char [][] gameBoard) {
List topRow = Arrays.asList(1, 2, 3);
List midRow = Arrays.asList(4, 5, 6);
List botRow = Arrays.asList(7, 8, 9);
List leftCol = Arrays.asList(1, 4, 7);
List midCol = Arrays.asList(2, 5, 8);
List rightCol = Arrays.asList(3, 6, 9);
List cross1 = Arrays.asList(1, 5, 9);
List cross2 = Arrays.asList(7, 5, 3);
List<List> gameOver = new ArrayList<List>();
gameOver.add(topRow);
gameOver.add(midRow);
gameOver.add(botRow);
gameOver.add(leftCol);
gameOver.add(midCol);
gameOver.add(rightCol);
gameOver.add(cross1);
gameOver.add(cross2);
for(List l : gameOver) {
if(playerPositions.containsAll(l)) {
return "Glückwunsch du hast gewonnen!";
} else if(computerPositions.contains(l)) {
return "Computer hat gewonnen!";
} else if(playerPositions.size() + computerPositions.size() == 9) {
return "Unentschieden!";
}
}
return "";
}*
> gameOver` etc.