private GameStatus prepareStatus(boolean isGameOver, String message) { GameStatus gameStatus = new GameStatus(); gameStatus.setBoard(game.getBoard().toString()); gameStatus.setIsGameOver(isGameOver); gameStatus.setMessage(message); gameStatus.setWinMoves(game.getBoardStatus().getMarks()); gameStatus.setStatus("OK"); if (isGameOver) gameStatus.setWinner(game.getWinner()); return gameStatus; }
/* * move - humanMove- Cell coordinates will be given by user * Assumption: User will post proper input. - Bad input is not handled here */ public Result move(String moves) { if (game == null) throw new RuntimeException("Game is not initialized"); /* * 1. Make human move * 2. Check for gameOver - Yes - Prepare final Status and return * 3. Make bot move * 4. Check for gameOver - Yes - Prepare final Status and return * 5. Prepare intermediate Game Status and return */ game.humanMove(moves); if (game.isGameOver()) return ok(toJson(prepareStatus(true, "Game Ended").toString())); game.botMove(game.freePosition()); if (game.isGameOver()) return ok(toJson(prepareStatus(true, "Game Ended").toString())); // return ok(toJson(prepareStatus(false,"Game running"))); return ok(toJson(prepareStatus(false, "Game running").toString())); }