/** * Checks for a victory condition. * * @param {string} boardString Current state of the board. * @return {number} Status code for the victory state. */ @ApiMethod(name = "board.checkForVictory", path = "checkForVictory", httpMethod = "POST") public Status checkForVictory(Board board) { CellContainer cellContainer = CellContainer.fromJson(board.getState()); ArrayList<Cell> cells = cellContainer.cells; int num_free = 0; int score_player1 = 0; int score_player2 = 0; for (int i = 0; i < cells.size(); i++) { Cell cell = cells.get(i); if (0 < cell.val && cell.val <= 10) { num_free += 1; } else if (10 < cell.val && cell.val <= 20) { score_player1 += cell.val - 10; } else if (20 < cell.val && cell.val <= 30) { score_player2 += cell.val - 20; } } Status s = new Status(); System.out.println("num free:" + num_free); if (num_free > 0) { s.setStatus(0); return s; } if (score_player1 > score_player2) { s.setStatus(1); return s; } if (score_player1 < score_player2) { s.setStatus(2); return s; } s.setStatus(3); return s; };