From 54704ebd1b03b3f33bcd7d2905a8538f5a842f0f Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 26 Jul 2026 15:45:51 +0200 Subject: i am stupid --- src/board.cpp | 8 +++++++- src/board.hpp | 1 - src/fen.cpp | 5 +++-- src/fen.hpp | 10 ++++------ src/main.cpp | 12 +++++++----- 5 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/board.cpp b/src/board.cpp index cbafcc6..201bd3a 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -1,11 +1,14 @@ #include "board.hpp" +#include #include #include #include #include #include +#include const char toChar(pieceType type) { + switch (type) { case NONE: return '.'; @@ -22,7 +25,7 @@ const char toChar(pieceType type) { case KING: return 'K'; default: - return '?'; + std::unreachable(); } } @@ -80,6 +83,9 @@ void printBoard(board *b) { std::println(); std::println("Turn: {}", b->turn ? "White" : "Black"); + + assert(b->castle != ""); + std::println("Castling: {}", b->castle); } diff --git a/src/board.hpp b/src/board.hpp index f085326..23f89ad 100644 --- a/src/board.hpp +++ b/src/board.hpp @@ -43,7 +43,6 @@ struct Move { bool operator==(const Move &) const = default; }; void printBoard(board *b); -void setBoardFen(std::string fen, board *b); Piece createPiece(pieceType type, bool color, bool moved = false); void PlayMove(Move move, board *b); // TODO implement diff --git a/src/fen.cpp b/src/fen.cpp index 8244425..a6773c2 100644 --- a/src/fen.cpp +++ b/src/fen.cpp @@ -1,3 +1,4 @@ +#include "fen.hpp" #include "board.hpp" #include #include @@ -94,13 +95,13 @@ void setBoardFen(std::string fen, board *b) { return; // malformed rank } continue; - } + }; if (toupper(fen[i]) == 'N') { Piece piece = createPiece(KNIGHT, isupper(fen[i])); b->pieces[rank * 8 + file] = piece; file++; continue; - } + }; if (toupper(fen[i]) == 'R') { Piece piece = createPiece(ROOK, isupper(fen[i])); b->pieces[rank * 8 + file] = piece; diff --git a/src/fen.hpp b/src/fen.hpp index 55d47ae..19f88e2 100644 --- a/src/fen.hpp +++ b/src/fen.hpp @@ -1,11 +1,9 @@ -#ifndef SRC_BOARD_H_ -#define SRC_BOARD_H_ +#ifndef SRC_FEN_H_ +#define SRC_FEN_H_ #include #include "board.hpp" -using namespace std; - -void setBoardFen(string fen, board *b); -#endif /* SRC_BOARD_H_ */ +void setBoardFen(std::string fen, board *b); +#endif /* SRC_FEN_H_ */ diff --git a/src/main.cpp b/src/main.cpp index d59195d..ba5e57c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "board.hpp" +#include "fen.hpp" #include "moves.hpp" #include #include @@ -66,16 +67,17 @@ int main(int argc, char **argv) { std::cout << command << "\n"; transform(command.begin(), command.end(), command.begin(), ::toupper); - if (command.length() != 4) { - std::cout << "Unknown Command, use EXIT to exit"; - std::println(); - continue; - } if (command == "EXIT") { std::println(); std::cout << "Exiting...\n"; return 0; } + + if (command.length() != 4) { + std::cout << "Unknown Command, use EXIT to exit"; + std::println(); + continue; + } if (!isValidChessFile(command[0])) { std::cout << "ERROR: Expected valid file at first place"; std::println(); -- cgit v1.2.3