private boolean checkGameStatus(Position pos) { Piece[][] grid = board.getCurrentBoard(); int row = 0, column = 0, diagonal = 0, antiDiagonal = 0; int size = board.getSize(); int x = pos.getX(); int y = pos.getY(); for (int i = 0; i < size; i++) { if (!board.isEmptyPosition(new Position(x, i)) && board.getPiece(new Position(x, i)).getType() == turn) column++; if (!board.isEmptyPosition(new Position(i, y)) && board.getPiece(new Position(i, y)).getType() == turn) row++; if (!board.isEmptyPosition(new Position(i, i)) && board.getPiece(new Position(i, i)).getType() == turn) diagonal++; if (!board.isEmptyPosition(new Position(i, size - 1 - i)) && board.getPiece(new Position(i, size - 1 - i)).getType() == turn) antiDiagonal++; } System.out.print(row + " " + column + " " + diagonal + " " + antiDiagonal + "\n"); if (column == size || row == size || diagonal == size || antiDiagonal == size) { if (turn == X) { System.out.println("Player X has won!"); } else if (turn == O) { System.out.println("Player O has won!"); } return false; } return true; }
public boolean validMove(Position pos) { if (!board.withinBounds(pos)) { return false; } if (!board.isEmptyPosition(pos)) { return false; } return true; }