]> git.sesse.net Git - stockfish/commitdiff
Print the move in addition to position
authorMarco Costalba <mcostalba@gmail.com>
Sat, 15 Nov 2008 07:14:28 +0000 (08:14 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 16 Nov 2008 11:37:46 +0000 (12:37 +0100)
Teach Position::print() to optionally print a
given move in san notation in addition to
the ASCII representation of the board.

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

index 958a9397d9fa68c7af70f89e8f06d8e07c1f61a7..8390facc5b501a040333c820285bd28e15573a29 100644 (file)
@@ -31,6 +31,7 @@
 #include "movepick.h"
 #include "position.h"
 #include "psqtab.h"
+#include "san.h"
 #include "ucioption.h"
 
 
@@ -263,28 +264,35 @@ const std::string Position::to_fen() const {
 
 
 /// Position::print() prints an ASCII representation of the position to
-/// the standard output.
-
-void Position::print() const {
-  char pieceStrings[][8] =
-    {"| ? ", "| P ", "| N ", "| B ", "| R ", "| Q ", "| K ", "| ? ",
-     "| ? ", "|=P=", "|=N=", "|=B=", "|=R=", "|=Q=", "|=K="
-    };
-
-  for(Rank rank = RANK_8; rank >= RANK_1; rank--) {
-    std::cout << "+---+---+---+---+---+---+---+---+\n";
-    for(File file = FILE_A; file <= FILE_H; file++) {
-      Square sq = make_square(file, rank);
-      Piece piece = piece_on(sq);
-      if(piece == EMPTY)
-        std::cout << ((square_color(sq) == WHITE)? "|   " : "| . ");
-      else
-        std::cout << pieceStrings[piece];
-    }
-    std::cout << "|\n";
+/// the standard output. If a move is given then also the san is print.
+
+void Position::print(Move m) const {
+
+  static const std::string pieceLetters = " PNBRQK  PNBRQK .";
+
+  std::cout << std::endl;
+  if (m != MOVE_NONE)
+  {
+      Position p(*this);
+      std::cout << "Move is: " << move_to_san(p, m) << std::endl;
+  }
+  for (Rank rank = RANK_8; rank >= RANK_1; rank--)
+  {
+      std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
+      for (File file = FILE_A; file <= FILE_H; file++)
+      {
+          Square sq = make_square(file, rank);
+          Piece piece = piece_on(sq);
+          if (piece == EMPTY && square_color(sq) == WHITE)
+              piece = NO_PIECE;
+
+          char col = (color_of_piece_on(sq) == BLACK ? '=' : ' ');
+          std::cout << '|' << col << pieceLetters[piece] << col;
+      }
+      std::cout << '|' << std::endl;
   }
-  std::cout << "+---+---+---+---+---+---+---+---+\n";
-  std::cout << to_fen() << std::endl;
+  std::cout << "+---+---+---+---+---+---+---+---+" << std::endl;
+  std::cout << "Fen is: " << to_fen() << std::endl;
   std::cout << key << std::endl;
 }
 
index 27ec25a7e60d0ac270fd6bee175e8b61b07949e7..6076a53905251d832d36e3b1868bc7146cec6a8d 100644 (file)
@@ -128,7 +128,7 @@ public:
   // Text input/output
   void from_fen(const std::string &fen);
   const std::string to_fen() const;
-  void print() const;
+  void print(Move m = MOVE_NONE) const;
 
   // Copying
   void copy(const Position &pos);