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

lc0 (experiment): Create fake history when starting from a fen position with no history #633

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 13 additions & 3 deletions lc0/src/chess/position.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ GameResult PositionHistory::ComputeGameResult() const {
}

void PositionHistory::Reset(const ChessBoard& board, int no_capture_ply,
int game_ply) {
int game_ply,bool clone_history) {
positions_.clear();
positions_.emplace_back(board, no_capture_ply, game_ply);
if(clone_history){
ChessBoard mirrored = board;
mirrored.Mirror();
for(int i=0; i<4;i++)
positions_.emplace_back(board, no_capture_ply, game_ply);
positions_.push_back(positions_.back());
positions_.emplace_back(mirrored, no_capture_ply, game_ply);
positions_.push_back(positions_.back());
}
positions_.emplace_back(board, no_capture_ply, game_ply);

}

void PositionHistory::Append(Move m) {
Expand Down Expand Up @@ -119,4 +129,4 @@ uint64_t PositionHistory::HashLast(int positions) const {
return HashCat(hash, Last().GetNoCapturePly());
}

} // namespace lczero
} // namespace lczero
4 changes: 2 additions & 2 deletions lc0/src/chess/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PositionHistory {
int GetLength() const { return positions_.size(); }

// Resets the position to a given state.
void Reset(const ChessBoard& board, int no_capture_ply, int game_ply);
void Reset(const ChessBoard& board, int no_capture_ply, int game_ply, bool clone_history);

// Appends a position to history.
void Append(Move m);
Expand All @@ -120,4 +120,4 @@ class PositionHistory {
std::vector<Position> positions_;
};

} // namespace lczero
} // namespace lczero
5 changes: 3 additions & 2 deletions lc0/src/mcts/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ void NodeTree::ResetToPosition(const std::string& starting_fen,
}

history_.Reset(starting_board, no_capture_ply,
full_moves * 2 - (starting_board.flipped() ? 1 : 2));
full_moves * 2 - (starting_board.flipped() ? 1 : 2),
ChessBoard::kStartingFen != starting_fen);

Node* old_head = current_head_;
current_head_ = gamebegin_node_;
Expand All @@ -382,4 +383,4 @@ void NodeTree::DeallocateTree() {
current_head_ = nullptr;
}

} // namespace lczero
} // namespace lczero