Ejemplo n.º 1
0
  /** makes a move on the model, adds the new state to the history and updates the board */
  void makeMove(int index) {
    try {
      lastMove = index;
      if (aiMatch) {
        stateToSetAfterAnimation = state.copyState();
        stateToSetAfterAnimation.makeMove(index);
        makeAnimatedMove(index, state.copyState());
      } else {
        State stateCopy = state.copyState();
        stateCopy.makeMove(index);
        sendMoveToServer(index, State.serialize(stateCopy));
      }
      // State oldState = state.copyState();
      //
      // stateToSetAfterAnimation = state.copyState();
      // stateToSetAfterAnimation.makeMove(index);

      // state.makeMove(index);

      // sendMoveToServer() is called by the graphics class after the animation is done
      // makeAnimatedMove(index, oldState);

    } catch (IllegalMoveException e) {
      graphics.setMessage(messages.newGameBecauseError() + e);
      setState(new State());
    } catch (GameOverException e) {
      graphics.setMessage(messages.newGameBecauseError() + e);
      setState(new State());
    }
  }
Ejemplo n.º 2
0
  public void makeAiMove() {
    // System.out.println("Presenter makeAiMove");
    if (state.isGameOver()) {
      return;
    }
    AlphaBetaPruning ai = new AlphaBetaPruning(new Heuristic());
    Integer aiMove = ai.findBestMove(state, 5, new DateTimer(3000));

    System.out.println("P MAIM state: " + state);
    System.out.println("P MAIM move: " + aiMove);

    State oldState = state.copyState();

    stateToSetAfterAnimation = state.copyState();
    stateToSetAfterAnimation.makeMove(aiMove);

    makeAnimatedMove(aiMove, oldState);

    // state.makeMove(aiMove);
    System.out.println("State after Move: " + state);
    // setState(state);

    // graphics.sendMoveToServerAI(aiMove, state);

    // this will be made in the graphics after the move was saved
    // if (state.getWhoseTurn().equals(usersSide.getOpposite()))
    // makeAiMove();

  }
Ejemplo n.º 3
0
  public void afterAnimation() {
    if (stateToSetAfterAnimation.getLastMoveWasOppositeCapture()) graphics.oppositeCaptureSound();

    state = stateToSetAfterAnimation.copyState();
    updateBoard();

    if (aiMatch) sendMoveToServerAI(lastMove, state);
  }