Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault when using the match option "extraPairs" #777

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 33 additions & 2 deletions cpp/command/match.cpp
Expand Up @@ -80,6 +80,37 @@ int MainCmds::match(const vector<string>& args) {
}
}

vector<bool> extraPairsBot(numBots);
// But flag if the bot is not to be part of normal matchmaking, but needs to
// be loaded anyway.
if (cfg.contains("extraPairs")) {
string pairsStr = cfg.getString("extraPairs");
std::vector<string> pairStrs = Global::split(pairsStr,',');
for(const string& pairStr: pairStrs) {
if(Global::trim(pairStr).size() <= 0)
continue;
std::vector<string> pieces = Global::split(Global::trim(pairStr),'-');
if(pieces.size() != 2) {
throw IOError("Could not parse pair: " + pairStr);
}
bool suc;
int p0;
int p1;
suc = Global::tryStringToInt(pieces[0],p0);
if(!suc)
throw IOError("Could not parse pair: " + pairStr);
suc = Global::tryStringToInt(pieces[1],p1);
if(!suc)
throw IOError("Could not parse pair: " + pairStr);
if(p0 < 0 || p0 >= numBots)
throw IOError("Invalid player index in pair: " + pairStr);
if(p1 < 0 || p1 >= numBots)
throw IOError("Invalid player index in pair: " + pairStr);
extraPairsBot[p0] = true;
extraPairsBot[p1] = true;
}
}

//Load the names of the bots and which model each bot is using
vector<string> nnModelFilesByBot(numBots);
vector<string> botNames(numBots);
Expand All @@ -103,7 +134,7 @@ int MainCmds::match(const vector<string>& args) {
vector<string> nnModelFiles;
vector<int> whichNNModel(numBots);
for(int i = 0; i<numBots; i++) {
if(excludeBot[i])
if(excludeBot[i] && !extraPairsBot[i])
continue;

const string& desiredFile = nnModelFilesByBot[i];
Expand Down Expand Up @@ -165,7 +196,7 @@ int MainCmds::match(const vector<string>& args) {

vector<NNEvaluator*> nnEvalsByBot(numBots);
for(int i = 0; i<numBots; i++) {
if(excludeBot[i])
if(excludeBot[i] && !extraPairsBot[i])
continue;
nnEvalsByBot[i] = nnEvals[whichNNModel[i]];
}
Expand Down