Beispiel #1
0
  public void revertMove() {
    // pops a move from the stack and reverses it
    try {
      Move move = this.popMoveFromHistory(); // pop a move off the stack
      if (move.getPosition() == -1) {
        // move is pass
      } else {
        this.positions[move.getPosition()] = 0; // set move position to empty

        int stackSize = move.getFlipStackSize(); // how many flips are there?
        for (int i = 0; i < stackSize; i++) { // loop through the stack
          int flipPosition = move.popFlip();
          // System.out.println(flipPosition);
          this.setPosition(flipPosition); // pop a flip and un-flip it
        }
      }

      // Debugging stuff
      popCount++;
      // System.out.println("pop");
      // this.printBoard();

    } catch (NullPointerException e) {
      System.out.println("(C you tried to pop an empty move stack )");
    }
  }
Beispiel #2
0
  public void applyMove(int color, Move move) {
    // applies move based on fields of supplied move and pushes it to the stack
    if (move.getPosition() == -1) {
      // move is pass
    } else {
      this.positions[move.getPosition()] = color;
      Stack<Integer> flipStack = move.getFlips();
      int amountOfFlips = flipStack.size();
      for (int i = 0; i < amountOfFlips; i++) {
        this.positions[flipStack.pop()] = color;
      }
    }
    this.pushMoveToHistory(move);
    this.clearLegalMovesList();

    // debugging stuff
    pushCount++;
    // System.out.println("push");
    // this.printBoard();
  }
Beispiel #3
0
  public int makeComputerMove(long timeRemaining) {
    // othellonator makes a move

    Move myMove = null;
    moveCount++;
    System.out.println("(C moveCount = " + moveCount + ")");
    if (this.generateLegalMoves(myColor)) { // evaluate board, do stuff if legal moves found
      String listSize = Integer.toString(getLegalMovesListSize());
      System.out.println("(C Number of moves:" + listSize + " )");

      if (moveCount < 10) {
        myMove = Search.alphaBetaSearch(this, 6, myColor);
      } else if (moveCount >= 10 && moveCount <= 20) {
        myMove = Search.alphaBetaSearch(this, 8, myColor);
      } else {
        myMove = Search.alphaBetaSearch(this, 10, myColor);
      }
      this.applyMove(myColor, myMove); // apply the move returned by the search
      return myMove.getPosition(); // return the position of the move so it can be output
    } else return -1; // signal that no move was found
  }
Beispiel #4
0
  public boolean evaluateOpponentMove(int color, int position) {
    // runs generateMoveForPosition() to generate flips and push the move on to the list
    // then applies the move at the front of the list
    boolean legal = false;
    Move move = null;

    this.generateLegalMoves(myColor * -1); // evaluate legal moves for opponent
    for (int i = 0; i < this.legalMovesList.size(); i++) { // check move against legalMovesList
      Move tester = this.getLegalMove(i);
      // if opponent's move found in legalMoveList, it is legal
      if (tester.getPosition() == position) {
        legal = true;
        move = tester;
      }
    }
    // if the move is legal, apply it and return true.  otherwise return false.
    if (legal) {
      applyMove(color, move);
      return true;
    } else return false;
  }