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

Add next mistake and previous mistake buttons #132

Open
wants to merge 3 commits into
base: main
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
17 changes: 17 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@ function menu_build() {
{
type: "separator",
},
{
label: translate("MENU_PREVIOUS_MISTAKE"),
accelerator: "CommandOrControl+Shift+P",
click: () => {
win.webContents.send("call", "previous_mistake");
}
},
{
label: translate("MENU_NEXT_MISTAKE"),
accelerator: "CommandOrControl+Shift+N",
click: () => {
win.webContents.send("call", "next_mistake");
}
},
{
type: "separator",
},
{
label: translate("MENU_PREVIOUS_SIBLING"),
accelerator: "Left",
Expand Down
2 changes: 2 additions & 0 deletions src/modules/config_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ exports.defaults = {
"wide_root_noise": 0.04, // Until 1.5.9, this was a bool, but was called "widerootnoise"
"report_every": 0.1,

"mistake_threshold": 3, // Amount of points to lose in a single move before it is considered a "mistake"

"ownership_marks": 1, // 0: None 1: Dead stones 2: Whole board 3: Whole board (alt)
"ownership_per_move": true,

Expand Down
36 changes: 36 additions & 0 deletions src/modules/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,42 @@ let hub_main_props = {
this.draw();
},

next_mistake: function() {

let delta_score = 0
let current_node = this.node
while (delta_score > -config.mistake_threshold && current_node.children.length > 0) {
current_node = current_node.get_blessed_child()
const last_score = current_node.parent.stored_score()
delta_score = current_node.stored_score() - last_score
if (current_node.has_key("W")) {
delta_score = delta_score * -1
}

}
this.set_node(current_node, {bless: false});
},

previous_mistake: function() {
let delta_score = 0
let current_node = this.node
let last_node = this.node
if (!current_node.parent)
return
current_node = current_node.parent
while (delta_score > -config.mistake_threshold && current_node.parent) {
const last_score = current_node.stored_score()
delta_score = last_score - current_node.parent.stored_score()
if (current_node.has_key("W")) {
delta_score = delta_score * -1
}
last_node = current_node
current_node = current_node.parent
}
this.set_node(last_node, {bless: false});

},

// Engine......................................................................................

receive_object: function(o) {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/hub_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ module.exports = {
}
break;

case "mistake_threshold":
break; // This doesn't change anything that needs to be drawn.

case "ownership_marks":
case "ownership_per_move":

Expand Down
2 changes: 2 additions & 0 deletions src/modules/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ translations[`English`] = {
MENU_PROMOTE_LINE_TO_MAIN_LINE: `Promote line to main line`,
MENU_DELETE_NODE: `Delete node`,
MENU_DELETE_ALL_PREVIOUS_FORKS: `Delete all previous forks`,
MENU_NEXT_MISTAKE: `Next Mistake`,
MENU_PREVIOUS_MISTAKE: `Previous Mistake`,

MENU_TOOLS: `Tools`,

Expand Down