feature/pathfinding-finetuning #11

Merged
lobo merged 3 commits from feature/pathfinding-finetuning into main 2026-02-05 09:25:41 +01:00
Showing only changes of commit f385a154d5 - Show all commits

View File

@@ -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++) {