Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tommadams committed Feb 22, 2019
1 parent 2e90718 commit c7fa4da
Show file tree
Hide file tree
Showing 30 changed files with 250 additions and 100 deletions.
17 changes: 17 additions & 0 deletions cc/BUILD
Expand Up @@ -142,6 +142,7 @@ minigo_cc_library(
deps = [
":base",
":game",
":logging",
":sgf",
"//cc/file",
"//cc/platform",
Expand All @@ -156,12 +157,15 @@ minigo_cc_library(
hdrs = ["gtp_player.h"],
deps = [
":base",
":logging",
":mcts",
":sgf",
"//cc:thread_safe_queue",
"//cc/dual_net",
"//cc/file",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:span",
],
)
Expand Down Expand Up @@ -204,13 +208,16 @@ minigo_cc_library(
deps = [
":base",
":gtp_player",
":logging",
":mcts",
":sgf",
":thread_safe_queue",
"//cc/dual_net",
"//cc/file",
"@com_github_nlohmann_json//:json",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:span",
],
Expand Down Expand Up @@ -277,10 +284,12 @@ minigo_cc_library(
deps = [
":base",
":logging",
"//cc/platform",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:span",
],
)

Expand Down Expand Up @@ -394,6 +403,7 @@ minigo_cc_test_9_only(
deps = [
":base",
":mcts",
":position",
":test_utils",
":zobrist",
"//cc/dual_net:fake_dual_net",
Expand Down Expand Up @@ -470,6 +480,7 @@ minigo_cc_binary(
visibility = ["//visibility:public"],
deps = [
":base",
":game",
":game_utils",
":init",
":logging",
Expand All @@ -483,6 +494,7 @@ minigo_cc_binary(
"@com_github_gflags_gflags//:gflags",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
],
)
Expand All @@ -500,8 +512,10 @@ minigo_cc_binary(
"//cc/dual_net:factory",
"//cc/file",
"@com_github_gflags_gflags//:gflags",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
],
)

Expand All @@ -523,6 +537,7 @@ minigo_cc_binary(
"@com_github_gflags_gflags//:gflags",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
Expand All @@ -534,6 +549,7 @@ minigo_cc_binary(
visibility = ["//visibility:public"],
deps = [
":base",
":game",
":game_utils",
":init",
":logging",
Expand Down Expand Up @@ -566,6 +582,7 @@ minigo_cc_binary(
":mcts",
":random",
":zobrist",
"//cc:game",
"//cc/dual_net:factory",
"//cc/platform",
"@com_github_gflags_gflags//:gflags",
Expand Down
4 changes: 4 additions & 0 deletions cc/dual_net/BUILD
Expand Up @@ -203,6 +203,7 @@ minigo_cc_test(
srcs = ["batching_dual_net_test.cc"],
deps = [
":batching_dual_net",
":dual_net",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/synchronization",
Expand Down Expand Up @@ -233,6 +234,8 @@ minigo_cc_test_9_only(
":factory",
"//cc:logging",
"//cc:position",
"//cc:random",
"//cc:symmetries",
"//cc:test_utils",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -243,6 +246,7 @@ minigo_cc_test(
srcs = ["inference_cache_test.cc"],
deps = [
":inference_cache",
"//cc:random",
"@com_google_googletest//:gtest_main",
],
)
3 changes: 1 addition & 2 deletions cc/eval.cc
Expand Up @@ -194,8 +194,7 @@ class Evaluator {
auto* curr_player = black.get();
auto* next_player = white.get();
batcher->StartGame(curr_player->network(), next_player->network());
while (!curr_player->root()->game_over() &&
!curr_player->root()->at_move_limit()) {
while (!game.game_over() && !curr_player->root()->at_move_limit()) {
auto move = curr_player->SuggestMove();
if (verbose) {
std::cerr << curr_player->root()->Describe() << "\n";
Expand Down
11 changes: 10 additions & 1 deletion cc/file/BUILD
Expand Up @@ -45,7 +45,15 @@ cc_library(

cc_library(
name = "file",
deps = [":path"] + select({
hdrs = [
"path.h",
"utils.h",
],
deps = [
":path",
"//cc/platform",
"@com_google_absl//absl/strings",
] + select({
"//cc/config:enable_tf": [":utils_tf"],
"//conditions:default": [":utils_no_tf"],
}),
Expand All @@ -66,6 +74,7 @@ cc_test(
deps = [
":file",
"//cc:base",
"//cc:logging",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
],
Expand Down
2 changes: 1 addition & 1 deletion cc/gtp_player.cc
Expand Up @@ -297,7 +297,7 @@ GtpPlayer::Response GtpPlayer::HandleFinalScore(CmdArgs args) {
if (!response.ok) {
return response;
}
if (!root()->game_over()) {
if (!game_.game_over()) {
// Game isn't over yet, calculate the current score using Tromp-Taylor
// scoring.
return Response::Ok(Game::FormatScore(
Expand Down
2 changes: 2 additions & 0 deletions cc/mcts_node.cc
Expand Up @@ -82,6 +82,8 @@ MctsNode::MctsNode(MctsNode* parent, Coord move)
stats(&parent->edges[move]),
move(move),
position(parent->position) {
MG_DCHECK(move >= 0);
MG_DCHECK(move < kNumMoves);
position.PlayMove(move);

// Insert a cache of ancestor Zobrist hashes at regular depths in the tree.
Expand Down
3 changes: 1 addition & 2 deletions cc/mcts_player.cc
Expand Up @@ -266,9 +266,8 @@ bool MctsPlayer::PlayMove(Coord c, Game* game) {

// Handle resignations.
if (c == Coord::kResign) {
root_ = root_->MaybeAddChild(c);
if (game != nullptr) {
game->SetGameOverBecauseOfResign(root_->position.to_play());
game->SetGameOverBecauseOfResign(OtherColor(root_->position.to_play()));
}
return true;
}
Expand Down
5 changes: 3 additions & 2 deletions cc/selfplay.cc
Expand Up @@ -67,7 +67,8 @@ DEFINE_bool(inject_noise, true,
"If true, inject noise into the root position at the start of "
"each tree search.");
DEFINE_double(noise_mix, 0.25,
"If inject_noise is true, the amount of noise to mix into the root.");
"If inject_noise is true, the amount of noise to mix into the "
"root.");
DEFINE_bool(soft_pick, true,
"If true, choose moves early in the game with a probability "
"proportional to the number of times visited during tree search. "
Expand Down Expand Up @@ -296,7 +297,7 @@ class SelfPlayer {
absl::MutexLock lock(&mutex_);
batcher_->StartGame(player->network(), player->network());
}
while (!player->root()->game_over() && !player->root()->at_move_limit()) {
while (!game->game_over() && !player->root()->at_move_limit()) {
auto move = player->SuggestMove();
if (player->options().verbose) {
const auto& position = player->root()->position;
Expand Down
2 changes: 1 addition & 1 deletion cc/simple_example.cc
Expand Up @@ -59,7 +59,7 @@ void SimpleExample() {
Game game(player.name(), player.name(), options.game_options);

// Play the game.
while (!player.root()->game_over() && !player.root()->at_move_limit()) {
while (!game.game_over() && !player.root()->at_move_limit()) {
auto move = player.SuggestMove();

const auto& position = player.root()->position;
Expand Down
3 changes: 1 addition & 2 deletions cc/tf_utils_dummy.cc
Expand Up @@ -20,8 +20,7 @@ namespace minigo {
namespace tf_utils {

void WriteGameExamples(const std::string& output_dir,
const std::string& output_name,
const MctsPlayer& player) {
const std::string& output_name, const Game& game) {
MG_LOG(FATAL)
<< "Can't write TensorFlow examples without TensorFlow support enabled. "
"Please recompile, passing --define=tf=1 to bazel build.";
Expand Down
28 changes: 18 additions & 10 deletions minigui/app.ts
Expand Up @@ -34,12 +34,15 @@ abstract class App {

protected positionMap = new Map<string, Position>();

protected abstract onGameOver(): void;

protected abstract onPositionUpdate(position: Position, update: Position.Update): void;

protected abstract onNewPosition(position: Position): void;

// We track game over state separately from the gameOver property of the
// latest position because when one player resigns, the game ends without a
// new Position with gameOver == true being generated.
protected gameOver = false;

constructor() {
this.gtp.onData('mg-update', (j: Position.Update) => {
let position = this.positionMap.get(j.id);
Expand All @@ -58,8 +61,12 @@ abstract class App {
let def = j as Position.Definition;
if (def.move == null) {
// No parent, this must be the root.
let p = this.positionMap.get(def.id);
if (p == null) {
p = new Position(def);
this.rootPosition = p;
}
position = this.rootPosition;
position.id = def.id;
} else {
// Get the parent.
if (def.parentId === undefined) {
Expand All @@ -81,13 +88,14 @@ abstract class App {
}
position.update(j);
this.onNewPosition(position);
if (position.gameOver) {
this.onGameOver();
}
this.positionMap.set(position.id, position);
});
}

protected onGameOver() {
this.gameOver = true;
}

protected connect() {
let uri = `http://${document.domain}:${location.port}/minigui`;
let params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -117,14 +125,12 @@ abstract class App {
});
}

protected newGame() {
protected newGame(): Promise<any> {
this.gameOver = false;
this.positionMap.clear();
this.rootPosition.children = [];
this.activePosition = this.rootPosition;

this.gtp.send('clear_board');
this.gtp.send('info');

// TODO(tommadams): Move this functionality into .ctl files.
// Iterate over the data-* attributes attached to the main minigui container
// element, looking for data-gtp-* attributes. Send any matching ones as GTP
Expand All @@ -140,6 +146,8 @@ abstract class App {
}
}
}

return this.gtp.send('clear_board');
}
}

Expand Down
2 changes: 1 addition & 1 deletion minigui/control/minigo_tf.ctl
Expand Up @@ -9,7 +9,7 @@ players = {
" --value_init_penalty=0"
" --courtesy_pass=true"
" --virtual_losses=8"
" --resign_threshold=-0.8",
" --resign_threshold=-0.3",
startup_gtp_commands=[
"report_search_interval 100",
]),
Expand Down

0 comments on commit c7fa4da

Please sign in to comment.