summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-27 09:42:26 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-27 09:42:26 +0100
commit8238444024716cdf344a08434855e772f32685ef (patch)
treebb5e928dde2b47f0d816345e28d0c45790774cfd
parentaa5aac203becba63416d8bc8079ef095b6fa4c09 (diff)
Cleaning code
-rw-r--r--src/ChessArbiter.cpp16
-rw-r--r--src/ChessArbiter.hpp16
2 files changed, 16 insertions, 16 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index 9207e80..a6dddf3 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(const 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(const std::string move, const char promote) {
+bool ChessArbiter::Play(const std::string &move, char promote) {
std::vector<std::string> 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(const std::string move, const char promote) {
bool ChessArbiter::WasEnPassant() { return (was_enpassant); }
-bool ChessArbiter::IsAttacked(const std::string square, const bool by) {
+bool ChessArbiter::IsAttacked(const std::string &square, bool by) {
std::vector<std::string> moves = board.ListPossibleMoves(by);
for (std::string &m : moves) {
std::string src = m.substr(0, 2);
@@ -209,7 +209,7 @@ bool ChessArbiter::IsAttacked(const std::string square, const bool by) {
return (false);
}
-bool ChessArbiter::IsCastlePossible(const bool isBlack, const bool isLong) {
+bool ChessArbiter::IsCastlePossible(bool isBlack, 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(const bool isBlack) {
+std::string ChessArbiter::GetCaptures(bool isBlack) {
std::string captures;
// Pawn
char p = 'P';
@@ -320,7 +320,7 @@ std::string ChessArbiter::GetCaptures(const bool isBlack) {
return (captures);
}
-std::vector<std::string> ChessArbiter::ListLegalMoves(const bool isBlack) {
+std::vector<std::string> ChessArbiter::ListLegalMoves(bool isBlack) {
std::vector<std::string> 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(const std::string SANMove) {
+std::string ChessArbiter::ParseSAN(const std::string &SANMove) {
std::string src, dst;
char piece = ' ';
char hint = ' ';
@@ -530,7 +530,7 @@ std::string ChessArbiter::ParseSAN(const std::string SANMove) {
return (src + dst);
}
-char ChessArbiter::ParseSANPromotion(const std::string SANMove){
+char ChessArbiter::ParseSANPromotion(const std::string &SANMove){
if(SANMove.length()>=4 && SANMove[0] - 'a' < 8 && SANMove[2]=='='){
char p=SANMove[3]; // Must be upper
if(p=='Q' || p=='R' || p=='B' || p=='N'){
diff --git a/src/ChessArbiter.hpp b/src/ChessArbiter.hpp
index 1379db2..b874493 100644
--- a/src/ChessArbiter.hpp
+++ b/src/ChessArbiter.hpp
@@ -37,16 +37,16 @@ class ChessArbiter {
public:
ChessArbiter();
- void Setup(const std::string);
+ void Setup(const std::string &fen);
std::string GetFEN();
/// @brief Check which player is going to play
bool IsBlackTurn();
/// @brief Check if a side is in check
bool IsCheck(bool);
/// @brief Play a move (return false if it's illegal)
- bool Play(const std::string, const char promote='Q');
+ bool Play(const std::string &move, char promote='Q');
/// @brief Check if a square is attacked by a particular player
- bool IsAttacked(const std::string, const bool);
+ bool IsAttacked(const std::string &square, bool);
/// @brief Get the serialized board
std::string GetBoard();
/// @brief Get current position evaluation according to player's material
@@ -54,14 +54,14 @@ public:
/// @brief Check if position is legal to be played
bool IsPlayable();
/// @brief Get pieces captures by a player
- std::string GetCaptures(const bool);
+ std::string GetCaptures(bool);
char GetCapture();
/// @brief Get the english SAN format of the last move
std::string GetSAN();
/// @brief List all the legal moves of a player
- std::vector<std::string> ListLegalMoves(const bool);
+ std::vector<std::string> ListLegalMoves(bool);
/// @brief Check if a specific castle is possible by a player
- bool IsCastlePossible(const bool, const bool);
+ bool IsCastlePossible(bool, bool);
bool IsCheckMate();
/// @brief Draws check
bool IsDrawByFiftyMoveRule();
@@ -69,7 +69,7 @@ public:
bool IsDrawByRepetitions();
bool IsDraw();
bool WasEnPassant();
- std::string ParseSAN(const std::string SANMove);
- char ParseSANPromotion(const std::string SANMove);
+ std::string ParseSAN(const std::string &SANMove);
+ char ParseSANPromotion(const std::string &SANMove);
};
} // namespace chessarbiter