Exemple #1
0
 /**
  * Allows the input player to play a single ply of Othello. (Make a single move on the board). If
  * the player has no available moves, this will switch to the other player w/o requesting a move.
  * If the game is over, this will switch to the GAMEOVER state.
  */
 private void playPly() {
   if (stateManager.isStateChange()) {
     MoveList validMoves = GameLogic.getValidMoves(board, curPlayer.getState());
     if (validMoves.size() > 0) { // Make your move.
       aiThread = new AIThread(curPlayer, board.clone(), validMoves.toPoints());
       timer.reset();
       aiThread.start();
       return;
     } else {
       nextPlayer();
       validMoves = GameLogic.getValidMoves(board, curPlayer.getState());
       if (validMoves.size() > 0) { // Other player goes again.
         output.playerGetsToMoveAgain(curPlayer);
         aiThread = new AIThread(curPlayer, board.clone(), validMoves.toPoints());
         timer.reset();
         aiThread.start();
         return;
       } else { // GameOver
         gameOver();
         return;
       }
     }
   }
   if (aiThread.isReady()) {
     Move move = aiThread.getMove();
     if (move != null) {
       FlipList flipList = GameLogic.getPointsFlipped(board, move);
       GameLogic.makeDestructiveMove(board, flipList);
       output.playerMadeMove(curPlayer, move, flipList, board);
       nextPlayer();
       stateManager.setCurState(GameState.PLAYING);
     } else { // Forfeit turn due to invalid move.
       gameOver(matchup.otherPlayer(curPlayer));
       return;
     }
   } else if (timer.expired()) {
     output.playerRanOutOfTime(curPlayer);
     gameOver(matchup.otherPlayer(curPlayer));
     return;
   }
 }
Exemple #2
0
 // TODO: Is the stateManager still necessary..?
 public void update(long deltaMs) {
   switch (stateManager.getCurState()) {
     case INIT:
       if (stateManager.isStateChange()) {
         dark.init(State.DARK);
         light.init(State.LIGHT);
         output.update(stateManager.getCurState(), matchup, board);
         stateManager.setCurState(GameState.PLAYING);
       }
       break;
     case PLAYING:
       playPly();
       break;
     case GAME_OVER:
       if (stateManager.isStateChange()) {
         output.update(stateManager.getCurState(), matchup, board);
         notifyGameOverObservers();
       }
       break;
   }
 }
Exemple #3
0
 private void gameOver(Player winner) {
   matchup.playedMatch(winner);
   stateManager.setCurState(GameState.GAME_OVER);
 }