From 4c84792f3b967f1c47b9bf99b24571eb5c321ddb Mon Sep 17 00:00:00 2001 From: tcsenpai Date: Sun, 30 Mar 2025 22:57:21 +0200 Subject: [PATCH] type declaration semantic fixes --- src/animals/fluffles.ts | 6 +++--- src/animals/rabbit.ts | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/animals/fluffles.ts b/src/animals/fluffles.ts index 86a252f..651fb29 100644 --- a/src/animals/fluffles.ts +++ b/src/animals/fluffles.ts @@ -258,7 +258,7 @@ export class Fluffles extends Animal { ]; // Check each adjacent position for food - let bestFoodPosition = null; + let bestFoodPosition: Position | null = null; let bestFoodValue = 0; for (const pos of adjacentPositions) { @@ -309,7 +309,7 @@ export class Fluffles extends Animal { if (nearbyAnimals.length > 0) { // Find the closest fluffles - let closestFluffles = null; + let closestFluffles: Animal | null = null; let closestDistance = Infinity; for (const animal of nearbyAnimals) { @@ -368,7 +368,7 @@ export class Fluffles extends Animal { if (potentialTargets.length > 0) { // Find the closest target - let closestTarget = null; + let closestTarget: Animal | null = null; let closestDistance = Infinity; for (const animal of potentialTargets) { diff --git a/src/animals/rabbit.ts b/src/animals/rabbit.ts index fedf038..9391365 100644 --- a/src/animals/rabbit.ts +++ b/src/animals/rabbit.ts @@ -181,9 +181,10 @@ export class Rabbit extends Animal { private seekCompany(): void { const nearbyAnimals = this.world.getAnimalsInRadius(this.position, 3); + let closestRabbit: Animal | null = null; + if (nearbyAnimals.length > 0) { // Find the closest rabbit - let closestRabbit = null; let closestDistance = Infinity; for (const animal of nearbyAnimals) { @@ -214,6 +215,8 @@ export class Rabbit extends Animal { private searchForMates(): void { const nearbyAnimals = this.world.getAnimalsInRadius(this.position, 2); + let closestRabbit: Animal | null = null; + for (const animal of nearbyAnimals) { if (animal.getId() !== this.id) { // Not self const pos = animal.getPosition();