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

When a move happens to be the "top engine move", it now appears in bold (movelist / tree view) #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions files/src/renderer/50_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const table_prototype = {
this.tbhits = 0; // Stat sent by engine
this.time = 0; // Stat sent by engine
this.limit = null; // The limit of the last search that updated this.
this.bestmove_so_far = null; // The "top engine move" move e.g. 'e7e5'
this.terminal = null; // null = unknown, "" = not terminal, "Non-empty string" = terminal reason
this.eval = null; // Used by grapher only, value from White's POV
this.eval_version = 0; // Which version (above) was used to generate the eval
Expand Down
20 changes: 19 additions & 1 deletion files/src/renderer/72_tree_draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ let tree_draw_props = {
ordered_nodes_cache: null,
ordered_nodes_cache_version: -1,

dom_bold_bestmove_child: function(node) {
let bestmove_move = node.table.bestmove_so_far;

node.children.forEach( function(child_node) {
let dom_child_node = document.getElementById(`node_${child_node.id}`);
dom_child_node.style.fontWeight = (bestmove_move == child_node.move) ? 'bold' : 'normal';
});
},

dom_easy_highlight_change: function() {

// When the previously highlighted node and the newly highlighted node are on the same line,
Expand Down Expand Up @@ -57,7 +66,8 @@ let tree_draw_props = {
this.ordered_nodes_cache_version = this.tree_version;
}

let pseudoelements = []; // Objects containing opening span string `<span foo>` and text string
let dom_bestmove_fontweight_ids = []; // The "from scratch" equivalent to `dom_bold_bestmove_child` — we want to bold when the move was the "top engine move"
let pseudoelements = []; // Objects containing opening span string `<span foo>` and text string

for (let item of this.ordered_nodes_cache) {

Expand Down Expand Up @@ -94,6 +104,10 @@ let tree_draw_props = {
classes.push("white"); // Otherwise, inherits gray colour from movelist CSS
}

if ((node.parent !== null) && (node.parent.table.bestmove_so_far !== null) && (node.parent.table.bestmove_so_far == node.move)) {
dom_bestmove_fontweight_ids.push(node.id);
}

pseudoelements.push({
opener: `<span class="${classes.join(" ")}" id="node_${node.id}">`,
text: node.token(),
Expand All @@ -117,6 +131,10 @@ let tree_draw_props = {

movelist.innerHTML = all_spans.join("");

dom_bestmove_fontweight_ids.forEach( function(node_id) {
document.getElementById(`node_${node_id}`).style.fontWeight = 'bold';
});

// Undo the damage to our tree from the start...

foo = line_end;
Expand Down
7 changes: 7 additions & 0 deletions files/src/renderer/90_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,20 @@ function NewEngine(hub) {
this.send("ucinewgame");
};

// e.g. `line` might be "bestmove e7e5 ponder g1f3"
eng.handle_bestmove_line = function(line) {

this.search_completed = this.search_running;
this.search_running = NoSearch;

this.unresolved_stop_time = null;

if (this.search_completed.node.table !== null) {
let tokens = line.split(" ").filter(z => z !== "");
this.search_completed.node.table.bestmove_so_far = tokens[1];
this.hub.tree.dom_bold_bestmove_child(this.search_completed.node);
}

// If this.search_desired === this.search_running then the search that just completed is
// the most recent one requested by the hub; we have nothing to replace it with.
//
Expand Down
2 changes: 2 additions & 0 deletions files/src/renderer/95_hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ let hub_props = {
break;
}

// e.g. `s` might be 'bestmove e7e5 ponder g1f3'
let tokens = s.split(" ").filter(z => z !== "");
ok = this.move(tokens[1]);

Expand Down Expand Up @@ -1273,6 +1274,7 @@ let hub_props = {
this.set_behaviour("halt"); // Will cause "stop" to be sent.
this.engine.send_ucinewgame(); // Must happen after "stop" is sent.
this.engine.suppress_cycle_info = this.info_handler.engine_cycle; // Ignore further info updates from this cycle.
this.tree.dom_from_scratch(); // Clear any highlights or annotations
},

// ---------------------------------------------------------------------------------------------------------------------
Expand Down