aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-26 16:08:46 +0200
committerAdam <adammegarules1@gmail.com>2026-07-26 16:08:46 +0200
commit809063825a9b0cc1edd01816ec78de55b0d7683e (patch)
tree2c5549ad9826a27298dc73db2d9dccc275f08429 /src
parentde369006392e6e8fa2089e3cf68ce9fcbf07963d (diff)
improing code
Diffstat (limited to 'src')
-rw-r--r--src/board.cpp5
-rw-r--r--src/main.cpp23
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 <algorithm>
#include <cctype>
@@ -10,11 +10,6 @@
#include <string>
#include <vector>
-Piece NonePiece = {
- false,
- NONE,
- false,
-};
#include <iostream>
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<Move> &moves) {
std::cout << "Moves (" << moves.size() << "):\n";
@@ -41,7 +46,8 @@ void PrintMoves(const std::vector<Move> &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) {