send game hash to server each second

This commit is contained in:
Evan
2025-02-25 11:49:07 -08:00
parent 393ed64ab5
commit 3fa97ed686
11 changed files with 93 additions and 25 deletions
+18 -10
View File
@@ -241,21 +241,29 @@ export class GameImpl implements Game {
this.execs.push(...inited);
this.unInitExecs = unInited;
this._ticks++;
if (this._ticks % 100 == 0) {
let hash = 1;
this._players.forEach((p) => {
hash += p.hash();
});
consolex.log(`tick ${this._ticks}: hash ${hash}`);
}
for (const player of this._players.values()) {
// Players change each to so always add them
this.addUpdate(player.toUpdate());
}
if (this.ticks() % 10 == 0) {
this.addUpdate({
type: GameUpdateType.Hash,
tick: this.ticks(),
hash: this.hash(),
});
}
this._ticks++;
return this.updates;
}
private hash(): number {
let hash = 1;
this._players.forEach((p) => {
hash += p.hash();
});
return hash;
}
terraNullius(): TerraNullius {
return this._terraNullius;
}
@@ -494,14 +502,14 @@ export class GameImpl implements Game {
sendEmojiUpdate(msg: EmojiMessage): void {
this.addUpdate({
type: GameUpdateType.EmojiUpdate,
type: GameUpdateType.Emoji,
emoji: msg,
});
}
setWinner(winner: Player): void {
this.addUpdate({
type: GameUpdateType.WinUpdate,
type: GameUpdateType.Win,
winnerID: winner.smallID(),
});
}
+13 -5
View File
@@ -34,8 +34,9 @@ export enum GameUpdateType {
BrokeAlliance,
AllianceExpired,
TargetPlayer,
EmojiUpdate,
WinUpdate,
Emoji,
Win,
Hash,
}
export type GameUpdate =
@@ -49,7 +50,8 @@ export type GameUpdate =
| DisplayMessageUpdate
| TargetPlayerUpdate
| EmojiUpdate
| WinUpdate;
| WinUpdate
| HashUpdate;
export interface TileUpdateWrapper {
type: GameUpdateType.Tile;
@@ -133,7 +135,7 @@ export interface TargetPlayerUpdate {
}
export interface EmojiUpdate {
type: GameUpdateType.EmojiUpdate;
type: GameUpdateType.Emoji;
emoji: EmojiMessage;
}
@@ -145,6 +147,12 @@ export interface DisplayMessageUpdate {
}
export interface WinUpdate {
type: GameUpdateType.WinUpdate;
type: GameUpdateType.Win;
winnerID: number;
}
export interface HashUpdate {
type: GameUpdateType.Hash;
tick: Tick;
hash: number;
}
+1 -1
View File
@@ -135,7 +135,7 @@ export class UnitImpl implements Unit {
}
hash(): number {
return this.tile() + simpleHash(this.type());
return this.tile() + simpleHash(this.type()) * this._id;
}
toString(): string {