From 090ef8046cb8093cb367f24d22a5ebc240431022 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 19 May 2025 14:02:50 -0400 Subject: [PATCH] Add hash to Unit interface (#811) ## Description: - Add `hash()` to the `Unit` interface to avoid casts with `as`. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/game/Game.ts | 2 ++ src/core/game/PlayerImpl.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index fda7d78c4..861fc70e5 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -324,6 +324,8 @@ export class PlayerInfo { } export interface Unit { + hash(): number; + // Common properties. id(): number; type(): UnitType; diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 989afc109..03d0a3b27 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -925,7 +925,7 @@ export class PlayerImpl implements Player { hash(): number { return ( simpleHash(this.id()) * (this.population() + this.numTilesOwned()) + - this._units.reduce((acc, unit) => acc + (unit as UnitImpl).hash(), 0) + this._units.reduce((acc, unit) => acc + unit.hash(), 0) ); } toString(): string {