From aa5aac203becba63416d8bc8079ef095b6fa4c09 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 27 Dec 2022 09:34:33 +0100 Subject: Cleaning code --- src/ChessArbiter.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/ChessArbiter.cpp') diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp index 0064234..9207e80 100644 --- a/src/ChessArbiter.cpp +++ b/src/ChessArbiter.cpp @@ -7,7 +7,7 @@ ChessArbiter::ChessArbiter() Setup("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); } -void ChessArbiter::Setup(std::string fen) { +void ChessArbiter::Setup(const std::string fen) { positions.clear(); SetFEN(fen); positions[this->fen.board] = 1; @@ -39,7 +39,7 @@ bool ChessArbiter::IsCheck(bool isBlack) { return (IsAttacked(kingloc, !isBlack)); } -bool ChessArbiter::Play(std::string move, char promote) { +bool ChessArbiter::Play(const std::string move, const char promote) { std::vector moves = ListLegalMoves(fen.player); if (find(moves.begin(), moves.end(), move) != moves.end()) { Piece moved = board.GetPieceAt(move.substr(0, 2)); // This call never fail @@ -189,7 +189,7 @@ bool ChessArbiter::Play(std::string move, char promote) { bool ChessArbiter::WasEnPassant() { return (was_enpassant); } -bool ChessArbiter::IsAttacked(std::string square, bool by) { +bool ChessArbiter::IsAttacked(const std::string square, const bool by) { std::vector moves = board.ListPossibleMoves(by); for (std::string &m : moves) { std::string src = m.substr(0, 2); @@ -209,7 +209,7 @@ bool ChessArbiter::IsAttacked(std::string square, bool by) { return (false); } -bool ChessArbiter::IsCastlePossible(bool isBlack, bool isLong) { +bool ChessArbiter::IsCastlePossible(const bool isBlack, const bool isLong) { if (isBlack && isLong && fen.black_castle_long) { if (board.IsEmpty("d8") && board.IsEmpty("c8") && board.IsEmpty("b8")) { @@ -273,7 +273,7 @@ int ChessArbiter::GetMaterialScore() { return (whiteScore - blackScore); } -std::string ChessArbiter::GetCaptures(bool isBlack) { +std::string ChessArbiter::GetCaptures(const bool isBlack) { std::string captures; // Pawn char p = 'P'; @@ -320,7 +320,7 @@ std::string ChessArbiter::GetCaptures(bool isBlack) { return (captures); } -std::vector ChessArbiter::ListLegalMoves(bool isBlack) { +std::vector ChessArbiter::ListLegalMoves(const bool isBlack) { std::vector moves; for (std::string &move : board.ListPossibleMoves(isBlack)) { std::string src = move.substr(0, 2); @@ -425,7 +425,7 @@ bool ChessArbiter::IsCheckMate() { std::string ChessArbiter::GetSAN() { return (SAN); } char ChessArbiter::GetCapture() { return (capture); } -std::string ChessArbiter::ParseSAN(std::string SANMove) { +std::string ChessArbiter::ParseSAN(const std::string SANMove) { std::string src, dst; char piece = ' '; char hint = ' '; @@ -530,15 +530,11 @@ std::string ChessArbiter::ParseSAN(std::string SANMove) { return (src + dst); } -char ChessArbiter::ParseSANPromotion(std::string SANMove){ - for(short i=0;i=4 && SANMove[0] - 'a' < 8 && SANMove[2]=='='){ + char p=SANMove[3]; // Must be upper + if(p=='Q' || p=='R' || p=='B' || p=='N'){ + return p; } } return 'Q'; -- cgit v1.2.3