Skip to content

Commit

Permalink
Fixed start/end being on wall after maze gen
Browse files Browse the repository at this point in the history
  • Loading branch information
tobinatore committed Sep 8, 2020
1 parent 6a26842 commit 7d35e4e
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions pathfinding.html
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ <h4>Useful Links</h4>
<script src="assets/js/Pathfinding/dfs_pf.js"></script>
<script src="assets/js/Pathfinding/dijkstra_pf.js"></script>
<script src="assets/js/Maze/recursive_dfs.js"></script>
<script src="assets/js/Maze/recursive_division.js"></script>
<script src="assets/js/Maze/growing_tree.js"></script>
<script src="assets/js/Maze/binary_tree_generator.js"></script>
<script src="assets/js/Maze/sidewinder.js"></script>

Expand Down Expand Up @@ -849,7 +849,6 @@ <h4>Useful Links</h4>
if (d.click % 2 == 0) {
d3.select(this).transition().duration(400).attr("fill", "#fff");
d.type = "floor";
console.log("yeet");
}
if (d.click % 2 == 1) {
d.anim = true;
Expand Down Expand Up @@ -1029,6 +1028,36 @@ <h4>Useful Links</h4>
await mazeGen.startMaze();
}

while (
gridData[startPos.y][startPos.x].type == "wall" ||
(startPos.x == endPos.x && startPos.y == endPos.y)
) {
if (startPos.x > 0) {
startPos.x -= 1;
d3.select("#start").attr("x", startPos.x * 25);
continue;
}
if (startPos.x < gridData[0].length - 2) {
startPos.x += 1;
d3.select("#start").attr("x", startPos.x * 25);
}
}

while (
gridData[endPos.y][endPos.x].type == "wall" ||
(startPos.x == endPos.x && startPos.y == endPos.y)
) {
if (endPos.x > 0) {
endPos.x -= 1;
d3.select("#end").attr("x", endPos.x * 25);
continue;
}
if (endPos.x < gridData[0].length - 2) {
endPos.x += 1;
d3.select("#end").attr("x", endPos.x * 25);
}
}

$("#startPf").prop("disabled", false);
$("#dropdownAlgo").prop("disabled", false);
$("#dropdownGen").prop("disabled", false);
Expand Down

0 comments on commit 7d35e4e

Please sign in to comment.