From f385a154d50c9de322b01754572e6b8efcbe562c Mon Sep 17 00:00:00 2001 From: LoboTheDark Date: Thu, 5 Feb 2026 08:35:34 +0100 Subject: [PATCH] Update pathfinding.component.ts Created new normal case --- .../pathfinding/pathfinding.component.ts | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/app/pages/algorithms/pathfinding/pathfinding.component.ts b/src/app/pages/algorithms/pathfinding/pathfinding.component.ts index bcd5a16..fcfd433 100644 --- a/src/app/pages/algorithms/pathfinding/pathfinding.component.ts +++ b/src/app/pages/algorithms/pathfinding/pathfinding.component.ts @@ -114,10 +114,9 @@ export class PathfindingComponent implements AfterViewInit { } // Default after size changes: pick one consistent scenario - this.edgeCase(); + this.normalCase(); } - // Scenarios (buttons) normalCase(): void { this.stopAnimations(); this.initializeGrid(true, 'normal'); @@ -250,7 +249,7 @@ export class PathfindingComponent implements AfterViewInit { this.endNode.isEnd = true; if (withWalls) { - this.placeDefaultDiagonalWall(); + this.placeDefaultDiagonalWall(scenario); } } @@ -300,7 +299,37 @@ export class PathfindingComponent implements AfterViewInit { }; } - private placeDefaultDiagonalWall(): void { + private placeDefaultDiagonalWall(scenario: 'normal' | 'edge'): void { + if (scenario === 'edge') { + this.createDiagonalWall(); + } + else if (scenario === 'normal') { + this.createVerticalWall(); + } + } + + private createVerticalWall() { + const height = this.gridRows; + const startCol = Math.floor(this.gridCols / 2); + + for (let i = 5; i < (height - 5); i++) { + const row = i; + + if (!this.isValidPosition(row, startCol)) { + continue; + } + + const node = this.grid[row][startCol]; + if (node.isStart || node.isEnd) { + continue; + } + + node.isWall = true; + } + + } + + private createDiagonalWall() { // Diagonal-ish wall; avoids start/end const len = Math.min(this.gridRows, this.gridCols); const startCol = Math.floor((this.gridCols - len) / 2); @@ -322,7 +351,7 @@ export class PathfindingComponent implements AfterViewInit { } } - // Path state +// Path state private clearPath(): void { for (let row = 0; row < this.gridRows; row++) { for (let col = 0; col < this.gridCols; col++) {