浏览代码

changed some stuff

Nicolas Winkler 7 年之前
父节点
当前提交
fcf5e697b8
共有 5 个文件被更改,包括 25 次插入21 次删除
  1. 2 2
      src/BitBoard.h
  2. 19 16
      src/Board.cpp
  3. 2 0
      src/ChessGame.cpp
  4. 1 2
      src/MoveGeneration.cpp
  5. 1 1
      src/MoveGeneration.h

+ 2 - 2
src/BitBoard.h

@@ -25,7 +25,7 @@ union chessy::Index
     Index(void) = default;
     inline constexpr Index(int8_t ind) : index{ ind } {}
     inline Index(const std::string& name) :
-        Index{ '8' - name[0], name[1] - 'a' } {}
+        Index{ name[0] - '1', name[1] - 'a' } {}
     inline constexpr Index(int row, int column) :
         index{int8_t(((row & 0x7) << 3) + (column & 0x7))} {}
 
@@ -37,7 +37,7 @@ union chessy::Index
 
     inline std::string getName(void) const
     {
-        return { char('a' + getColumn()), char('8' - getRow()) };
+        return { char('a' + getColumn()), char(getRow() + '1') };
     }
 };
 

+ 19 - 16
src/Board.cpp

@@ -1,6 +1,6 @@
 #include "Board.h"
 #include <string>
-#include <unordered_map>
+#include <map>
 #include <ctype.h>
 #include <stdexcept>
 #include <sstream>
@@ -55,20 +55,20 @@ bool Board::tryToMove(Bitboard start, Bitboard end, Bitboard& b)
 
 void Board::setBoard(const std::string& fenPosition)
 {
-    int row = 0, column = 0;
-    unordered_map<char, Bitboard*> boards {
-        { 'p', &whites[PieceType::PAWN] },
-        { 'n', &whites[PieceType::KNIGHT] },
-        { 'b', &whites[PieceType::BISHOP] },
-        { 'r', &whites[PieceType::ROOK] },
-        { 'q', &whites[PieceType::QUEEN] },
-        { 'k', &whites[PieceType::KING] },
-        { 'P', &blacks[PieceType::PAWN] },
-        { 'N', &blacks[PieceType::KNIGHT] },
-        { 'B', &blacks[PieceType::BISHOP] },
-        { 'R', &blacks[PieceType::ROOK] },
-        { 'Q', &blacks[PieceType::QUEEN] },
-        { 'K', &blacks[PieceType::KING] }
+    int row = 7, column = 0;
+    map<char, Bitboard*> boards {
+        { 'p', &blacks[PieceType::PAWN] },
+        { 'n', &blacks[PieceType::KNIGHT] },
+        { 'b', &blacks[PieceType::BISHOP] },
+        { 'r', &blacks[PieceType::ROOK] },
+        { 'q', &blacks[PieceType::QUEEN] },
+        { 'k', &blacks[PieceType::KING] },
+        { 'P', &whites[PieceType::PAWN] },
+        { 'N', &whites[PieceType::KNIGHT] },
+        { 'B', &whites[PieceType::BISHOP] },
+        { 'R', &whites[PieceType::ROOK] },
+        { 'Q', &whites[PieceType::QUEEN] },
+        { 'K', &whites[PieceType::KING] }
     };
     setEmpty();
     for (auto character : fenPosition) {
@@ -76,7 +76,8 @@ void Board::setBoard(const std::string& fenPosition)
             column += character - '0';
         }
         else if (character == '/') {
-            ++ row;
+            -- row;
+            column = 0;
         }
         else {
             auto board = boards.find(character);
@@ -88,6 +89,8 @@ void Board::setBoard(const std::string& fenPosition)
             }
             ++ column;
         }
+        if (row < -1 || column > 8)
+            throw runtime_error("invalid board string "s + fenPosition);
     }
 }
 

+ 2 - 0
src/ChessGame.cpp

@@ -114,6 +114,8 @@ std::string ChessGame::generateFen(void) const
         (canCastleQueenSideBlack ? "Q"s : ""s) +
         (canCastleKingSideWhite ? "k"s : ""s) +
         (canCastleQueenSideWhite ? "q"s : ""s);
+    if (castlingRights.empty())
+        castlingRights = "-"s;
 
     string enPassant;
     if (this->enPassant == -1) {

+ 1 - 2
src/MoveGeneration.cpp

@@ -12,7 +12,7 @@ std::string chessy::Move::asString(void) const
     return origin.getName() + "-" + destination.getName();
 }
 
-#include <iostream>
+
 template<int side>
 typename PawnPushGenerator<side>::MoveIterator PawnPushGenerator<side>::begin(void) const
 {
@@ -27,7 +27,6 @@ typename PawnPushGenerator<side>::MoveIterator PawnPushGenerator<side>::begin(vo
     
     movedPieces &= ~(side == WHITE_SIDE ? board.getBlacks() : board.getWhites());
 
-    std::cout << movedPieces << std::endl;
     return MoveIterator{ movedPieces };
 }
 

+ 1 - 1
src/MoveGeneration.h

@@ -92,7 +92,7 @@ class chessy::PawnPushGenerator
         inline Move operator *(void) const
         {
             Index pp = *pawnPushes;
-            return Move{ int8_t(pp + (side == BLACK_SIDE ? 8 : -8)), pp };
+            return Move{ int8_t(pp + (side != WHITE_SIDE ? 8 : -8)), pp };
         }
 
         inline void operator ++(void)