]> git.sesse.net Git - stockfish/commitdiff
Simplify Position::print()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 12 May 2012 10:35:40 +0000 (11:35 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 12 May 2012 11:50:11 +0000 (12:50 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp

index 95195d3af47240dfed607c8a0bc6ddc127add1b8..fd7b1ba26a02bd2c154ae1108e711517bf977f98 100644 (file)
@@ -63,7 +63,7 @@ const Value PieceValueEndgame[17] = {
 };
 
 // To convert a Piece to and from a FEN char
 };
 
 // To convert a Piece to and from a FEN char
-static const string PieceToChar(" PNBRQK  pnbrqk  .");
+static const string PieceToChar(" PNBRQK  pnbrqk");
 
 
 /// CheckInfo c'tor
 
 
 /// CheckInfo c'tor
@@ -154,7 +154,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) {
           sq += Square(token - '0'); // Advance the given number of files
 
       else if (token == '/')
           sq += Square(token - '0'); // Advance the given number of files
 
       else if (token == '/')
-          sq = make_square(FILE_A, rank_of(sq) - Rank(2));
+          sq -= Square(16);
 
       else if ((p = PieceToChar.find(token)) != string::npos)
       {
 
       else if ((p = PieceToChar.find(token)) != string::npos)
       {
@@ -319,7 +319,11 @@ const string Position::to_fen() const {
 
 void Position::print(Move move) const {
 
 
 void Position::print(Move move) const {
 
-  const char* dottedLine = "\n+---+---+---+---+---+---+---+---+\n";
+  const string dottedLine =            "\n+---+---+---+---+---+---+---+---+";
+  const string twoRows =  dottedLine + "\n|   | . |   | . |   | . |   | . |"
+                        + dottedLine + "\n| . |   | . |   | . |   | . |   |";
+
+  string brd = twoRows + twoRows + twoRows + twoRows + dottedLine;
 
   if (move)
   {
 
   if (move)
   {
@@ -327,22 +331,11 @@ void Position::print(Move move) const {
       cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
   }
 
       cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
   }
 
-  for (Rank rank = RANK_8; rank >= RANK_1; rank--)
-  {
-      cout << dottedLine << '|';
-      for (File file = FILE_A; file <= FILE_H; file++)
-      {
-          Square sq = make_square(file, rank);
-          Piece piece = piece_on(sq);
-          char c = (color_of(piece) == BLACK ? '=' : ' ');
-
-          if (piece == NO_PIECE && !opposite_colors(sq, SQ_A1))
-              piece++; // Index the dot
+  for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
+      if (piece_on(sq) != NO_PIECE)
+          brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
 
 
-          cout << c << PieceToChar[piece] << c << '|';
-      }
-  }
-  cout << dottedLine << "Fen is: " << to_fen() << "\nKey is: " << st->key << endl;
+  cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl;
 }
 
 
 }