Skip to content

Commit

Permalink
Windows版の不具合をいくつか修正
Browse files Browse the repository at this point in the history
  • Loading branch information
gikou-official committed Jun 5, 2016
1 parent 906ed81 commit f30b1e8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 27 deletions.
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ LIBRARIES = -lpthread
#
# 2. Target Specific Settings
#
ifeq ($(TARGET),gikou) # executable for Windows
ifeq ($(TARGET),gikou) # Windowsの実行ファイル
sources := $(shell ls src/*.cc)
CXXFLAGS += -O3 -DNDEBUG -DMINIMUM -static
CXXFLAGS += -O3 -DNDEBUG -DMINIMUM -DPSEUDO_RANDOM_DEVICE -static
endif
ifeq ($(TARGET),release)
ifeq ($(TARGET),release) # Mac / Linuxの実行ファイル
sources := $(shell ls src/*.cc)
CXXFLAGS += -O3 -DNDEBUG
endif
ifeq ($(TARGET),cluster)
ifeq ($(TARGET),cluster) # 疎結合並列探索のマスター側(デバッグ用、assertマクロON)
sources := $(shell ls src/*.cc)
CXXFLAGS += -O3 -DCLUSTER
endif
ifeq ($(TARGET),consultation)
ifeq ($(TARGET),consultation) # 合議アルゴリズムのマスター側(デバッグ用、assertマクロON)
sources := $(shell ls src/*.cc)
CXXFLAGS += -O3 -DCONSULTATION
endif
ifeq ($(TARGET),development)
ifeq ($(TARGET),development) # 開発用・デバッグ用
sources := $(shell ls src/*.cc)
CXXFLAGS += -O2 -g3
endif
ifeq ($(TARGET),profile)
ifeq ($(TARGET),profile) # プロファイル用
sources := $(shell ls src/*.cc)
CXXFLAGS += -O3 -DNDEBUG -pg
endif
ifeq ($(TARGET),test)
ifeq ($(TARGET),test) # ユニットテスト用(Google Testを利用)
sources := $(shell ls src/*.cc test/*.cc test/common/*.cc)
sources += lib/gtest-1.7.0/fused-src/gtest/gtest-all.cc
CXXFLAGS += -g3 -Og -DUNIT_TEST
INCLUDES += -Isrc -Ilib/gtest-1.7.0/fused-src
endif
ifeq ($(TARGET),coverage)
ifeq ($(TARGET),coverage) # カバレッジテスト用(Google Testを利用)
sources := $(shell ls src/*.cc test/*.cc test/common/*.cc)
sources += lib/gtest-1.7.0/fused-src/gtest/gtest-all.cc
CXXFLAGS += -g3 -DUNIT_TEST -ftest-coverage -fprofile-arcs
Expand Down
27 changes: 19 additions & 8 deletions src/book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cstdio>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <fstream>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -131,8 +132,15 @@ Move BookMoves::PickRandom() const {
}

// 4. 候補手が複数存在する場合は、その重要度に応じて、ランダムに定跡手を選択する
#ifdef PSEUDO_RANDOM_DEVICE
// random_deviceの代わりに、現在時刻を用いて乱数生成器を初期化する
// (特定の環境では、std::random_deviceが非決定的乱数を返さないがあるため)
// 参考: http://en.cppreference.com/w/cpp/numeric/random/random_device
static std::mt19937 gen(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#else
static std::random_device rd;
static std::mt19937 gen(rd());
#endif
std::uniform_int_distribution<int64_t> dis(0, sum_importance);
int64_t threashold = dis(gen);
for (const CandidateMove& candidate : candidates) {
Expand Down Expand Up @@ -296,27 +304,30 @@ Move Book::GetOneBookMove(const Position& pos, const UsiOptions& usi_options) co
// 定跡手の中からランダムに1手選ぶ
const Move book_move = book_moves.PickRandom();

// 定跡手を評価値が良い順にソートする
// 定跡手を評価値が低い順にソートする(「将棋所」で、評価値の高い手を上に表示するため)
std::sort(book_moves.begin(), book_moves.end(), [](const BookMove& lhs, const BookMove& rhs) {
return lhs.score == rhs.score
? (lhs.importance > rhs.importance)
: lhs.score > rhs.score;
? (lhs.importance < rhs.importance)
: lhs.score < rhs.score;
});

// 定跡データについての情報を出力する
int multipv = 0;
int multipv = std::count_if(book_moves.begin(), book_moves.end(), [&](const BookMove& bm) {
return bm.importance > 0;
});
int book_move_number = 0;
for (const BookMove& bm : book_moves) {
if (bm.importance > 0) {
SYNCED_PRINTF("info time 0 depth %d nodes %d score cp %d multipv %d pv %s\n",
kBookSearchDepth / kOnePly,
int(bm.win_count),
int(bm.score),
++multipv,
multipv,
bm.move.ToSfen().c_str());
}
if (bm.move == book_move) {
book_move_number = multipv;
if (bm.move == book_move) {
book_move_number = multipv;
}
multipv--;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/psq.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define PSQ_H_

#include <cstdlib>
#include <tmmintrin.h> // SSSE 3
#include "common/array.h"
#include "common/arraymap.h"
#include "common/sequence.h"
Expand Down
7 changes: 1 addition & 6 deletions src/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ void Search::IterativeDeepening(Node& node, ThreadManager& thread_manager) {
// 現在までに探索した指し手をソートする
std::stable_sort(root_moves_.begin(), root_moves_.begin() + pv_index_ + 1,
std::greater<RootMove>());

// ワーカースレッドは、マルチPV探索を行わない
if (!is_master_thread()) {
break;
}
}

assert(score != kScoreNone);
Expand Down Expand Up @@ -1204,7 +1199,7 @@ void Search::SendUsiInfo(const Node& node, int depth, int64_t time,
std::string buf;

// マルチPVのループ
for (int pv_index = 0; pv_index < multipv_; ++pv_index) {
for (int pv_index = multipv_ - 1; pv_index >= 0; --pv_index) {
Score score = root_moves_.at(pv_index).score;

// 1. 評価値とPV以外
Expand Down
4 changes: 4 additions & 0 deletions src/time_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ FixedTimeControl::FixedTimeControl(const Position& position,
: TimeControl(position, go_options, usi_options) {
// 常に固定された時間だけ考える
fixed_time_ = time_per_move() - usi_options["ByoyomiMargin"];
fixed_time_ = std::max(fixed_time_, INT64_C(10)); // 不具合を避けるため、思考時間を10ミリ秒未満にしない
}

DynamicTimeControl::DynamicTimeControl(const Position& position,
Expand Down Expand Up @@ -115,6 +116,7 @@ FischerTimeControl::FischerTimeControl(const Position& position,
// 最小思考時間
int64_t min_thinking_time = usi_options_["MinThinkingTime"];
minimum_time_ = std::max(base_time_ / kMinRatio, min_thinking_time) - byoyomi_margin_;
minimum_time_ = std::max(minimum_time_, INT64_C(10)); // 不具合を避けるため、最小思考時間を10ミリ秒未満にしない

SYNCED_PRINTF("info string Time Control: base=%" PRIu64 " max=%" PRIu64 " min=%" PRIu64 "\n",
base_time_, maximum_time_, minimum_time_);
Expand All @@ -139,6 +141,7 @@ ByoyomiTimeControl::ByoyomiTimeControl(const Position& position,
// 最小思考時間
int64_t min_thinking_time = usi_options_["MinThinkingTime"];
minimum_time_ = std::max(base_time_ / kMinRatio, min_thinking_time) - byoyomi_margin_;
minimum_time_ = std::max(minimum_time_, INT64_C(10)); // 不具合を避けるため、最小思考時間を10ミリ秒未満にしない

SYNCED_PRINTF("info string Time Control: base=%" PRIu64 " max=%" PRIu64 " min=%" PRIu64 "\n",
base_time_, maximum_time_, minimum_time_);
Expand All @@ -164,6 +167,7 @@ SuddenDeathTimeControl::SuddenDeathTimeControl(const Position& position,
// 最小思考時間
int64_t min_thinking_time = usi_options_["MinThinkingTime"];
minimum_time_ = std::max(base_time_ / kMinRatio, min_thinking_time) - byoyomi_margin_;
minimum_time_ = std::max(minimum_time_, INT64_C(10)); // 不具合を避けるため、最小思考時間を10ミリ秒未満にしない

SYNCED_PRINTF("info string Time Control: base=%" PRIu64 " max=%" PRIu64 " min=%" PRIu64 "\n",
base_time_, maximum_time_, minimum_time_);
Expand Down
6 changes: 3 additions & 3 deletions src/usi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

namespace {

const auto kProgramName = "Gikou 20160601";
const auto kProgramName = "Gikou 20160606";
const auto kAuthorName = "Yosuke Demura";
const auto kBookFile = "book.bin";

Expand Down Expand Up @@ -306,7 +306,7 @@ UsiOptions::UsiOptions() {
map_.emplace("DrawScore", UsiOption(0, -200, 200));

// 秒読み時の安全マージン(単位はミリ秒)
map_.emplace("ByoyomiMargin", UsiOption(0, 0, 10000));
map_.emplace("ByoyomiMargin", UsiOption(100, 0, 10000));

// フィッシャールール時の安全マージン(単位はミリ秒)
map_.emplace("FischerMargin", UsiOption(12000, 0, 60000));
Expand All @@ -315,7 +315,7 @@ UsiOptions::UsiOptions() {
map_.emplace("SuddenDeathMargin", UsiOption(60, 0, 600));

// 最小思考時間(実際には、ここから安全マージンを引いた時間だけ思考する)(単位はミリ秒)
map_.emplace("MinThinkingTime", UsiOption(1000, 1, 60000));
map_.emplace("MinThinkingTime", UsiOption(1000, 10, 60000));

// 定跡を使うか否か(trueならば、定跡を用いる)
map_.emplace("OwnBook", UsiOption(true));
Expand Down
2 changes: 1 addition & 1 deletion src/usi.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class UsiOption {
* @param max USIオプションの最大値
*/
UsiOption(int default_value, int min, int max)
: value_(default_value),
: value_(std::min(std::max(default_value, min), max)),
default_value_(default_value),
min_(min),
max_(max),
Expand Down

0 comments on commit f30b1e8

Please sign in to comment.