Skip to content

Commit

Permalink
- makebook peta_shockコマンドで、エンジンオプションのFlippedBookがtrueの時は、先手番の局面しか書き出さ…
Browse files Browse the repository at this point in the history
…ないようにした。

  - 後手番の局面はそれをflipした局面が書き出されているので、実際に使う時にFlippedBookをtrueにしておけば、後手番は、反転された先手の局面にhitするはずだから。
  • Loading branch information
yaneurao committed Jul 4, 2023
1 parent a0b329f commit 3996216
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions source/book/makebook2023.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// makebook petashock book1.db user_book1.db
//
// book1.dbをmin-max探索してuser_book1.dbを書き出す。
//
// エンジンオプションのFlippedBookがtrueなら、先手番の局面しか書き出さない。(後手番の局面はそれをflipした局面が書き出されているはずだから)
//

#include <sstream>
Expand Down Expand Up @@ -372,6 +374,11 @@ namespace MakeBook2023
cout << "draw_value_black : " << draw_value(REPETITION_DRAW, BLACK) << endl;
cout << "draw_value_white : " << draw_value(REPETITION_DRAW, WHITE) << endl;

// 反転された局面を書き出すのか。(FlippedBookがtrueなら書き出さない)
// すなわち、後手番の局面はすべて書き出さない。(反転された先手番の局面を書き出しているはずだから)
bool flipped_book = Options["FlippedBook"];
cout << "FlippedBook : " << flipped_book << endl;

cout << endl;

// 手数無視のオプションを有効にすると、MemoryBook::read_book()は、
Expand Down Expand Up @@ -1162,6 +1169,10 @@ namespace MakeBook2023
auto& index = sfen_index.second;
auto& book_node = book_nodes[index];

// FlippedBookがtrueなら、後手番の局面は書き出さない。
if (flipped_book && book_node.color == WHITE)
continue;

Book::BookMoves bookMoves;
for(auto& move : book_node.moves)
{
Expand All @@ -1173,6 +1184,8 @@ namespace MakeBook2023

progress.check(++counter);
}
progress.check(sfen_to_index.size());

// 定跡ファイルの書き出し
new_book.write_book(writebook_path);
write_counter = new_book.size();
Expand Down
8 changes: 8 additions & 0 deletions source/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ const std::string Position::flipped_sfen(int gamePly_) const
return ss.str();
}

// sfen文字列を先後反転したsfen文字列に変換する。
const std::string Position::sfen_to_flipped_sfen(std::string sfen)
{
Position pos;
StateInfo si;
pos.set(sfen,&si,Threads.main());
return pos.flipped_sfen();
}

void Position::set_state(StateInfo* si) const {

Expand Down
3 changes: 3 additions & 0 deletions source/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ class Position
const std::string flipped_sfen() const { return flipped_sfen(game_ply()); }
const std::string flipped_sfen(int gamePly) const;

// sfen文字列を先後反転したsfen文字列に変換する。
static const std::string sfen_to_flipped_sfen(std::string sfen);

// 平手の初期盤面を設定する。
// siについては、上記のset()にある説明を読むこと。
void set_hirate(StateInfo*si,Thread* th) { set(SFEN_HIRATE,si,th); }
Expand Down

0 comments on commit 3996216

Please sign in to comment.