|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|