From e93ddffa4ab47f7e1f710a9d7e78ca831b2df78a Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 10 May 2023 06:55:12 +0200 Subject: [PATCH] Cleaning and debug code --- src/Board.cpp | 4 ++-- src/ChessArbiter.cpp | 1 - src/Fen.cpp | 6 +++--- src/Fen.hpp | 2 +- src/Piece.hpp | 2 +- tests/chessarbiter.cpp | 4 ++++ 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Board.cpp b/src/Board.cpp index 029c407..b711058 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -21,7 +21,7 @@ bool Board::AddPiece(char p, const std::string &coord) { } bool Board::RemovePiece(const std::string &coord) { - for (char i = 0; i < pieces.size(); i++) { + for (char i = 0; i < (char)pieces.size(); i++) { if (pieces[i].coord == coord) { pieces.erase(pieces.begin() + i); return (true); @@ -183,7 +183,7 @@ bool Board::IsMovePossible(const std::string &move) { char r = src[1] + d2 * side; // Perform empty square checks - while (f != dst[0], r != dst[1]) { + while (f != dst[0] && r != dst[1]) { if (!IsEmpty(f + std::string() + r)) { return (false); } diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp index 3c3a26a..947807a 100644 --- a/src/ChessArbiter.cpp +++ b/src/ChessArbiter.cpp @@ -480,7 +480,6 @@ std::string ChessArbiter::ParseSAN(const std::string &SANMove) { piece = SANMove[0]; char c1 = (SANMove.size() >= 2) ? SANMove[1] : '?'; char c2 = (SANMove.size() >= 3) ? SANMove[2] : '?'; - char c3 = (SANMove.size() >= 4) ? SANMove[3] : '?'; if (c1 == 'x') { dst = SANMove.substr(2, 2); } else if (c2 == 'x') { diff --git a/src/Fen.cpp b/src/Fen.cpp index 54dddfd..3ba4ddb 100644 --- a/src/Fen.cpp +++ b/src/Fen.cpp @@ -28,7 +28,7 @@ std::string FENParser::normalize_rank(const std::string &fen_rank) { } char FENParser::NextToken(const std::string &fen, char loc) { - while (loc < fen.size() && IS_BLANK(fen[loc])) { + while (loc < (char)fen.size() && IS_BLANK(fen[loc])) { loc++; } return (loc); @@ -36,7 +36,7 @@ char FENParser::NextToken(const std::string &fen, char loc) { char FENParser::NextRank(const std::string &fen, char loc) { loc++; - while (loc < fen.size() && fen[loc] != '/' && fen[loc] != ' ') { + while (loc < (char)fen.size() && fen[loc] != '/' && fen[loc] != ' ') { loc++; } return (loc); @@ -190,7 +190,7 @@ FEN FENParser::Parse(const std::string &fen) { // Parse move counter loc = NextToken(fen, loc); std::string move; - while (loc < fen.size() && !IS_BLANK(fen[loc])) { + while (loc < (char)fen.size() && !IS_BLANK(fen[loc])) { if (!IS_DIGIT(fen[loc])) { throw InvalidFEN(); } diff --git a/src/Fen.hpp b/src/Fen.hpp index bcb93de..ac344ad 100644 --- a/src/Fen.hpp +++ b/src/Fen.hpp @@ -6,7 +6,7 @@ (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || \ c == '6' || c == '7' || c == '8' || c == '9') #define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r') -#define CHECK_LOC() {if(loc>=fen.size()){throw InvalidFEN();}} +#define CHECK_LOC() {if(loc>=(char)fen.size()){throw InvalidFEN();}} namespace chessarbiter { diff --git a/src/Piece.hpp b/src/Piece.hpp index 7469ee2..60452dd 100644 --- a/src/Piece.hpp +++ b/src/Piece.hpp @@ -16,9 +16,9 @@ namespace chessarbiter { */ class Piece { public: + char piece; bool isBlack; std::string coord; - char piece; Piece(char c, const std::string &coord); /// @brief Get all possible moves according to the type of piece and its position std::vector GetMoves(); diff --git a/tests/chessarbiter.cpp b/tests/chessarbiter.cpp index 1c013cc..0a49e22 100644 --- a/tests/chessarbiter.cpp +++ b/tests/chessarbiter.cpp @@ -529,4 +529,8 @@ TEST_CASE("Specific bugs found on a game", "[BugFixes]") { a.Setup("rnb1k1nr/pppp1ppp/4P3/8/1b3B2/1Nq5/PPP1PPPP/R2KNB1R b kq - 16 12"); a.Play("c3e1"); CHECK(a.GetSAN()=="Qxe1#"); + + // Bug 8 Not a bug but just check if bishop cannot jump above pieces + a.Setup("rnbqkbnr/p1pp1ppp/8/1p2p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1"); + CHECK(!a.Play("f1a6")); } \ No newline at end of file