-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (46 loc) · 1.54 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include "documentation/board.h"
#include "documentation/moves.h"
#include "engine/search.h"
#include "evaluator/classical_eval/eval.h"
#include "documentation/move.h"
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: ./necai_engine \"<fen>\" <depth>\n";
return 1;
}
std::string fen = argv[1];
int depth = std::atoi(argv[2]);
if (depth < 1) {
depth = 1;
}
Board board;
board.load_fen(fen);
MoveGenerator generator(board);
std::vector<Move> legal_moves = generator.generate_moves();
if (legal_moves.empty()) {
bool in_check = board.is_in_check(board.is_white_turn());
std::cout << "{";
std::cout << "\"best_move\": null, ";
std::cout << "\"game_over\": true, ";
std::cout << "\"reason\": \"" << (in_check ? "checkmate" : "stalemate") << "\"";
std::cout << "}\n";
return 0;
}
Search search(board);
Move best = search.best_move(depth);
Eval eval(board);
int current_eval = eval.evaluate();
// evaluate() returns score from side-to-move's perspective; flip to
// White's perspective so the UI can interpret it consistently.
if (!board.is_white_turn()) current_eval = -current_eval;
std::cout << "{";
std::cout << "\"best_move\": \"" << move_to_uci(best) << "\", ";
std::cout << "\"engine_eval\": " << current_eval << ", ";
std::cout << "\"game_over\": false";
std::cout << "}\n";
return 0;
}