Chess Engine
C++ chess engine with movegen, bitboards, and Arduino-friendly docs
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// main.cpp
2#include <cstdio>
3#include <cstdlib>
4#include <cstring>
5
6#include "defs.h"
7#include "board/board_data.h"
8#include "board/board.h"
10#include "move/make_move.h"
11#include "util/notation.h"
12#include "util/setup.h"
14
15
16
17
18
19
20#include "test/perft.h"
21
22
23//PERF TEST
24
25
26int main() {
28
29 S_BOARD pos[1];
30 loadFEN(START_FEN, pos); // start position
31 printBoardState(pos);
32
33 int depth = 5; //depth of perf testing
34 PerftTest(depth, pos);
35
36 return 0;
37}
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58/*
59
60
61MOVE GENERATOR WITH USER INPUT
62
63
64
65*/
66
67
68
69
70// int main(int /*argc*/, char* /*argv*/[]) {
71// initializeEngine();
72
73// S_BOARD pos[1];
74
75// std::setbuf(stdin, nullptr);
76// std::setbuf(stdout, nullptr);
77
78// // Load start position so "e2" etc. works immediately
79// if (loadFEN(START_FEN, pos) != 0) {
80// std::printf("Failed to parse START_FEN\n");
81// }
82
83// std::printf("Type a square (e.g., 'e2'), then a destination (e.g., 'e4').\n");
84// std::printf("Commands: board | new | fen <FEN> | undo | quit\n");
85
86// // Selection state
87// int pending_from = NO_SQ;
88// int pending_moves[MAXPOSITIONMOVES];
89// char pending_labels[MAXPOSITIONMOVES][8];
90// int pending_count = 0;
91
92// char line[512];
93
94// while (TRUE) {
95// std::memset(line, 0, sizeof(line));
96// std::fflush(stdout);
97
98// if (!std::fgets(line, static_cast<int>(sizeof(line)), stdin)) continue;
99// if (line[0] == '\n') continue;
100
101// // Commands
102// if (!std::strncmp(line, "quit", 4)) break;
103
104// if (!std::strncmp(line, "board", 5)) {
105// printBoardState(pos);
106// continue;
107// }
108
109// if (!std::strncmp(line, "new", 3)) {
110// loadFEN(START_FEN, pos);
111// pending_from = NO_SQ;
112// pending_count = 0;
113// printBoardState(pos);
114// continue;
115// }
116
117// if (!std::strncmp(line, "fen ", 4)) {
118// const char* fen = line + 4;
119// if (loadFEN(const_cast<char*>(fen), pos) != 0) std::printf("Bad FEN\n");
120// pending_from = NO_SQ;
121// pending_count = 0;
122// printBoardState(pos);
123// continue;
124// }
125
126// if (!std::strncmp(line, "undo", 4)) {
127// if (pos->hisPly > 0) {
128// takeMove(pos);
129// pending_from = NO_SQ;
130// pending_count = 0;
131// printBoardState(pos);
132// } else {
133// std::printf("Nothing to undo\n");
134// }
135// continue;
136// }
137
138// // If no pending selection, treat input as a "from" square.
139// if (pending_from == NO_SQ) {
140// const int from = ParseSquare2(line);
141// if (from == -1) {
142// std::printf("Unknown command or bad square. Try: e2 | board | new | fen <FEN> | undo | quit\n");
143// continue;
144// }
145
146// const int pce = pos->pieces[from];
147// if (pce == EMPTY || pce == OFFBOARD) {
148// std::printf("No piece on %s\n", squareToString(from));
149// continue;
150// }
151// if (pieceColor[pce] != pos->side) {
152// std::printf("It's %s to move; %s has a %c on %s\n",
153// (pos->side == WHITE ? "White" : "Black"),
154// (pieceColor[pce] == WHITE ? "White" : "Black"),
155// pieceToCharacter[pce],
156// squareToString(from));
157// continue;
158// }
159
160// pending_count = LegalMovesFrom(pos, from, pending_moves, pending_labels, MAXPOSITIONMOVES);
161// if (pending_count == 0) {
162// std::printf("No legal moves for %s\n", squareToString(from));
163// continue;
164// }
165
166// pending_from = from;
167// std::printf("Legal moves for %s (%c): ", squareToString(from), pieceToCharacter[pce]);
168// for (int i = 0; i < pending_count; ++i) {
169// std::printf("%s%s", pending_labels[i], (i + 1 == pending_count ? "" : " "));
170// }
171// std::printf("\n");
172// continue;
173// }
174
175// // We have a pending from-square; treat input as a destination.
176// const char* p = line;
177// while (*p == ' ') ++p;
178
179// const int chosen = MatchDestinationMove(pos, pending_from, p, pending_moves, pending_count);
180// if (chosen == NOMOVE) {
181// std::printf("'%.*s' is not a legal destination for %s. Try again.\n",
182// static_cast<int>(std::strcspn(p, "\n")), p, squareToString(pending_from));
183// continue;
184// }
185
186// // Make the move
187// if (makeMove(pos, chosen) == TRUE) {
188// pending_from = NO_SQ;
189// pending_count = 0;
190// printBoardState(pos);
191
192// std::printf("%s to move. Select a piece (e.g., '%s').\n",
193// (pos->side == WHITE ? "White" : "Black"),
194// (pos->side == WHITE ? "e2" : "e7"));
195// } else {
196// std::printf("Internal error: move became illegal. Try again.\n");
197// }
198// }
199
200// return 0;
201// }
int loadFEN(char *fen, S_BOARD *pos)
Parse a FEN string into the given board state.
Definition board.cpp:146
void printBoardState(const S_BOARD *pos)
Print the board to stdout in a human-readable format.
Definition board.cpp:272
#define START_FEN
Definition defs.h:35
int main()
Definition main.cpp:26
void PerftTest(int depth, S_BOARD *pos)
Executes a perft test and prints move breakdown and timing.
Definition perft.cpp:32
void initializeEngine()
Run all initialization routines.
Definition setup.cpp:156