tucoopy.io.game_spec¶
Parsing and conversion helpers for spec-like JSON objects.¶
This module provides:
- tolerant "field access" helpers for dict-like / attribute-like objects,
- JSON loading helpers for specs (string/bytes/path),
- converters between
tucoopy.base.game.Gameand a stable wire dict, and - helpers to extract relevant pieces from an animation spec (game, sets, frames).
The wire formats are designed to remain simple, JSON-friendly, and compatible with the schema files shipped in tucoopy.io.schemas.
Examples:
>>> from tucoopy.io.game_spec import spec_from_json
>>> spec = spec_from_json(
... '{"n_players": 2, "characteristic_function": [{"coalition_mask": 0, "value": 0.0}] }'
... )
>>> isinstance(spec, dict)
True
game_from_animation_spec ¶
game_from_animation_spec(spec)
STRICT builder: construct a Game from an AnimationSpec-like object that uses the canonical CF shape:
spec.game = { "n_players": int, "player_labels": [... optional ...], "characteristic_function": [{"coalition_mask": int, "value": number}, ...] }
Inputs accepted: - dict-like spec - dataclass/attr-like spec - JSON string/bytes/Path that parses to a dict
game_from_wire_dict ¶
game_from_wire_dict(data)
Deserialize a Game from wire format produced by game_to_wire_dict.
game_to_wire_dict ¶
game_to_wire_dict(game)
Serialize a Game into a JSONable dict (wire format).
Stable format: { "n_players": int, "player_labels": [str] | null, "values": { "
spec_from_json ¶
spec_from_json(data)
Load a spec-like dict from JSON content.
Accepts: - JSON string - JSON bytes - Path to a JSON file - str path to a .json file (if exists)