aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/board/board.cpp4
-rw-r--r--src/board/board.hpp8
-rw-r--r--src/board/fen.cpp40
-rw-r--r--src/bot.cpp2
-rw-r--r--src/moves.cpp4
-rw-r--r--src/uci.cpp14
6 files changed, 37 insertions, 35 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp
index 8c8e423..af313d0 100644
--- a/src/board/board.cpp
+++ b/src/board/board.cpp
@@ -82,11 +82,11 @@ UndoMove MakeMove(Move move, Game *g) {
// Adding enpassant
if (piece.type == PAWN) {
Position to = move.To;
- to.rank -= (piece.color ? -2 : 2);
+ to.rank -= static_cast<uint8_t>(piece.color ? -2 : 2);
if (to == move.From) {
g->canEnpassant = true;
Position target = move.From;
- target.rank += piece.color ? -1 : 1;
+ target.rank += static_cast<uint8_t>(piece.color ? -1 : 1);
g->enPassant = target;
};
}
diff --git a/src/board/board.hpp b/src/board/board.hpp
index 7a9779a..5d0d913 100644
--- a/src/board/board.hpp
+++ b/src/board/board.hpp
@@ -27,8 +27,8 @@ struct Piece {
};
struct Position {
- uint8_t rank = 0;
- uint8_t file = 0;
+ int rank = 0;
+ int file = 0;
bool operator==(const Position &) const = default;
};
@@ -58,8 +58,8 @@ struct Game {
bool whiteCastleQueen = false;
bool blackCastleKing = false;
bool blackCastleQueen = false;
- uint8_t halfMoveClock = 0;
- uint16_t MoveClock = 0;
+ int halfMoveClock = 0;
+ int MoveClock = 0;
Position enPassant;
bool canEnpassant = false;
GameState state = TURN;
diff --git a/src/board/fen.cpp b/src/board/fen.cpp
index ccd8b6f..faa8f83 100644
--- a/src/board/fen.cpp
+++ b/src/board/fen.cpp
@@ -2,9 +2,11 @@
#include "board.hpp"
#include <cassert>
#include <cctype>
+#include <cstdint>
#include <cstdlib>
#include <print>
#include <string>
+#include <sys/types.h>
bool WHITE = true;
bool BLACK = false;
@@ -16,51 +18,51 @@ void setBoardFen(std::string fen, Game *g) {
Position enpassant = {};
enum parserState {
- POSITION,
- TURN,
+ BOARD,
+ PLAYER_TO_MOVE,
CASTLE,
ENPASSANT,
HALF_MOVE_CLOCK,
FULL_MOVE_CLOCK,
};
- parserState state = POSITION;
+ parserState parser_state = BOARD;
for (uint i = 0; i < fen.length(); i++) {
char c = fen[i];
if (c == ' ') {
- if (state == POSITION) {
- state = TURN;
+ if (parser_state == BOARD) {
+ parser_state = PLAYER_TO_MOVE;
continue;
}
- if (state == TURN) {
- state = CASTLE;
+ if (parser_state == PLAYER_TO_MOVE) {
+ parser_state = CASTLE;
continue;
}
- if (state == CASTLE) {
- state = ENPASSANT;
+ if (parser_state == CASTLE) {
+ parser_state = ENPASSANT;
continue;
}
- if (state == ENPASSANT) {
- state = HALF_MOVE_CLOCK;
+ if (parser_state == ENPASSANT) {
+ parser_state = HALF_MOVE_CLOCK;
continue;
}
- if (state == HALF_MOVE_CLOCK) {
- state = FULL_MOVE_CLOCK;
+ if (parser_state == HALF_MOVE_CLOCK) {
+ parser_state = FULL_MOVE_CLOCK;
continue;
}
}
- if (state == ENPASSANT) {
+ if (parser_state == ENPASSANT) {
if (toupper(c) >= 'A' && toupper(c) <= 'H') {
- enpassant.file = toupper(c) - 'A';
+ enpassant.file = static_cast<uint8_t>(toupper(c) - 'A');
g->canEnpassant = true;
}
if (c >= '1' && c <= '8') {
- enpassant.rank = c - '0';
+ enpassant.rank = static_cast<uint8_t>(c - '0');
g->canEnpassant = true;
}
continue;
}
- if (state == CASTLE) {
+ if (parser_state == CASTLE) {
if (c == '-') {
g->blackCastleKing = false;
g->blackCastleQueen = false;
@@ -85,7 +87,7 @@ void setBoardFen(std::string fen, Game *g) {
continue;
}
}
- if (state == TURN) {
+ if (parser_state == PLAYER_TO_MOVE) {
if (toupper(c) == 'W') {
g->turn = WHITE;
continue;
@@ -95,7 +97,7 @@ void setBoardFen(std::string fen, Game *g) {
continue;
}
}
- if (state == POSITION) {
+ if (parser_state == BOARD) {
if (isdigit(c)) {
int move = c - '0';
file += move;
diff --git a/src/bot.cpp b/src/bot.cpp
index 860bf84..0358241 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -326,7 +326,7 @@ Move GetBestMove(Game *b, const int maxDepth) {
if (depth >= actualDepth) {
continueSearching = false;
}
- int seconds_since_start = difftime(time(0), start);
+ int seconds_since_start = static_cast<int>(difftime(time(0), start));
if (seconds_since_start >= MAXIMUM_TIME_PER_MOVE && usingDefaultDepth) {
continueSearching = false;
}
diff --git a/src/moves.cpp b/src/moves.cpp
index 84c5ba4..b07c91b 100644
--- a/src/moves.cpp
+++ b/src/moves.cpp
@@ -354,8 +354,8 @@ bool IsSquareAttacked(Game *g, Position square, bool white) {
}
Position IndexToPosition(int i) {
- uint8_t rank = i / 8; // 0-7
- uint8_t file = i % 8; // 0-7
+ uint8_t rank = static_cast<uint8_t>(i / 8); // 0-7
+ uint8_t file = static_cast<uint8_t>(i % 8); // 0-7
return {rank, file};
}
diff --git a/src/uci.cpp b/src/uci.cpp
index 33289b0..d9972b2 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -41,11 +41,11 @@ Move UciToMove(string uci) {
Position from;
Position to;
- from.file = uci[0] - 'a';
- from.rank = '8' - uci[1];
+ from.file = static_cast<uint8_t>(uci[0] - 'a');
+ from.rank = static_cast<uint8_t>('8' - uci[1]);
- to.file = uci[2] - 'a';
- to.rank = '8' - uci[3];
+ to.file = static_cast<uint8_t>(uci[2] - 'a');
+ to.rank = static_cast<uint8_t>('8' - uci[3]);
return {from, to};
}
@@ -133,8 +133,8 @@ void Uci() {
Move best = GetBestMove(&game, depth);
cout << "bestmove ";
- cout << (char)(best.From.file + 'a') << 8 - best.From.rank
- << (char)(best.To.file + 'a') << 8 - best.To.rank;
+ cout << static_cast<char>(best.From.file + 'a') << 8 - best.From.rank
+ << static_cast<char>(best.To.file + 'a') << 8 - best.To.rank;
if (best.promotion != NONEPIECE) {
switch (best.promotion) {
@@ -206,7 +206,7 @@ void Uci() {
cout.flush();
continue;
}
- int count = MoveGenTest(depth, &game);
+ uint64_t count = MoveGenTest(depth, &game);
cout << count << "\n";
cout.flush();