aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-26 13:54:49 +0200
committerAdam <adammegarules1@gmail.com>2026-07-26 13:54:49 +0200
commit1db141c6c0d87cde4270d50b661162273ef6a9f5 (patch)
treeb1ae71321b6a9a9800b62e082029ff5ffa490bc8 /src/main.cpp
parent3b231aa281e16319f8bed37da49e53dd6b950650 (diff)
adding move chenging to repl
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a508042..bea30b0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,9 +1,11 @@
+#include <algorithm>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <print>
#include <string>
+#include <vector>
#include "board.hpp"
#include "moves.hpp"
@@ -39,8 +41,7 @@ void PrintMoves(const std::vector<Move> &moves) {
}
}
int main(int argc, char **argv) {
- std::string startingFen =
- "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
+ std::string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/8/RNBQKBNR w KQkq - 0 1";
if (argc < 1 || argc > 2) {
printf("wrong arg count, use: ./chess [optinal starting fen]\n");
return 1;
@@ -59,8 +60,6 @@ int main(int argc, char **argv) {
};
setBoardFen(startingFen, &b);
printBoard(&b);
- auto moves = GetLegalMoves(&b);
- PrintMoves(moves);
while (true) {
std::cout << "> ";
std::string command;
@@ -103,15 +102,26 @@ int main(int argc, char **argv) {
}
// we know its a valid chess pos
- uint8_t fromFile = command[0] - 'A';
- uint8_t fromRank = command[1] - '0';
- uint8_t toFile = command[2] - 'A';
- uint8_t toRank = command[3] - '0';
- std::cout << static_cast<int>(fromFile) << "\n";
- std::cout << static_cast<int>(fromRank) << "\n";
- std::cout << static_cast<int>(toFile) << "\n";
- std::cout << static_cast<int>(toRank) << "\n";
- Move move = {fromRank, fromFile, toRank, toFile};
+ int fromFile = command[0] - 'A';
+ int fromRank = '8' - command[1];
+ int toFile = command[2] - 'A';
+ int toRank = '8' - command[3];
+ std::cout << fromFile << "\n";
+ std::cout << fromRank << "\n";
+ std::cout << toFile << "\n";
+ std::cout << toRank << "\n";
+ Move move = {
+ {static_cast<uint8_t>(fromRank), static_cast<uint8_t>(fromFile)},
+ {static_cast<uint8_t>(toRank), static_cast<uint8_t>(toFile)}};
+
+ auto moves = GetLegalMoves(&b);
+ if (std::ranges::find(moves, move) != moves.end()) {
+ std::cout << "Move is legal!\n";
+ } else {
+ std::cout << "Move is not legal!\n";
+ PrintMoves(moves);
+ continue;
+ }
std::println();
}
return EXIT_SUCCESS;