diff --git a/source/board.cpp b/source/board.cpp index 598a89f..ab30133 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -69,6 +69,7 @@ void Board::SetByFen(std::string_view fen) { occupied = colors[White] | colors[Black]; hashKey = GetHashKey(*this); + GenerateMoves(*this, sideToMove); GenAttackMaps(*this); } @@ -137,6 +138,7 @@ void Board::ListMoves() { for (int i = 0; i < currentMoveIndex; i++) { std::cout << i+1 << ". "; moveList[i].PrintMove(); + std::cout << std::endl; } } diff --git a/source/uci.cpp b/source/uci.cpp index 36e8b5d..21cc81e 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -34,6 +34,9 @@ void ParsePosition(Board &board, std::string_view command) { board.MakeMove(parseMove(board, move)); } } + + GenerateMoves(board, board.sideToMove); + GenAttackMaps(board); } static int ReadParam(std::string param, std::string &command) { @@ -102,7 +105,7 @@ void UCILoop(Board &board) { // parse UCI "position" command if (input.find("position") != std::string::npos) { - ParsePosition(board, input.c_str()); + ParsePosition(board, input); continue; } @@ -159,5 +162,10 @@ void UCILoop(Board &board) { board.PrintBoard(); continue; } + + if (input.find("listmoves") != std::string::npos) { + board.ListMoves(); + continue; + } } } diff --git a/source/utils.cpp b/source/utils.cpp index 3911661..25b3678 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,4 +1,5 @@ #include "utils.h" +#include "movegen.h" std::vector split(std::string_view str, char delim) { std::vector results; @@ -24,6 +25,8 @@ int parseSquare(std::string_view str) { } Move parseMove(Board &board, std::string_view str) { + GenerateMoves(board, board.sideToMove); + int from = parseSquare(str.substr(0, 2)); int to = parseSquare(str.substr(2, 2)); @@ -62,6 +65,13 @@ Move parseMove(Board &board, std::string_view str) { break; } } + } else { + for (Move move : board.moveList) { + if (move.MoveFrom() == from && move.MoveTo() == to) { + flag = move.GetFlags(); + break; + } + } } return Move(from, to, flag);