Skip to content

Commit

Permalink
Fix typo in closest target algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Oct 15, 2024
1 parent 4dd82cf commit b45f0e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions games/ZombieSurvival/ZombieSurvival.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ test("kills zombies", () => {
[" ", " ", " ", "P", "B", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", "B", " ", " ", " ", " ", " "],
["R", "R", "R", "R", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", "Z", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", "Z", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
]);
Expand All @@ -150,9 +150,9 @@ test("kills zombies", () => {
[" ", " ", " ", "P", "B", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", "B", " ", " ", " ", " ", " "],
["R", "R", "R", "R", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", "Z", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", "Z", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
]);
Expand Down Expand Up @@ -312,6 +312,7 @@ test("player gets killed with too many zombies", () => {
game.step();
game.step();
game.step();
game.step();

expect(game.getState()).toStrictEqual([
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "],
Expand Down
2 changes: 1 addition & 1 deletion games/ZombieSurvival/lib/closest-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function closestEntity(entity: Entity, targets: Entity[]): Entity {
continue;
}

const targetPosition = positionAsNumber(entity.getPosition());
const targetPosition = positionAsNumber(target.getPosition());
const score = Math.abs(entityPosition - targetPosition);

scores.push({ target, score });
Expand Down

0 comments on commit b45f0e7

Please sign in to comment.