|
@@ -8,8 +8,7 @@
|
|
using namespace chessy;
|
|
using namespace chessy;
|
|
|
|
|
|
MoveInfo::MoveInfo(Move move, const ChessGame& cg) :
|
|
MoveInfo::MoveInfo(Move move, const ChessGame& cg) :
|
|
- move{ move }, movedPiece{ cg.getBoard().getAtPosition(move.origin) },
|
|
|
|
- enPassantTarget{ 0 }
|
|
|
|
|
|
+ move{ move }, movedPiece{ cg.getBoard().getAtPosition(move.origin) }
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
@@ -44,6 +43,9 @@ void ChessGame::loadFromFen(const std::string& fenString)
|
|
{
|
|
{
|
|
using namespace std;
|
|
using namespace std;
|
|
|
|
|
|
|
|
+ // push zobrist hash of current position
|
|
|
|
+ history.push_back(hash);
|
|
|
|
+
|
|
stringstream tokenizer (fenString);
|
|
stringstream tokenizer (fenString);
|
|
|
|
|
|
string board;
|
|
string board;
|
|
@@ -151,6 +153,10 @@ std::string ChessGame::generateFen(void) const
|
|
UndoInfo ChessGame::doMove(const MoveInfo& mi)
|
|
UndoInfo ChessGame::doMove(const MoveInfo& mi)
|
|
{
|
|
{
|
|
assert(hash == zobrist::getHash(*this)); // valid zobrist hash
|
|
assert(hash == zobrist::getHash(*this)); // valid zobrist hash
|
|
|
|
+
|
|
|
|
+ std::string fen = this->generateFen();
|
|
|
|
+ // push zobrist hash of current position
|
|
|
|
+ history.push_back(hash);
|
|
|
|
|
|
UndoInfo ui;
|
|
UndoInfo ui;
|
|
ui.hash = hash;
|
|
ui.hash = hash;
|
|
@@ -246,6 +252,7 @@ void ChessGame::undoMove(const UndoInfo& ui)
|
|
castlingRights = ui.castlingRights;
|
|
castlingRights = ui.castlingRights;
|
|
enPassant = ui.enPassantBefore;
|
|
enPassant = ui.enPassantBefore;
|
|
hash = ui.hash;
|
|
hash = ui.hash;
|
|
|
|
+ history.pop_back();
|
|
|
|
|
|
assert(hash == zobrist::getHash(*this)); // valid zobrist hash
|
|
assert(hash == zobrist::getHash(*this)); // valid zobrist hash
|
|
}
|
|
}
|