From 809063825a9b0cc1edd01816ec78de55b0d7683e Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 26 Jul 2026 16:08:46 +0200 Subject: improing code --- src/board.cpp | 5 +++-- src/main.cpp | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/board.cpp b/src/board.cpp index 201bd3a..081cc7d 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -11,7 +11,7 @@ const char toChar(pieceType type) { switch (type) { case NONE: - return '.'; + return '.'; case PAWN: return 'P'; case KNIGHT: @@ -25,7 +25,8 @@ const char toChar(pieceType type) { case KING: return 'K'; default: - std::unreachable(); + assert(false && "Unknown piece"); + return '?'; } } diff --git a/src/main.cpp b/src/main.cpp index ba5e57c..7a6e7f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ #include "board.hpp" -#include "fen.hpp" +#include "fen.hpp" #include "moves.hpp" #include #include @@ -10,11 +10,6 @@ #include #include -Piece NonePiece = { - false, - NONE, - false, -}; #include bool isValidChessRank(char rank) { @@ -31,6 +26,16 @@ bool isValidChessFile(char rank) { return false; } } +void setAllPiecesToEmpty(board *b) { + Piece NonePiece = { + false, + NONE, + false, + }; + for (int i = 0; i < 64; i++) { + b->pieces[i] = NonePiece; + }; +} void PrintMoves(const std::vector &moves) { std::cout << "Moves (" << moves.size() << "):\n"; @@ -41,7 +46,8 @@ void PrintMoves(const std::vector &moves) { } } int main(int argc, char **argv) { - std::string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/8/RNBQKBNR w KQkq - 0 1"; + std::string startingFen = + "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; if (argc < 1 || argc > 2) { printf("wrong arg count, use: ./chess [optinal starting fen]\n"); return 1; @@ -55,9 +61,6 @@ int main(int argc, char **argv) { b.castle = ""; b.halfMoveClock = 0; b.MoveClock = 0; - for (int i = 0; i < 64; i++) { - b.pieces[i] = NonePiece; - }; setBoardFen(startingFen, &b); printBoard(&b); while (true) { -- cgit v1.2.3