Skip to content

Commit

Permalink
add OwnBookPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjunSahlot committed Jul 21, 2023
1 parent 5c2c3b6 commit 4b64734
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ int main(const int argc, const char* argv[]) {
} else {
Hash::init();
Eval::init();
Opening::init();

print_info();
return loop();
Expand Down
6 changes: 3 additions & 3 deletions src/opening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <fstream>
#include "hash.hpp"
#include "bitboard.hpp"
#include "options.hpp"
#include "utils.hpp"
#include "random.hpp"

Expand All @@ -37,11 +38,10 @@ using std::getline;


namespace Opening {
const string OPENINGS_FILE = "openings.txt";
vector<string> openings;

void init() {
ifstream openings_file(OPENINGS_FILE);
void load_openings(Options& options) {
ifstream openings_file(options.OwnBookPath);

if (!openings_file.is_open()) {
cerr << "Warning: could not open openings file." << endl;
Expand Down
3 changes: 2 additions & 1 deletion src/opening.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <vector>
#include <string>
#include "bitboard.hpp"
#include "options.hpp"

using std::cin;
using std::cout;
Expand All @@ -31,6 +32,6 @@ using std::vector;
using std::string;

namespace Opening {
void init();
void load_openings(Options&);
vector<string> get_sequence(const string&);
}
1 change: 1 addition & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Options::Options() {
EvalKings = 1;

OwnBook = false;
OwnBookPath = "openings.txt";

hash_table = new Transposition[16];
set_hash();
Expand Down
1 change: 1 addition & 0 deletions src/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ EvalKings: type=spin, default=100, min=0, max=1000, weight (percent) of king eva
float EvalKings;

bool OwnBook;
string OwnBookPath;
};
7 changes: 7 additions & 0 deletions src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ int loop() {
string cmd;
Options options;
Position pos = Bitboard::startpos();
Opening::load_openings(options);
vector<string> move_list = {};
float prev_eval = 0;
bool searching = false;
Expand All @@ -198,6 +199,7 @@ int loop() {
cout << "id author Megalodon Developers\n";

cout << "option name OwnBook type check default false\n";
cout << "option name OwnBookPath type path default 'openings.txt'\n";
cout << "option name Hash type spin default 256 min 1 max 65536\n";

cout << "option name EvalMaterial type spin default 100 min 0 max 1000\n";
Expand Down Expand Up @@ -234,6 +236,11 @@ int loop() {
else std::cerr << "Unknown value: " << value << endl;
}

else if (name == "OwnBookPath") {
options.OwnBookPath = value;
Opening::load_openings(options);
}

else std::cerr << "Unknown option: " << name << endl;
}

Expand Down

0 comments on commit 4b64734

Please sign in to comment.