From 159d5334128ff0bb90a8e4e85739dc8bc44baad8 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 30 Jan 2022 10:00:28 +0100 Subject: - Add drawing methods to the API - Improve tests --- src/Board.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Board.cpp') diff --git a/src/Board.cpp b/src/Board.cpp index afd32e3..0e88423 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -74,14 +74,11 @@ std::string Board::GetKingLocation(bool isBlack) { void Board::Move(std::string move) { std::string src(move.substr(0, 2)); std::string dst(move.substr(2, 2)); - if (!IsEmpty(src)) { - if (!IsEmpty(dst)) { - RemovePiece(dst); - } - for (Piece &p : pieces) { - if (p.coord == src) { - p.coord = dst; - } + for (Piece &p : pieces) { + if (p.coord == src) { + RemovePiece(dst); // Remove piece on dst if exists + p.coord = dst; + break; } } } @@ -116,6 +113,9 @@ bool Board::IsMovePossible(std::string move) { } // Check colors on dst square + // Seems that checking that is empty + // instead of catching NoPieceFound exception is + // more performant if (!IsEmpty(dst)) { Piece dstp = GetPieceAt(dst); if (srcp.isBlack == dstp.isBlack) -- cgit v1.2.3