Skip to content

Commit 6fd87bb

Browse files
committed
Fixed bug in maze solution
1 parent 08d6a3a commit 6fd87bb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

animations/backtracking-maze/js/sketch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class Sketch extends Engine {
1616
this._solution_color = Color.fromHEX("#218380");
1717
this._visited_color = Color.fromHEX("#ffbc42");
1818
this._start = [1, 1];
19-
this._end = [this._cols - 2, this._cols - 2];
2019

2120
this._single_frame_generation = false;
2221
this._single_frame_solution = false;
@@ -38,6 +37,7 @@ class Sketch extends Engine {
3837
this._xor128 = new XOR128(this._seed);
3938
this._cols = this._xor128.random_int(80, 120);
4039
if (this._cols % 2 === 0) this._cols++; // Ensure cols is odd for maze generation
40+
this._end = [this._cols - 2, this._cols - 2];
4141

4242
this._generation_first_step = true;
4343
this._solution_first_step = true;
@@ -126,8 +126,10 @@ class Sketch extends Engine {
126126
}
127127

128128
_solutionNextStep() {
129+
if (this._solution_stack.length === 0) return true;
129130
// find the node with the lowest f score
130131
const current = this._lowestFScore();
132+
if (current == null) return true;
131133
const [cx, cy] = this._i_to_xy(current);
132134
// add the current node to the visited set for visualization
133135
this._solution_visited[current] = true;

0 commit comments

Comments
 (0)