コード例 #1
0
ファイル: Match.java プロジェクト: ablaine/Othello
 /**
  * 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;
   }
 }
コード例 #2
0
ファイル: Match.java プロジェクト: ablaine/Othello
 private void nextPlayer() { // NOTE: Do NOT set GameState.PLAYING here.
   curPlayer = matchup.otherPlayer(curPlayer);
 }