/** * Provides the ability to insert a new Score entity. * * @param board object representing the state of the board * @return the board including the computer's move */ @ApiMethod(name = "board.getmove", path = "getmove", httpMethod = "POST") public Board getmove( Board board, @Named("id") int id, @Named("row") int row, @Named("col") int col) { System.out.println("id: " + id); CellContainer cellContainer = CellContainer.fromJson(board.getState()); ArrayList<Cell> cells = cellContainer.cells; ArrayList<Cell> unoccupiedCells = new ArrayList<Cell>(); for (Cell cell : cells) { System.out.println("row: " + row + " | cell.x: " + cell.x); if (row == cell.x && col == cell.y && row != 100 && col != 100) { System.out.println("updated 1"); cell.val += (id + 1) * 10; CellContainer updateContainer = new CellContainer(cells); Board updated = new Board(CellContainer.toJson(updateContainer)); return updated; } if (cell.val <= 10) { unoccupiedCells.add(cell); } } if (id == 0) System.out.println("what"); Random randomG = new Random(); System.out.println("updated 2"); Cell randomfreeCell = unoccupiedCells.get(randomG.nextInt(unoccupiedCells.size())); randomfreeCell.val = randomfreeCell.val + (id + 1) * 10; CellContainer updateContainer = new CellContainer(cells); Board updated = new Board(CellContainer.toJson(updateContainer)); return updated; }