aboutsummaryrefslogtreecommitdiff
path: root/src/board.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-26 14:10:48 +0200
committerAdam <adammegarules1@gmail.com>2026-07-26 14:10:48 +0200
commitc04f179b9902532a8d5db0c2ebd98460a70fc652 (patch)
tree6fe2718c2a172a24c5bf2fc24030392007c80ffa /src/board.cpp
parent1db141c6c0d87cde4270d50b661162273ef6a9f5 (diff)
making repl work
Diffstat (limited to 'src/board.cpp')
-rw-r--r--src/board.cpp168
1 files changed, 26 insertions, 142 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 5c30d75..e8fa787 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -5,9 +5,6 @@
#include <print>
#include <string>
-bool WHITE = true;
-bool BLACK = false;
-
const char toChar(pieceType type) {
switch (type) {
case NONE:
@@ -43,153 +40,40 @@ void printBoard(board *b) {
std::cout << letter;
std::cout << line;
- for (int rank = 0; rank < 8; rank++) {
- std::printf("%d |", 8 - rank);
- for (int file = 0; file < 8; file++) {
- Piece piece = b->pieces[rank * 8 + file];
- char symbol = toChar(piece.type);
- if (piece.color == BLACK) {
- symbol = std::tolower(static_cast<unsigned char>(symbol));
+ if (b->turn) {
+ for (int rank = 0; rank < 8; rank++) {
+ std::printf("%d |", 8 - rank);
+ for (int file = 0; file < 8; file++) {
+ Piece piece = b->pieces[rank * 8 + file];
+ char symbol = toChar(piece.type);
+ if (piece.color == false) {
+ symbol = std::tolower(static_cast<unsigned char>(symbol));
+ }
+ std::printf(" %c", symbol);
+ }
+ std::printf(" | %d\n", 8 - rank);
+ }
+ } else {
+ for (int rank = 7; rank >= 0; rank--) {
+ std::printf("%d |", 8 - rank);
+ for (int file = 7; file >= 0; file--) {
+ Piece piece = b->pieces[rank * 8 + file];
+ char symbol = toChar(piece.type);
+ if (piece.color == false) {
+ symbol = std::tolower(static_cast<unsigned char>(symbol));
+ }
+ std::printf(" %c", symbol);
}
- std::printf(" %c", symbol);
+ std::printf(" | %d\n", 8 - rank);
}
- std::printf(" | %d\n", 8 - rank);
}
std::cout << line;
std::cout << letter;
std::println();
- std::println("Turn: {}", b->turn == WHITE ? "White" : "Black");
+ std::println("Turn: {}", b->turn ? "White" : "Black");
std::println("Castling: {}", b->castle);
}
-void setBoardFen(std::string fen, board *b) {
- // example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
- int file = 0;
- int rank = 0;
-
- std::string castle = "";
-
- enum parserState {
- POSITION,
- TURN,
- CASTLE,
- ENPASSANT,
- CLOCK1,
- CLOCK2,
- };
- parserState state = POSITION;
-
- for (int i = 0; i < fen.length(); i++) {
- std::printf("state: %d\n", state);
- std::printf("doing: %c\n", fen[i]);
- if (fen[i] == ' ') {
- if (state == POSITION) {
- state = TURN;
- continue;
- }
- if (state == TURN) {
- state = CASTLE;
- continue;
- }
- if (state == CASTLE) {
- state = ENPASSANT;
- continue;
- }
- if (state == ENPASSANT) {
- state = CLOCK1;
- continue;
- }
- if (state == CLOCK1) {
- state = CLOCK2;
- continue;
- }
- }
- if (state == ENPASSANT) {
- continue;
- }
- if (state == CASTLE) {
- if (fen[i] == '-') {
- castle = "-";
- continue;
- }
- if (toupper(fen[i]) == 'K') {
- castle += fen[i];
- continue;
- }
- if (toupper(fen[i]) == 'Q') {
- castle += fen[i];
- continue;
- }
- }
- if (state == TURN) {
- if (toupper(fen[i]) == 'W') {
- b->turn = WHITE;
- continue;
- }
- if (toupper(fen[i]) == 'B') {
- b->turn = BLACK;
- continue;
- }
- }
- if (state == POSITION) {
- if (isdigit(fen[i])) {
- int move = fen[i] - '0';
- file += move;
- if (file > 8) {
- std::println("Fatal: file was to big");
- return; // malformed rank
- }
- continue;
- }
- if (fen[i] == '/') {
- file = 0;
- rank++;
- if (rank > 8) {
- std::println("Fatal: rank was to big");
- 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;
- file++;
- continue;
- }
- if (toupper(fen[i]) == 'Q') {
- Piece piece = createPiece(QUEEN, isupper(fen[i]));
- b->pieces[rank * 8 + file] = piece;
- file++;
- continue;
- }
- if (toupper(fen[i]) == 'B') {
- Piece piece = createPiece(BISHOP, isupper(fen[i]));
- b->pieces[rank * 8 + file] = piece;
- file++;
- continue;
- }
- if (toupper(fen[i]) == 'P') {
- Piece piece = createPiece(PAWN, isupper(fen[i]));
- b->pieces[rank * 8 + file] = piece;
- file++;
- continue;
- }
- if (toupper(fen[i]) == 'K') {
- Piece piece = createPiece(KING, isupper(fen[i]));
- b->pieces[rank * 8 + file] = piece;
- file++;
- continue;
- }
- }
- break;
- }
- b->castle = castle.empty() ? "-" : castle;
-}
+void PlayMove(Move move, board *b) { return; }