Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cc/gtp_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ void GtpClient::Ponder() {

GtpClient::Response GtpClient::ReplaySgf(
const std::vector<std::unique_ptr<sgf::Node>>& trees) {

if (!trees.empty()) {
// the SGF parser takes care of transforming an sgf into moves that the
// engine is able to understand, so all we do here is just play them in.
for (const auto& move : trees[0]->ExtractMainLine()) {
if (!player_->PlayMove(move.c)) {
MG_LOG(ERROR) << "couldn't play move " << move.c;
return Response::Error("cannot load file");
MG_LOG(ERROR) << "Couldn't play move " << move.c;
return Response::Error("Cannot load file");
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions cc/sgf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ bool GetTreeImpl(const Ast::Tree& tree,
std::vector<std::unique_ptr<Node>>* dst) {
const auto* src = &tree;
const Ast::Property* prop;
const Ast::Property* stones;

// Extract all the nodes out of this tree.
for (const auto& node : src->nodes) {
Expand All @@ -219,6 +220,43 @@ bool GetTreeImpl(const Ast::Tree& tree,
move.color = Color::kBlack;
} else if ((prop = node.FindProperty("W")) != nullptr) {
move.color = Color::kWhite;
} else if ((prop = node.FindProperty("HA")) != nullptr) {
int handicap;
bool valid_handicap = absl::SimpleAtoi(prop->values[0], &handicap);
if (!valid_handicap) {
MG_LOG(ERROR) << "Invalid handicap property: " << prop->values[0];
break;
}

if ((handicap <= 1) || (handicap > 9)) {
MG_LOG(ERROR) << "Invalid handicap value:" << handicap;
return false;
}
stones = node.FindProperty("AB");
if (stones == nullptr) {
MG_LOG(ERROR) << "Handicap stones not specified.";
return false;
}

for (const auto& h_location : stones->values) {
Move m;
m.color = Color::kBlack;
m.c = Coord::FromSgf(h_location, true);
if (m.c == Coord::kInvalid) {
MG_LOG(ERROR) << "Can't parse node " << node.ToString() << ": \""
<< h_location << "\" isn't a valid SGF coord for a handicap stone";
return false;
}
dst->push_back(absl::make_unique<Node>(m, ""));
dst = &(dst->back()->children);
if (h_location != stones->values.back()) {
m.color = Color::kWhite;
m.c = Coord::kPass;
dst->push_back(absl::make_unique<Node>(m, ""));
dst = &(dst->back()->children);
}
}
continue;
} else {
continue;
}
Expand Down