Skip to content

Commit

Permalink
Add uci.cpp and ucioption.cpp liground-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
mtaktikos authored Feb 16, 2023
1 parent 2986570 commit 91fdc32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/uci.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2022 The Stockfish developers (see AUTHORS file)
Copyright (C) 2004-2023 The Stockfish developers (see AUTHORS file)
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 +22,7 @@
#include <sstream>
#include <string>

#include "benchmark.h"
#include "evaluate.h"
#include "movegen.h"
#include "position.h"
Expand All @@ -35,8 +36,6 @@ using namespace std;

namespace Stockfish {

extern vector<string> setup_bench(const Position&, istream&);

namespace {

// FEN string for the initial position in standard xiangqi
Expand Down Expand Up @@ -160,7 +159,7 @@ namespace {
uint64_t num, nodes = 0, cnt = 1;

vector<string> list = setup_bench(pos, args);
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0 || s.find("eval") == 0; });
num = count_if(list.begin(), list.end(), [](const string& s) { return s.find("go ") == 0 || s.find("eval") == 0; });

TimePoint elapsed = now();

Expand Down Expand Up @@ -358,7 +357,7 @@ string UCI::wdl(Value v, int ply) {
/// UCI::square() converts a Square to a string in algebraic notation (g1, a7, etc.)

std::string UCI::square(Square s) {
if (rank_of(s) < 9)
if (rank_of(s) < 9)
return std::string{ char('a' + file_of(s)), char('1' + rank_of(s)) };
else return std::string{ char('a' + file_of(s)), char('1'), char('0') };
}
Expand Down
35 changes: 19 additions & 16 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2022 The Stockfish developers (see AUTHORS file)
Copyright (C) 2004-2023 The Stockfish developers (see AUTHORS file)
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,19 +33,23 @@ using std::string;
namespace Stockfish {

UCI::OptionsMap Options; // Global object
bool UseRule60 = true;
bool Strict3Fold = false;
bool EnableRule60 = true;
bool StrictThreeFold = false;
uint8_t MateThreatDepth = 1;
bool ChineseRule = false;

namespace UCI {

/// 'On change' actions, triggered by an option's value change
void on_clear_hash(const Option&) { Search::clear(); }
void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
void on_logger(const Option& o) { start_logger(o); }
void on_threads(const Option& o) { Threads.set(size_t(o)); }
void on_rule60(const Option& o) { UseRule60 = bool(o); }
void on_strict3fold(const Option& o) { Strict3Fold = bool(o); }
void on_eval_file(const Option& ) { Eval::NNUE::init(); }
static void on_clear_hash(const Option&) { Search::clear(); }
static void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
static void on_logger(const Option& o) { start_logger(o); }
static void on_threads(const Option& o) { Threads.set(size_t(o)); }
static void on_rule60(const Option& o) { EnableRule60 = bool(o); }
static void on_strict_three_fold(const Option& o) { StrictThreeFold = bool(o); }
static void on_mate_threat_depth(const Option& o) { MateThreatDepth = size_t(o); }
static void on_repetition_rule(const Option& o) { ChineseRule = o == "ChineseRule"; }
static void on_eval_file(const Option& ) { Eval::NNUE::init(); }

/// Our case insensitive less() function as required by UCI protocol
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
Expand All @@ -71,9 +75,10 @@ void init(OptionsMap& o) {
o["Move Overhead"] << Option(10, 0, 5000);
o["Slow Mover"] << Option(100, 10, 1000);
o["nodestime"] << Option(0, 0, 10000);
o["UCI_Chess960"] << Option(false);
o["Rule60"] << Option(true, on_rule60);
o["Strict3Fold"] << Option(false, on_strict3fold);
o["Sixty Move Rule"] << Option(true, on_rule60);
o["Strict Three Fold"] << Option(false, on_strict_three_fold);
o["Mate Threat Depth"] << Option(1, 0, 10, on_mate_threat_depth);
o["Repetition Rule"] << Option("AsianRule var AsianRule var ChineseRule", "AsianRule" , on_repetition_rule);
o["UCI_LimitStrength"] << Option(false);
o["UCI_Elo"] << Option(1350, 1350, 2850);
o["UCI_WDLCentipawn"] << Option(true);
Expand All @@ -97,10 +102,8 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {

if (o.type == "string" || o.type == "check" || o.type == "combo")
os << " default " << o.defaultValue;

if (o.type == "combo")
if (o.type == "combo")
os << " var " << o.currentValue;

if (o.type == "spin")
os << " default " << int(stof(o.defaultValue))
<< " min " << o.min
Expand Down

0 comments on commit 91fdc32

Please sign in to comment.