import type { GameState } from './state.js'; export function serializeGame(game: GameState): string { // Use a deterministic JSON serializer for snapshots; currently use JSON.stringify return JSON.stringify(game); } export function deserializeGame(serialized: string): GameState { try { return JSON.parse(serialized) as GameState; } catch (e) { // If parsing fails, return a minimal empty game state to avoid crashes return { players: [], placements: { corners: [], roads: [] } } as GameState; } } export function cloneGame(game: GameState): GameState { return deserializeGame(serializeGame(game)); }