Skip to content

Commit

Permalink
fix_singleton_handicap() - return early if no children
Browse files Browse the repository at this point in the history
  • Loading branch information
rooklift committed Feb 7, 2024
1 parent 772f989 commit 9350c12
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/modules/root_fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,27 @@ function purge_newlines(root) {
}

function fix_singleton_handicap(root) {
if (root.all_values("AB").length !== 1 || root.has_key("AW") || root.has_key("AE") || root.has_key("B") || root.has_key("W")) {

if (root.all_values("AB").length !== 1) {
return;
}

// Any weirdness at all about this file, and we abort...

if (root.has_key("AW") || root.has_key("AE") || root.has_key("B") || root.has_key("W")) {
return;
}
for (let child of root.children) { // Any weirdness, i.e. anything other than one W move in a child, and we abort...
if (root.children.length === 0) {
return;
}
for (let child of root.children) {
if (!child.has_key("W") || child.has_key("B") || child.has_key("AB") || child.has_key("AW") || child.has_key("AE")) {
return;
}
}

// File is apparently not weird...

root.set("B", root.get("AB"));
root.delete_key("AB");
}
Expand Down

0 comments on commit 9350c12

Please sign in to comment.