Skip to content

Commit 4b76a36

Browse files
committed
fixed some user bugs
1 parent 55b4b0e commit 4b76a36

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

main.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
#include "uci.h"
33
#include "ucioption.h"
44
#include <iostream>
5+
#include <thread>
56
using namespace engine;
7+
extern std::thread searchThread;
68
int main() {
79
options.add("Move Overhead", Option(10, 0, 1000));
8-
options.add( //
9-
"Hash", Option(16, 1, 1 << 25, [](const Option &o) {
10-
search::tt.resize((o.operator int()));
11-
return std::nullopt;
12-
}));
10+
options.add("Hash", Option(16, 1, 1 << 25, [](const Option &o) {
11+
search::tt.resize((o.operator int()));
12+
return std::nullopt;
13+
}));
1314

14-
options.add( //
15-
"Clear Hash", Option(+[](const Option &) {
16-
search::tt.clear();
17-
return std::nullopt;
18-
}));
15+
options.add("Clear Hash", Option(+[](const Option &) {
16+
if (searchThread.joinable()) {
17+
std::cout
18+
<< "info string In search, do not modify hash table\n";
19+
return std::nullopt;
20+
}
21+
search::tt.clear();
22+
23+
return std::nullopt;
24+
}));
1925
loop();
20-
}
26+
}

uci.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
using namespace engine;
1212
chess::Position pos;
1313
OptionsMap engine::options;
14+
std::thread searchThread;
1415
void handlePosition(std::istringstream &is) {
16+
if (searchThread.joinable()) {
17+
std::cout << "info string In search, do not modify position\n";
18+
return;
19+
}
1520
std::string token, fen;
1621

1722
is >> token;
@@ -71,7 +76,6 @@ timeman::LimitsType parse_limits(std::istream &is) {
7176

7277
return limits;
7378
}
74-
std::thread searchThread;
7579

7680
void handleGo(std::istringstream &ss) {
7781
if (searchThread.joinable()) {
@@ -198,4 +202,7 @@ void engine::loop() {
198202
}
199203
}
200204
}
205+
search::stop();
206+
if (searchThread.joinable())
207+
searchThread.join();
201208
}

0 commit comments

Comments
 (0)