summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-01-30 13:14:58 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-01-30 13:14:58 +0100
commitf42a6ac20b9f14fd391269cd90606d91a592b2f1 (patch)
treea432460e6f16da333d66a8b49c773edea1687aab
parent159d5334128ff0bb90a8e4e85739dc8bc44baad8 (diff)
Cleaning code
-rw-r--r--src/Board.cpp8
-rw-r--r--src/ChessArbiter.cpp1
-rw-r--r--src/Fen.cpp26
-rw-r--r--src/Fen.hpp6
4 files changed, 20 insertions, 21 deletions
diff --git a/src/Board.cpp b/src/Board.cpp
index 0e88423..a107c02 100644
--- a/src/Board.cpp
+++ b/src/Board.cpp
@@ -72,8 +72,8 @@ 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));
+ std::string src = move.substr(0, 2);
+ std::string dst = move.substr(2, 2);
for (Piece &p : pieces) {
if (p.coord == src) {
RemovePiece(dst); // Remove piece on dst if exists
@@ -99,8 +99,8 @@ std::string Board::Serialize() {
}
bool Board::IsMovePossible(std::string move) {
- std::string src(move.substr(0, 2));
- std::string dst(move.substr(2, 2));
+ std::string src = move.substr(0, 2);
+ std::string dst = move.substr(2, 2);
if (src == dst) {
return (false);
}
diff --git a/src/ChessArbiter.cpp b/src/ChessArbiter.cpp
index 1d1379d..b2e73b6 100644
--- a/src/ChessArbiter.cpp
+++ b/src/ChessArbiter.cpp
@@ -133,7 +133,6 @@ bool ChessArbiter::IsAttacked(std::string square, bool by) {
for (std::string &m : moves) {
std::string src = m.substr(0, 2);
std::string dst = m.substr(2, 2);
-
if (dst == square) {
// Pawn do not attack forward
Piece p = board.GetPieceAt(src);
diff --git a/src/Fen.cpp b/src/Fen.cpp
index 804ecd0..f3acfe5 100644
--- a/src/Fen.cpp
+++ b/src/Fen.cpp
@@ -5,7 +5,7 @@ namespace chessarbiter {
std::string FENParser::normalize_rank(std::string fen_rank) {
std::string normalized;
for (char &c : fen_rank) {
- if (FEN__IS_DIGIT(c)) {
+ if (IS_DIGIT(c)) {
for (char i = 0; i < (c - '0'); i++) {
normalized += ' ';
}
@@ -28,7 +28,7 @@ std::string FENParser::normalize_rank(std::string fen_rank) {
}
char FENParser::NextToken(std::string fen, char loc) {
- while (loc < fen.size() && FEN__IS_BLANK(fen[loc])) {
+ while (loc < fen.size() && IS_BLANK(fen[loc])) {
loc++;
}
return (loc);
@@ -110,7 +110,7 @@ FEN FENParser::Parse(std::string fen) {
// Parse board
char loc = 0;
for (char rank = 0; rank < 8; rank++) {
- FEN__CHECK_LOC();
+ CHECK_LOC();
char newloc = NextRank(fen, loc);
parsed.board += normalize_rank(fen.substr(loc, newloc - loc));
loc = newloc + 1;
@@ -122,16 +122,16 @@ FEN FENParser::Parse(std::string fen) {
throw InvalidFEN();
}
parsed.player = fen[loc] == 'b';
- FEN__CHECK_LOC();
+ CHECK_LOC();
// Parse castling
loc = NextToken(fen, loc + 1);
char length = 0;
char cur_loc = loc;
- while (!FEN__IS_BLANK(fen[cur_loc])) {
+ while (!IS_BLANK(fen[cur_loc])) {
length++;
cur_loc++;
- FEN__CHECK_LOC();
+ CHECK_LOC();
}
parsed.white_castle_short = false;
parsed.white_castle_long = false;
@@ -172,29 +172,29 @@ FEN FENParser::Parse(std::string fen) {
}
}
loc++;
- FEN__CHECK_LOC();
+ CHECK_LOC();
// Parse half move counter
loc = NextToken(fen, loc);
std::string halfmove;
- while (!FEN__IS_BLANK(fen[loc])) {
- if (!FEN__IS_DIGIT(fen[loc])) {
+ while (!IS_BLANK(fen[loc])) {
+ if (!IS_DIGIT(fen[loc])) {
throw InvalidFEN();
}
halfmove += fen[loc];
loc++;
- FEN__CHECK_LOC();
+ CHECK_LOC();
}
parsed.halfmove = stoi(halfmove);
// Parse move counter
loc = NextToken(fen, loc);
std::string move;
- while (loc < fen.size() && !FEN__IS_BLANK(fen[loc])) {
- if (!FEN__IS_DIGIT(fen[loc])) {
+ while (loc < fen.size() && !IS_BLANK(fen[loc])) {
+ if (!IS_DIGIT(fen[loc])) {
throw InvalidFEN();
}
- FEN__CHECK_LOC();
+ CHECK_LOC();
move += fen[loc];
loc++;
}
diff --git a/src/Fen.hpp b/src/Fen.hpp
index 06ca338..c7720b5 100644
--- a/src/Fen.hpp
+++ b/src/Fen.hpp
@@ -2,11 +2,11 @@
#include <sstream>
#include <string>
-#define FEN__IS_DIGIT(c) \
+#define IS_DIGIT(c) \
(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || \
c == '6' || c == '7' || c == '8' || c == '9')
-#define FEN__IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r')
-#define FEN__CHECK_LOC() {if(loc>=fen.size()){throw InvalidFEN();}}
+#define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r')
+#define CHECK_LOC() {if(loc>=fen.size()){throw InvalidFEN();}}
namespace chessarbiter {