summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-27 11:28:13 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-27 11:28:13 +0100
commitd32baf9894ce67850c83b6e4a281bd1cfd921a93 (patch)
tree0d760a3637bd9972f124bf22044b9ef41d6fad6a
parentf9ac11ad44b00f7e29ef2a9159c65f146f739835 (diff)
Improve code in general
-rw-r--r--src/ChessArbiter.cpp4
-rw-r--r--src/ChessArbiter.hpp4
-rw-r--r--src/Fen.cpp14
-rw-r--r--src/Fen.hpp10
-rw-r--r--src/Piece.cpp2
-rw-r--r--src/Piece.hpp2
6 files changed, 18 insertions, 18 deletions
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index 29b17c7..dece4b9 100644
--- a/src/ChessArbiter.cpp
+++ b/src/ChessArbiter.cpp
@@ -13,9 +13,9 @@ void ChessArbiter::Setup(const std::string &fen) {
positions[this->fen.board] = 1;
}
-void ChessArbiter::SetFEN(FEN fen) { SetFEN(FENParser::Serialize(fen)); }
+void ChessArbiter::SetFEN(const FEN &fen) { SetFEN(FENParser::Serialize(fen)); }
-void ChessArbiter::SetFEN(std::string newfen) {
+void ChessArbiter::SetFEN(const std::string &newfen) {
fen = FENParser::Parse(newfen);
board.Clear();
diff --git a/src/ChessArbiter.hpp b/src/ChessArbiter.hpp
index b874493..c29dd32 100644
--- a/src/ChessArbiter.hpp
+++ b/src/ChessArbiter.hpp
@@ -29,8 +29,8 @@ class ChessArbiter {
/// @brief Use to compute occurences of positions
std::unordered_map<std::string, char> positions;
/// @brief FEN methods used internally
- void SetFEN(std::string);
- void SetFEN(FEN);
+ void SetFEN(const std::string &newfen);
+ void SetFEN(const FEN &fen);
std::string SAN, SAN_last;
char capture;
bool was_enpassant;
diff --git a/src/Fen.cpp b/src/Fen.cpp
index f3acfe5..54dddfd 100644
--- a/src/Fen.cpp
+++ b/src/Fen.cpp
@@ -2,9 +2,9 @@
namespace chessarbiter {
-std::string FENParser::normalize_rank(std::string fen_rank) {
+std::string FENParser::normalize_rank(const std::string &fen_rank) {
std::string normalized;
- for (char &c : fen_rank) {
+ for (const char &c : fen_rank) {
if (IS_DIGIT(c)) {
for (char i = 0; i < (c - '0'); i++) {
normalized += ' ';
@@ -27,14 +27,14 @@ std::string FENParser::normalize_rank(std::string fen_rank) {
return (normalized);
}
-char FENParser::NextToken(std::string fen, char loc) {
+char FENParser::NextToken(const std::string &fen, char loc) {
while (loc < fen.size() && IS_BLANK(fen[loc])) {
loc++;
}
return (loc);
}
-char FENParser::NextRank(std::string fen, char loc) {
+char FENParser::NextRank(const std::string &fen, char loc) {
loc++;
while (loc < fen.size() && fen[loc] != '/' && fen[loc] != ' ') {
loc++;
@@ -42,11 +42,11 @@ char FENParser::NextRank(std::string fen, char loc) {
return (loc);
}
-std::string FENParser::Serialize(FEN fen) {
+std::string FENParser::Serialize(const FEN &fen) {
std::string s;
char skip = 0;
char rank = 0;
- for (char &c : fen.board) {
+ for (const char &c : fen.board) {
rank++;
if (c == ' ') {
skip++;
@@ -104,7 +104,7 @@ std::string FENParser::Serialize(FEN fen) {
return (s);
}
-FEN FENParser::Parse(std::string fen) {
+FEN FENParser::Parse(const std::string &fen) {
FEN parsed;
// Parse board
diff --git a/src/Fen.hpp b/src/Fen.hpp
index c7720b5..bcb93de 100644
--- a/src/Fen.hpp
+++ b/src/Fen.hpp
@@ -29,15 +29,15 @@ public:
class FENParser {
private:
- static std::string normalize_rank(std::string fen_rank);
- static char NextToken(std::string fen, char loc);
- static char NextRank(std::string fen, char loc);
+ static std::string normalize_rank(const std::string &fen_rank);
+ static char NextToken(const std::string &fen, char loc);
+ static char NextRank(const std::string &fen, char loc);
public:
/// @brief Parse a FEN from a string (can throw InvalidFEN)
- static FEN Parse(std::string);
+ static FEN Parse(const std::string &fen);
/// @brief Generate a fen string from the FEN object
- static std::string Serialize(FEN fen);
+ static std::string Serialize(const FEN &fen);
};
struct InvalidFEN : public std::exception {
diff --git a/src/Piece.cpp b/src/Piece.cpp
index 8ace179..2a32a9d 100644
--- a/src/Piece.cpp
+++ b/src/Piece.cpp
@@ -1,7 +1,7 @@
#include "Piece.hpp"
namespace chessarbiter {
-Piece::Piece(char c, std::string coord)
+Piece::Piece(char c, const std::string &coord)
: piece(c), isBlack(!isupper(c)), coord(coord) {}
std::vector<std::string> Piece::GetMoves() {
diff --git a/src/Piece.hpp b/src/Piece.hpp
index c1f19d6..7469ee2 100644
--- a/src/Piece.hpp
+++ b/src/Piece.hpp
@@ -19,7 +19,7 @@ public:
bool isBlack;
std::string coord;
char piece;
- Piece(char c, std::string coord);
+ Piece(char c, const std::string &coord);
/// @brief Get all possible moves according to the type of piece and its position
std::vector<std::string> GetMoves();
};