-
Notifications
You must be signed in to change notification settings - Fork 0
/
uci.cpp
118 lines (104 loc) · 2.19 KB
/
uci.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include "version.h"
#include "board.h"
#include "search.h"
#include "history.h"
#include "book.h"
#include "table.h"
using namespace std;
// UCI command interface
extern vector<board> history;
int main()
{
string inputline;
board b;
while(getline(cin, inputline))
{
istringstream input(inputline);
string command;
input >> command;
if (command == "uci")
{
initBook();
srand(time(NULL));
cout << "id name " << ENGINE_NAME << endl;
cout << "id version " << ENGINE_VERSION << endl;
cout << "uciok" << endl;
}
else if (command == "isready")
{
cout << "readyok" << endl;
}
else if (command == "position")
{
clearHistory();
string FEN_A, FEN_B, FEN_C, FEN_D, FEN_E, FEN_F;
string move;
input >> FEN_A;
if (FEN_A == "startpos")
{
b = board();
}
else
{
input >> FEN_B >> FEN_C >> FEN_D >> FEN_E >> FEN_F;
b = board(FEN_A + " " + FEN_B + " " + FEN_C + " " + FEN_D + " " + FEN_E + " " + FEN_F);
}
input >> FEN_A;
pushHistory(b);
while (input)
{
input >> move;
if (!input)
break;
b.executeMove(b.parseMove(move));
pushHistory(b);
}
}
else if (command == "go")
{
int wtime = 0;
int btime = 0;
int movestogo = 0;
resetTableHits();
// Parse rest of input
while (input)
{
string subcommand;
input >> subcommand;
if (subcommand == "wtime")
input >> wtime;
else if (subcommand == "btime")
input >> btime;
else if (subcommand == "movestogo")
input >> movestogo;
}
// Find move
move bestMove;
if (findMove(b, bestMove, wtime, btime, movestogo))
{
cout << "bestmove " << bestMove.dump() << endl;
}
else
{
cout << "bestmove 0000" << endl;
}
cout << "info string tablehits: " << queryTableHits() << "/" << queryTableTotal() << endl;
cout << "info string table frac: " << (double(queryTableHits())/double(queryTableTotal())) << endl;
}
else if (command == "quit")
{
return 0;
}
else
{
cout << "info string unrecognized command " << command << endl;
}
cout.flush();
}
}