Exemplo 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());
    }
  }
Exemplo 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();

  }
Exemplo n.º 3
0
  /**
   * After the user clicked on a pit the seeds should be distributed in an animated fashion
   *
   * @param chosenPitIndex the index the user chose to distribute the seeds from
   * @param oldState the state before the user chose his pit
   */
  void makeAnimatedMove(int chosenPitIndex, State oldState) {

    // disable board until the animation is over
    disableBoard();
    state.makeMove(chosenPitIndex);

    PlayerColor whoseTurn = oldState.getWhoseTurn();
    PlayerColor sideToPlaceSeedOn = whoseTurn;
    int seedAmount = oldState.getPitsOfWhoseTurn()[chosenPitIndex];
    boolean lastAnimation = false;
    int indexToPlaceSeedIn = chosenPitIndex;
    int maxIndex = 6;
    for (int i = 1; i <= seedAmount; i++) {
      indexToPlaceSeedIn++;
      maxIndex = whoseTurn.equals(sideToPlaceSeedOn) ? 6 : 5;
      if ((indexToPlaceSeedIn) > maxIndex) {
        sideToPlaceSeedOn = sideToPlaceSeedOn.getOpposite();
        indexToPlaceSeedIn = 0;
      }
      if (i == seedAmount) lastAnimation = true;
      graphics.animateFromPitToPit(
          whoseTurn,
          chosenPitIndex,
          sideToPlaceSeedOn,
          indexToPlaceSeedIn,
          400 * (i - 1),
          lastAnimation);
    }

    if (this.state.getLastMoveWasOppositeCapture()) {
      // graphics.oppositeCaptureSound();

      // TODO: give this it's own animation

      // //int[] opposingPits = whoseTurn.isNorth() ?
      // this.state.getSouthPits() : state.getNorthPits();
      // int seedAmountInOpposingPit = this.state.getOppositeSeeds();
      //
      // graphics.animateFromPitToPit(whoseTurn, indexToPlaceSeedIn,
      // whoseTurn, 6, seedAmount * 400 + 1400);
      // for(int i = 0; i < seedAmountInOpposingPit; i++)
      // graphics.animateFromPitToPit(whoseTurn.getOpposite(),
      // State.getMirrorIndex(indexToPlaceSeedIn, 5), whoseTurn, 6,
      // seedAmount * 400 + 1000 + 400 * i);
    }
  }