Skip to content
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
1 change: 1 addition & 0 deletions docs/contributor-guide/authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is the alphabetically sorted list of contributors to PathFinding.js:
Anders Riutta <https://github.com/ariutta><br>
Chris Khoo <https://github.com/chriskck><br>
Gerjo <https://github.com/Gerjo><br>
Henry Quillin <https://github.com/HenryQuillin><br>
Juan Pablo Canepa <https://github.com/jpcanepa><br>
Mat Gadd <https://github.com/Drarok><br>
Murilo Pereira <https://github.com/mpereira><br>
Expand Down
39 changes: 34 additions & 5 deletions visual/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ $.extend(Controller, {
this.timeSpent = (timeEnd - timeStart).toFixed(4);

this.loop();

// Shows the algorithm stats when start is clicked
View.showStats({
pathLength: PF.Util.pathLength(this.path),
timeSpent: this.timeSpent,
operationCount: this.operationCount,
});
// => searching
},
onrestart: function() {
Expand Down Expand Up @@ -171,11 +178,6 @@ $.extend(Controller, {
// => ready
},
onfinish: function(event, from, to) {
View.showStats({
pathLength: PF.Util.pathLength(this.path),
timeSpent: this.timeSpent,
operationCount: this.operationCount,
});
View.drawPath(this.path);
// => finished
},
Expand Down Expand Up @@ -480,6 +482,33 @@ $.extend(Controller, {

this.setStartPos(centerX - 5, centerY);
this.setEndPos(centerX + 5, centerY);

this.generateRandomWalls()
},

generateRandomWalls: function() {
// for each node
// generate random number between 0 and 1
// if the number is less than 3, place a wall node

var numCols = this.gridSize[0];
var numRows = this.gridSize[1];
var percentWalls = .2


for (let i = 0; i < numRows; i++) {
for (let j = 0; j < numCols; j++) {

const node = this.grid.nodes[i][j];
num = Math.random();
if (num < percentWalls && (!this.isStartOrEndPos(node.x,node.y))) {
View.setWalkableAt(node.x, node.y, false)
this.setWalkableAt(node.x, node.y, false)
}

}

}
},
setStartPos: function(gridX, gridY) {
this.startX = gridX;
Expand Down