Пример #1
0
  /**
   * Returns the score of the given move made by the given color based upon searches to the
   * specified depth.
   *
   * @param m the move to score
   * @param depth the max depth to search to
   * @param color the player who makes the move
   * @return the score of the move
   */
  private int getScore(Move m, int depth, int color, int a, int b) {
    board.makeMove(m, color);
    depth--;

    int score = 0;
    if (board.hasNetwork(oppositeColor(this.color))) {
      score = Scorer.MINSCORE - depth;
    } else if (board.hasNetwork(this.color)) {
      score = Scorer.MAXSCORE + depth;
    } else if (depth == 0 || Scorer.hasScore(board, color)) {
      score = Scorer.getScore(board, this.color);
    } else {
      score = chooseMove(depth, oppositeColor(color), a, b).score;
      Scorer.addScore(board, color, score);
    }
    board.rollback();
    return score;
  }
Пример #2
0
 /**
  * Returns a new <code>Move</code> by this player. Internally records the move (update the
  * internal game board) as a move by this player. Changes search depth based on whether pieces are
  * being added or stepped
  *
  * @return the Move chosen by this player
  */
 public Move chooseMove() {
   int maxDepth = searchDepth;
   if (maxDepth == VARDEPTH) {
     if (board.getNumPieces(color) > 8) // Step move
     maxDepth = 4;
     else // Add move
     maxDepth = 4;
   }
   Move m;
   if (board.getNumPieces(color) == 0) { // First move starts in center
     m = new Move(3, 3);
     if (!board.isValidMove(m, color)) m = new Move(3, 4);
   } else {
     ScoreMove sm = chooseMove(maxDepth, color, Scorer.MINSCORE - 1, Scorer.MAXSCORE + 1);
     m = sm.move;
     Scorer.clearCache();
   }
   board.makeMove(m, color);
   return m;
 }
Пример #3
0
 /**
  * Forces this player to make the specified move if legal and returns true. If the move is not
  * legal, returns false and does not record the move.
  *
  * @param m the Move forced to make
  * @return true if legal move, false otherwise
  */
 public boolean forceMove(Move m) {
   if (!board.isValidMove(m, color)) return false;
   board.makeMove(m, color);
   return true;
 }
Пример #4
0
 /**
  * Records the specified move as a move by the opponent if it is legal and returns true. If the
  * move is not legal, returns false and does not record the move.
  *
  * @param m the Move provided by the opponent
  * @return true if legal move, false otherwise
  */
 public boolean opponentMove(Move m) {
   if (!board.isValidMove(m, oppositeColor(color))) return false;
   board.makeMove(m, oppositeColor(color));
   return true;
 }