Example #1
0
 /**
  * Get board position as text diagram.
  *
  * @param board The board to print.
  * @param withGameInfo Print additional game information on the right side of the board (at
  *     present only number of prisoners)
  * @return Board position as text diagram.
  */
 public static String toString(ConstBoard board, boolean withGameInfo) {
   StringBuilder s = new StringBuilder(1024);
   int size = board.getSize();
   String separator = System.getProperty("line.separator");
   assert separator != null;
   printXCoords(size, s, separator);
   for (int y = size - 1; y >= 0; --y) {
     printYCoord(y, s, true);
     s.append(' ');
     for (int x = 0; x < size; ++x) {
       GoPoint point = GoPoint.get(x, y);
       GoColor color = board.getColor(point);
       if (color == BLACK) s.append("X ");
       else if (color == WHITE) s.append("O ");
       else {
         if (board.isHandicap(point)) s.append("+ ");
         else s.append(". ");
       }
     }
     printYCoord(y, s, false);
     if (withGameInfo) printGameInfo(board, s, y);
     s.append(separator);
   }
   printXCoords(size, s, separator);
   if (!withGameInfo) {
     printToMove(board, s);
     s.append(separator);
   }
   return s.toString();
 }
Example #2
0
 private static void printGameInfo(ConstBoard board, StringBuilder s, int yIndex) {
   int size = board.getSize();
   if (yIndex == size - 1) {
     s.append("  ");
     printToMove(board, s);
   } else if (yIndex == size - 2) {
     s.append("  Prisoners: B ");
     s.append(board.getCaptured(BLACK));
     s.append("  W ");
     s.append(board.getCaptured(WHITE));
   }
 }
Example #3
0
 /**
  * Copy the state of one board to another. Initializes the target board with the size and the
  * setup stones of the source board and executes all moves of the source board on the target
  * board.
  */
 public static void copy(Board target, ConstBoard source) {
   target.init(source.getSize());
   ConstPointList setupBlack = source.getSetup(BLACK);
   ConstPointList setupWhite = source.getSetup(WHITE);
   GoColor setupPlayer = source.getSetupPlayer();
   if (setupBlack.size() > 0 || setupWhite.size() > 0) {
     if (source.isSetupHandicap()) target.setupHandicap(setupBlack);
     else target.setup(setupBlack, setupWhite, setupPlayer);
   }
   for (int i = 0; i < source.getNumberMoves(); ++i) target.play(source.getMove(i));
 }
Example #4
0
 private static void printToMove(ConstBoard board, StringBuilder buffer) {
   buffer.append(board.getToMove().getCapitalizedName());
   buffer.append(" to play");
 }