]> git.sesse.net Git - stockfish/commitdiff
Reformat FEN construction
authorMarco Costalba <mcostalba@gmail.com>
Fri, 4 Jan 2013 11:32:13 +0000 (12:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 4 Jan 2013 12:38:14 +0000 (13:38 +0100)
Simplify and shrink code.

No functional change.

src/position.cpp

index c814e7657a7e8505d557ff77c673e03889d580c4..8dab668bd90e1fb392338e7d933e6e6aa5647d96 100644 (file)
@@ -331,33 +331,26 @@ void Position::set_castle_right(Color c, Square rfrom) {
 const string Position::fen() const {
 
   std::ostringstream ss;
-  Square sq;
-  int emptyCnt;
 
   for (Rank rank = RANK_8; rank >= RANK_1; rank--)
   {
-      emptyCnt = 0;
-
       for (File file = FILE_A; file <= FILE_H; file++)
       {
-          sq = file | rank;
+          Square sq = file | rank;
 
           if (is_empty(sq))
-              emptyCnt++;
-          else
           {
-              if (emptyCnt > 0)
-              {
-                  ss << emptyCnt;
-                  emptyCnt = 0;
-              }
-              ss << PieceToChar[piece_on(sq)];
+              int emptyCnt = 1;
+
+              for ( ; file < FILE_H && is_empty(sq++); file++)
+                  emptyCnt++;
+
+              ss << emptyCnt;
           }
+          else
+              ss << PieceToChar[piece_on(sq)];
       }
 
-      if (emptyCnt > 0)
-          ss << emptyCnt;
-
       if (rank > RANK_1)
           ss << '/';
   }