| 42 | |
| 43 | /* Only works for 3x3 board */ |
| 44 | public static Piece hasWon1(Piece[][] board) { |
| 45 | for (int i = 0; i < board.length; i++) { |
| 46 | if (board[i][0] != Piece.Empty && board[i][0] == board[i][1] && board[i][0] == board[i][2]) { |
| 47 | return board[i][0]; |
| 48 | } |
| 49 | if (board[0][i] != Piece.Empty && board[0][i] == board[1][i] && board[0][i] == board[2][i]) { |
| 50 | return board[0][i]; |
| 51 | } |
| 52 | } |
| 53 | if (board[0][0] != Piece.Empty && board[0][0] == board[1][1] && board[0][0] == board[2][2]) { |
| 54 | return board[0][0]; |
| 55 | } |
| 56 | if (board[2][0] != Piece.Empty && board[2][0] == board[1][1] && board[2][0] == board[0][2]) { |
| 57 | return board[2][0]; |
| 58 | } |
| 59 | return Piece.Empty; |
| 60 | } |
| 61 | |
| 62 | /* NxN board - prioritizes code reuse */ |
| 63 | public static Piece hasWon2(Piece[][] board) { |