Ejemplo n.º 1
0
 private Value primitiveValue(boolean strict) {
   if (!(isChildrenValid)) getChildren(strict);
   if (numChildren == 0) {
     return numPieces[turn] > numPieces[Math.abs(turn - 1)] ? Value.WIN : Value.LOSE;
   } else {
     return Value.UNDECIDED;
   }
 }
Ejemplo n.º 2
0
 @Override
 public int validMoves(TierState[] moves) {
   if (!(isChildrenValid)) getChildren(false);
   for (int i = 0; i < numChildren; i++) {
     moves[i].set(children[i]);
   }
   if (numChildren == 0) throw new Error("No children at this position");
   return numChildren;
 }
Ejemplo n.º 3
0
 @Override
 public Collection<Pair<String, TierState>> validMoves() {
   getChildren(true);
   TierState[] states = newStateArray(numChildren);
   validMoves(states);
   ArrayList<Pair<String, TierState>> moves = new ArrayList<Pair<String, TierState>>();
   for (int i = 0; i < numChildren; i++) {
     moves.add(new Pair<String, TierState>(stringMoves[i], states[i]));
   }
   return moves;
 }
Ejemplo n.º 4
0
 private void getChildren(boolean setStringMoves) {
   dbh.getCharArray(oldPosition);
   int counter = 0;
   // looks at every spot on the board
   for (int row = 0; row < height; row++) {
     for (int col = 0; col < width; col++) {
       // only a valid child if there is an empty space there
       if (board[row][col].getPiece() == ' ') {
         Cell place = board[row][col];
         Cell[] neighbors = place.getNeighbors();
         // looks at each spot around the given spot
         for (int index = 0; index < 8; index++) {
           // makes sure the spot is within bounds, then checks if
           // there is an opposing piece next to it
           Cell neighbor = neighbors[index];
           if (neighbor != null
               && neighbor.getPiece() == pieces[opposite(turn)]
               && isFlippable(place.boardNum, index, false, null)) {
             if (setStringMoves) {
               stringMoves[counter] = (char) (col + 'A') + Integer.toString(row + 1);
             }
             System.arraycopy(oldPosition, 0, tempPosition, 0, boardSize);
             isFlippable(place.boardNum, index, true, tempPosition);
             int newWhitePieces = count(tempPosition);
             int nextTier = getTier() + 1;
             children[counter].tier = nextTier;
             children[counter].hash =
                 offsetTable[nextTier][opposite(turn)][newWhitePieces]
                     + dbh.setNumsAndHash(tempPosition);
             counter++;
             dbh.setNumsAndHash(oldPosition);
             break;
           }
         }
       }
     }
   }
   if (setStringMoves && counter == 0) {
     turn = opposite(turn);
     getChildren(false);
     if (numChildren > 0) {
       stringMoves[0] = "pass";
       children[0].tier = getTier();
       children[0].hash = getHash();
       counter = 1;
     }
     turn = opposite(turn);
   }
   numChildren = counter;
   isChildrenValid = true;
 }