Skip to content

Commit

Permalink
fix stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rooklift committed Feb 19, 2022
1 parent ae2663f commit 91b943f
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions src/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,50 +237,58 @@ let node_prototype = {

get_board: function() {

if (this.__board) {
return this.__board;
}
let nodes_without_boards = [];

if (!this.parent) {
this.__board = new_board(this.width(), this.height());
} else {
this.__board = this.parent.get_board().copy();
let nd = this;
while (nd && !nd.__board) {
nodes_without_boards.push(nd);
nd = nd.parent;
}
nodes_without_boards.reverse();

for (let s of this.all_values("AE")) {
this.__board.add_empty(s);
}
for (let node of nodes_without_boards) {

for (let s of this.all_values("AB")) {
this.__board.add_black(s);
this.__board.active = "w";
}
if (!node.parent) {
node.__board = new_board(node.width(), node.height());
} else {
node.__board = node.parent.__board.copy();
}

for (let s of this.all_values("AW")) {
this.__board.add_white(s);
this.__board.active = "b";
}
for (let s of node.all_values("AE")) {
node.__board.add_empty(s);
}

for (let s of this.all_values("B")) {
this.__board.play_black(s); // Will treat s as a pass if it's not a valid move.
}
for (let s of node.all_values("AB")) {
node.__board.add_black(s);
node.__board.active = "w";
}

for (let s of this.all_values("W")) {
this.__board.play_white(s); // Will treat s as a pass if it's not a valid move.
}
for (let s of node.all_values("AW")) {
node.__board.add_white(s);
node.__board.active = "b";
}

let pl = this.get("PL");
if (pl[0] === "B" || pl[0] === "b" || pl === "1") this.__board.active = "b";
if (pl[0] === "W" || pl[0] === "w" || pl === "2") this.__board.active = "w";
for (let s of node.all_values("B")) {
node.__board.play_black(s); // Will treat s as a pass if it's not a valid move.
}

let km = parseFloat(this.get("KM"));
if (Number.isNaN(km) === false) {
this.__board.komi = km;
}
for (let s of node.all_values("W")) {
node.__board.play_white(s); // Will treat s as a pass if it's not a valid move.
}

let pl = node.get("PL");
if (pl[0] === "B" || pl[0] === "b" || pl === "1") node.__board.active = "b";
if (pl[0] === "W" || pl[0] === "w" || pl === "2") node.__board.active = "w";

let ru = this.get("RU");
if (ru) {
this.__board.rules = ru;
let km = parseFloat(node.get("KM"));
if (Number.isNaN(km) === false) {
node.__board.komi = km;
}

let ru = node.get("RU");
if (ru) {
node.__board.rules = ru;
}
}

return this.__board;
Expand Down

0 comments on commit 91b943f

Please sign in to comment.