From a3531de362f91cac7e3fc5b7fb449b345474834b Mon Sep 17 00:00:00 2001 From: Henry Quillin Date: Fri, 24 Sep 2021 09:52:51 -0500 Subject: [PATCH 1/3] Stats now show right after start is clicked --- docs/contributor-guide/authors.md | 1 + visual/js/controller.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docs/contributor-guide/authors.md b/docs/contributor-guide/authors.md index 55edc771..dca62796 100644 --- a/docs/contributor-guide/authors.md +++ b/docs/contributor-guide/authors.md @@ -5,6 +5,7 @@ This is the alphabetically sorted list of contributors to PathFinding.js: Anders Riutta
Chris Khoo
Gerjo
+Henry Quillin
Juan Pablo Canepa
Mat Gadd
Murilo Pereira
diff --git a/visual/js/controller.js b/visual/js/controller.js index f5260710..2d0667d1 100644 --- a/visual/js/controller.js +++ b/visual/js/controller.js @@ -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() { From 92ce7d56e7f91d6cca29d94b4beb6940e559bfd5 Mon Sep 17 00:00:00 2001 From: Henry Quillin Date: Fri, 24 Sep 2021 09:59:25 -0500 Subject: [PATCH 2/3] Removed viewStats() from onfinish function --- visual/js/controller.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/visual/js/controller.js b/visual/js/controller.js index 2d0667d1..996ef194 100644 --- a/visual/js/controller.js +++ b/visual/js/controller.js @@ -178,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 }, From 1cb135037a494edb03e445a72e7e8893f906495f Mon Sep 17 00:00:00 2001 From: Henry Quillin Date: Fri, 24 Sep 2021 21:49:19 -0500 Subject: [PATCH 3/3] now generates random walls onload --- visual/js/controller.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/visual/js/controller.js b/visual/js/controller.js index 996ef194..bdd55f5c 100644 --- a/visual/js/controller.js +++ b/visual/js/controller.js @@ -482,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;