1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-13 20:49:15 +00:00

Rename execute_uci_command() to uci_loop()

As a side effect now root position can be directly
allocated on the stack and doesn't need to be defined
static anymore.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-07-24 07:56:26 +01:00
parent 5b0c6b9bc0
commit dab1cd8af9
2 changed files with 62 additions and 63 deletions

View file

@ -37,7 +37,7 @@
using namespace std; using namespace std;
extern bool execute_uci_command(const string& cmd); extern void uci_loop();
extern void benchmark(int argc, char* argv[]); extern void benchmark(int argc, char* argv[]);
extern void kpk_bitbase_init(); extern void kpk_bitbase_init();
@ -68,11 +68,8 @@ int main(int argc, char* argv[]) {
if (CpuHasPOPCNT) if (CpuHasPOPCNT)
cout << "Good! CPU has hardware POPCNT." << endl; cout << "Good! CPU has hardware POPCNT." << endl;
// Wait for a command from the user, and passes this command to // Enter the UCI loop waiting for input
// execute_uci_command() and also intercepts EOF from stdin to uci_loop();
// ensure that we exit gracefully if the GUI dies unexpectedly.
string cmd;
while (getline(cin, cmd) && execute_uci_command(cmd)) {}
} }
else if (string(argv[1]) == "bench" && argc < 8) else if (string(argv[1]) == "bench" && argc < 8)
benchmark(argc, argv); benchmark(argc, argv);

View file

@ -35,7 +35,7 @@ using namespace std;
namespace { namespace {
// FEN string for the initial position // FEN string for the initial position
const string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; const char* StarFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
// Keep track of position keys along the setup moves (from start position to the // Keep track of position keys along the setup moves (from start position to the
// position just before to start searching). This is needed by draw detection // position just before to start searching). This is needed by draw detection
@ -49,27 +49,30 @@ namespace {
} }
/// execute_uci_command() takes a string as input, parses this text string as /// Wait for a command from the user, parse this text string as an UCI command,
/// an UCI command, and calls the appropriate functions. In addition to the /// and calls the appropriate functions. Also intercepts EOF from stdin to
/// UCI commands, the function also supports a few debug commands. /// ensure that we exit gracefully if the GUI dies unexpectedly. In addition to
/// the UCI commands, the function also supports a few debug commands.
bool execute_uci_command(const string& cmd) { void uci_loop() {
static Position pos(StartPositionFEN, false, 0); // The root position Position pos(StarFEN, false, 0); // The root position
string cmd, token;
while (getline(cin, cmd))
{
istringstream is(cmd); istringstream is(cmd);
string token;
is >> skipws >> token; is >> skipws >> token;
if (token == "quit") if (token == "quit")
return false; break;
if (token == "go") if (token == "go" && !go(pos, is))
return go(pos, is); break;
if (token == "ucinewgame") if (token == "ucinewgame")
pos.from_fen(StartPositionFEN, false); pos.from_fen(StarFEN, false);
else if (token == "isready") else if (token == "isready")
cout << "readyok" << endl; cout << "readyok" << endl;
@ -107,8 +110,7 @@ bool execute_uci_command(const string& cmd) {
<< "\nuciok" << endl; << "\nuciok" << endl;
else else
cout << "Unknown command: " << cmd << endl; cout << "Unknown command: " << cmd << endl;
}
return true;
} }
@ -128,7 +130,7 @@ namespace {
if (token == "startpos") if (token == "startpos")
{ {
fen = StartPositionFEN; fen = StarFEN;
is >> token; // Consume "moves" token if any is >> token; // Consume "moves" token if any
} }
else if (token == "fen") else if (token == "fen")