Example #1
0
 private void gameOver() {
   int darkScore = board.getScore(State.DARK);
   int lightScore = board.getScore(State.LIGHT);
   if (darkScore > lightScore) {
     gameOver(dark);
   } else if (lightScore > darkScore) {
     gameOver(light);
   } else {
     gameOver(null); // It was a tie.
   }
 }
Example #2
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;
   }
 }
Example #3
0
 @Override
 public void update(final Match.GameState curState, final Matchup matchup, final Board board) {
   switch (curState) {
     case INIT:
       tileLayer.clear();
       grid = new Tile[Board.SIZE][Board.SIZE];
       for (int x = 0; x < Board.SIZE; x++) {
         for (int y = 0; y < Board.SIZE; y++) {
           Tile t = new Tile(x, y, board.getState(x, y));
           grid[x][y] = t;
           tileLayer.add(t);
         }
       }
       break;
   }
 }