aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-26 15:45:51 +0200
committerAdam <adammegarules1@gmail.com>2026-07-26 15:45:51 +0200
commit54704ebd1b03b3f33bcd7d2905a8538f5a842f0f (patch)
tree759637f24570f3a0332ae2c81247d35084861ca1
parente0cfca5590c2a41b5c4c0b269edeefca6041eb69 (diff)
i am stupid
-rw-r--r--src/board.cpp8
-rw-r--r--src/board.hpp1
-rw-r--r--src/fen.cpp5
-rw-r--r--src/fen.hpp10
-rw-r--r--src/main.cpp12
5 files changed, 21 insertions, 15 deletions
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 <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <print>
#include <string>
+#include <utility>
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 <cctype>
#include <cstdio>
@@ -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 <string>
#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 <algorithm>
#include <cctype>
@@ -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();