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

Pr700 pr750 #788

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
54a199a
Efficient and informative depth computation.
Videodr0me Aug 12, 2018
b6c88dc
Update comments and replace tabs with spaces
Videodr0me Aug 13, 2018
db3b419
Merge remote-tracking branch 'upstream/master'
Videodr0me Oct 17, 2018
fbebb38
Merge remote-tracking branch 'upstream/master'
Videodr0me Oct 17, 2018
891ef72
Certainty Propagation
Videodr0me Nov 3, 2018
5f8aff0
Fixes compiler warnings/errors on -pedantic.
Videodr0me Nov 3, 2018
c664fb5
Resolve merge conflicts
Videodr0me Nov 4, 2018
560e413
Resolve Merge Conflicts 2
Videodr0me Nov 4, 2018
4078af0
Merge: unexpected behaviour when go infinite fixed
Videodr0me Nov 4, 2018
4fb5522
Speed fix. Reading non-cached parameters was slow. Now using cached v…
Videodr0me Nov 4, 2018
84113e5
Speed fix. Used reserve in pseudo legal move generation. If compiled …
Videodr0me Nov 5, 2018
aa266eb
Fix for CP=2, CP=2 (default for play) is now more conservative and ad…
Videodr0me Nov 6, 2018
f087312
Bugfixes, codecleanup minor changes:
Videodr0me Dec 1, 2018
fdbe61a
Rename ClearEdge
Videodr0me Dec 1, 2018
ffee98f
change build-cuda to latest
Videodr0me Dec 2, 2018
4920e74
use optional info.mate to display mate scores
Videodr0me Dec 3, 2018
5e726b4
display 0.00 for tablebase draws when syzygy filtered
Videodr0me Dec 4, 2018
aba68a7
Finalize this WIP PR:
Videodr0me Dec 9, 2018
fec72f0
merge with master
Videodr0me Dec 9, 2018
2a47958
Merge remote-tracking branch 'upstream/master'
Videodr0me Dec 14, 2018
2c7e465
Merge remote-tracking branch 'upstream/master'
Videodr0me Dec 14, 2018
b7379f4
Merge branch 'certainty-propagation-negabound'
Videodr0me Jan 18, 2019
1b7ac55
merge with master
Videodr0me Jan 18, 2019
9f21d9d
Prefer terminal wins over certain wins, to avoid delaying mate. Pref…
Videodr0me Jan 26, 2019
27bdf3a
update to master
Videodr0me Jan 26, 2019
5343415
basic certainty propagation - part 2 of PR 487
Videodr0me Jan 26, 2019
57b8675
IsTerminal should not go to NN
MelleKoning Jan 27, 2019
f503c15
fix off by one mate count
Videodr0me Jan 27, 2019
cf07352
Merge pull request #2 from Videodr0me/basic-certainty-propagation
MelleKoning Jan 29, 2019
5c45b1a
Encompass gameResult and trigger
MelleKoning Jan 29, 2019
01bb096
Make Two Fold Draw Scoring optional to make everybody happy
Videodr0me Jan 29, 2019
fc292d8
Merge branch 'VidDrome-basic-certainty-propagation' into basic-certai…
MelleKoning Jan 29, 2019
ef963f2
Certain is already Terminal checked
MelleKoning Jan 30, 2019
2f63b78
fixed typos, comments and formatting
Videodr0me Jan 31, 2019
0a7cfa5
fixed more typos and renamed GetCertaintyStatus to GetCertaintyState
Videodr0me Feb 1, 2019
2ada0a0
Merge branch 'VidDrome-basic-certainty-propagation' into basic-certai…
MelleKoning Feb 3, 2019
e5c4a02
ignore .gitignore
Videodr0me Feb 9, 2019
4919472
Cosmetic update and comment update.
Videodr0me Feb 9, 2019
6395f5b
merge to master
Videodr0me Feb 9, 2019
35df42f
fix .gitignore
Videodr0me Feb 10, 2019
d3350ca
remove redundant checks and code formatting
Videodr0me Feb 10, 2019
c5824b0
certain moves without children are reset (n_ = 0), only correct root …
Videodr0me Feb 11, 2019
64dcec3
Streamline node Q getter (now as fast as master - works with PR487!),…
Videodr0me Feb 21, 2019
823db45
Merge branch 'master' into basic-certainty-propagation
Videodr0me Feb 23, 2019
31bc393
merge with master
Videodr0me Feb 23, 2019
1e40525
merge with master2
Videodr0me Feb 23, 2019
f0f8948
Add EarlyRootWidening to explore wider initially like AlphaZero
Mardak Feb 25, 2019
d6cfd84
Replace parameter by reference in EvalPosition. Use CertaintyRessult …
Videodr0me Feb 27, 2019
4108a55
Merge branch 'fpu1-root' into PR700PR750
MelleKoning Mar 6, 2019
4928d2a
Merge branch 'master' into PR700PR750
MelleKoning Mar 8, 2019
5827db8
Merge branch 'master' into VidDrome-basic-certainty-propagation
MelleKoning Mar 9, 2019
dc20921
Merge remote-tracking branch 'MelleKoning/basic-certainty-propagation…
MelleKoning Mar 9, 2019
4d69b77
fix gameResult typos
MelleKoning Mar 9, 2019
7afdc7b
Merge branch 'master' into PR700PR750
MelleKoning Mar 9, 2019
7fa4e85
Merge branch 'VidDrome-basic-certainty-propagation' into PR700PR750
MelleKoning Mar 9, 2019
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
2 changes: 2 additions & 0 deletions src/chess/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct ThinkingInfo {
int hashfull = -1;
// Win in centipawns.
optional<int> score;
// Distance to mate.
optional<int> mate;
// Number of successful TB probes (not the same as playouts ending in TB hit).
int tb_hits = -1;
// Best line found. Moves are from perspective of white player.
Expand Down
7 changes: 7 additions & 0 deletions src/chess/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class Position {
};

enum class GameResult { UNDECIDED, WHITE_WON, DRAW, BLACK_WON };
enum class CertaintyTrigger { NONE, TB_HIT, TWO_FOLD, TERMINAL, NORMAL };

struct CertaintyResult {
public:
GameResult gameResult;
CertaintyTrigger trigger;
};

class PositionHistory {
public:
Expand Down
8 changes: 7 additions & 1 deletion src/chess/uciloop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ void UciLoop::SendInfo(const std::vector<ThinkingInfo>& infos) {
if (info.seldepth >= 0) res += " seldepth " + std::to_string(info.seldepth);
if (info.time >= 0) res += " time " + std::to_string(info.time);
if (info.nodes >= 0) res += " nodes " + std::to_string(info.nodes);
if (info.score) res += " score cp " + std::to_string(*info.score);

// If mate display mate, otherwise if score display score.
if (info.mate) {
res += " score mate " + std::to_string(*info.mate);
} else if (info.score) {
res += " score cp " + std::to_string(*info.score);
}
if (info.hashfull >= 0) res += " hashfull " + std::to_string(info.hashfull);
if (info.nps >= 0) res += " nps " + std::to_string(info.nps);
if (info.tb_hits >= 0) res += " tbhits " + std::to_string(info.tb_hits);
Expand Down
1 change: 1 addition & 0 deletions src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void EngineController::Go(const GoParams& params) {
if (info.multipv <= 1) {
ponder_info = info;
if (ponder_info.score) ponder_info.score = -*ponder_info.score;
if (ponder_info.mate) ponder_info.mate = -*ponder_info.mate;
if (ponder_info.depth > 1) ponder_info.depth--;
if (ponder_info.seldepth > 1) ponder_info.seldepth--;
ponder_info.pv.clear();
Expand Down
126 changes: 102 additions & 24 deletions src/mcts/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "mcts/node.h"

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
Expand Down Expand Up @@ -160,9 +161,58 @@ float Edge::GetP() const {
return ret;
}

void Edge::MakeTerminal(GameResult result) {
certainty_state_ |= kTerminalMask | kCertainMask | kUpperBound | kLowerBound;
certainty_state_ &= kGameResultClear;
if (result == GameResult::WHITE_WON) {
certainty_state_ |= kGameResultWin;
} else if (result == GameResult::BLACK_WON) {
certainty_state_ |= kGameResultLoss;
}
}

void Edge::MakeCertain(CertaintyResult certaintyresult) {
certainty_state_ |= kCertainMask | kUpperBound | kLowerBound;
certainty_state_ &= kGameResultClear;
if (certaintyresult.gameResult == GameResult::WHITE_WON) {
certainty_state_ |= kGameResultWin;
} else if (certaintyresult.gameResult == GameResult::BLACK_WON) {
certainty_state_ |= kGameResultLoss;
}
if (certaintyresult.trigger == CertaintyTrigger::TB_HIT) certainty_state_ |= kTBHit;
if (certaintyresult.trigger == CertaintyTrigger::TWO_FOLD) certainty_state_ |= kTwoFold;
}

void Edge::MakeCertain(int q, CertaintyTrigger trigger) {
certainty_state_ |= kCertainMask | kUpperBound | kLowerBound;
certainty_state_ &= kGameResultClear;
if (q == 1) {
certainty_state_ |= kGameResultWin;
} else if (q == -1) {
certainty_state_ |= kGameResultLoss;
}
if (trigger == CertaintyTrigger::TB_HIT) certainty_state_ |= kTBHit;
if (trigger == CertaintyTrigger::TWO_FOLD) certainty_state_ |= kTwoFold;
}
void Edge::SetEQ(int eq) {
certainty_state_ &= kGameResultClear;
if (eq == 1) {
certainty_state_ |= kGameResultWin;
} else if (eq == -1) {
certainty_state_ |= kGameResultLoss;
}
}

int Edge::GetEQ() const {
if (certainty_state_ & kGameResultLoss) return -1;
if (certainty_state_ & kGameResultWin) return 1;
return 0;
}

std::string Edge::DebugString() const {
std::ostringstream oss;
oss << "Move: " << move_.as_string() << " p_: " << p_ << " GetP: " << GetP();
oss << "Move: " << move_.as_string() << " p_: " << p_ << " GetP: " << GetP()
<< " Certainty:" << std::bitset<8>(certainty_state_);
return oss.str();
}

Expand Down Expand Up @@ -197,39 +247,51 @@ void Node::CreateEdges(const MoveList& moves) {
Node::ConstIterator Node::Edges() const { return {edges_, &child_}; }
Node::Iterator Node::Edges() { return {edges_, &child_}; }

void Node::RecomputeNfromChildren() {
if (n_ > 1) {
uint32_t visits = 1;
for (const auto& child : Edges()) visits += child.GetN();
n_ = visits;
}
assert(n_in_flight_ == 0);
}

float Node::GetVisitedPolicy() const { return visited_policy_; }

float Node::GetQ() const {
// Currently all certain edges have a corresponding node (PR700) and
// that nodes q_ is set correctly. If we later allow edges to become
// certain without creating the node (PR487 through look-ahead-search),
// we need to revisit this getter or adapt search.
// if (parent_) {
// auto edge = parent_->GetEdgeToNode(this);
// if (edge->IsCertain()) return (float)edge->GetEQ();
// }
return q_;
}

Edge* Node::GetEdgeToNode(const Node* node) const {
assert(node->parent_ == this);
assert(node->index_ < edges_.size());
return &edges_[node->index_];
}

Edge* Node::GetOwnEdge() const { return GetParent()->GetEdgeToNode(this); }
Edge* Node::GetOwnEdge() const {
if (GetParent()) {
return GetParent()->GetEdgeToNode(this);
} else
return nullptr;
}

std::string Node::DebugString() const {
std::ostringstream oss;
oss << " Term:" << is_terminal_ << " This:" << this << " Parent:" << parent_
<< " Index:" << index_ << " Child:" << child_.get()
<< " Sibling:" << sibling_.get() << " Q:" << q_ << " N:" << n_
<< " N_:" << n_in_flight_ << " Edges:" << edges_.size();
oss << " This:" << this << " Parent:" << parent_ << " Index:" << index_
<< " Child:" << child_.get() << " Sibling:" << sibling_.get()
<< " Q:" << q_ << " N:" << n_ << " N_:" << n_in_flight_
<< " Edges:" << edges_.size();
return oss.str();
}

void Node::MakeTerminal(GameResult result) {
is_terminal_ = true;
if (result == GameResult::DRAW) {
q_ = 0.0f;
d_ = 1.0f;
} else if (result == GameResult::WHITE_WON) {
q_ = 1.0f;
d_ = 0.0f;
} else if (result == GameResult::BLACK_WON) {
q_ = -1.0f;
d_ = 0.0f;
}
}

bool Node::TryStartScoreUpdate() {
if (n_ == 0 && n_in_flight_ > 0) return false;
++n_in_flight_;
Expand Down Expand Up @@ -388,6 +450,13 @@ void NodeTree::MakeMove(Move move) {
current_head_->ReleaseChildrenExceptOne(new_head);
current_head_ =
new_head ? new_head : current_head_->CreateSingleChildNode(move);
// If certain and no children, reset node (so that n_ = 0).
if (current_head_->IsCertain() && !current_head_->HasChildren())
TrimTreeAtHead();
// Clear certainty flag but keep bounds.
if (current_head_->GetParent())
current_head_->GetOwnEdge()->ClearCertaintyState();
current_head_->RecomputeNfromChildren();
history_.Append(move);
}

Expand Down Expand Up @@ -430,10 +499,19 @@ bool NodeTree::ResetToPosition(const std::string& starting_fen,
// previously searched position, which means that the current_head_ might
// retain old n_ and q_ (etc) data, even though its old children were
// previously trimmed; we need to reset current_head_ in that case.
// Also, if the current_head_ is terminal, reset that as well to allow forced
// analysis of WDL hits, or possibly 3 fold or 50 move "draws", etc.
if (!seen_old_head || current_head_->IsTerminal()) TrimTreeAtHead();

// Also, if the current_head_ is certain and has no children, reset that
// as well to allow forced analysis of WDL hits, or possibly 2 or 3 fold
// or 50 move "draws", etc.
if (!seen_old_head ||
(current_head_->IsCertain() && !current_head_->HasChildren()))
TrimTreeAtHead();
// Certainty Propagation: No need to trim the head for certain nodes with
// children (these became certain through backpropagation), just resetting
// certainty state except bounds, and recomputing N suffices. TrimTreeAtHead
// sets n_ to 0 this remains 0 after RecomputeNfromChildren.
if (current_head_->GetParent())
current_head_->GetOwnEdge()->ClearCertaintyState();
current_head_->RecomputeNfromChildren();
return seen_old_head;
}

Expand Down
Loading