From d1be25c6e8956cca5f531f11e92a5851d0ebfcc6 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Sun, 16 Nov 2025 15:32:03 -0500 Subject: [PATCH] added load_cards and load_nobles --- python/splendor/base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/splendor/base.py b/python/splendor/base.py index 97a6edb..744e978 100644 --- a/python/splendor/base.py +++ b/python/splendor/base.py @@ -3,12 +3,14 @@ from __future__ import annotations import itertools +import json import random from dataclasses import dataclass, field from typing import TYPE_CHECKING, Literal, Protocol if TYPE_CHECKING: from collections.abc import Sequence + from pathlib import Path GemColor = Literal["white", "blue", "green", "red", "black", "gold"] @@ -602,6 +604,18 @@ def create_random_nobles() -> list[Noble]: return nobles +def load_nobles(file: Path) -> list[Noble]: + """Load nobles from a file.""" + nobles = json.loads(file.read_text()) + return [Noble(**noble) for noble in nobles] + + +def load_cards(file: Path) -> list[Card]: + """Load cards from a file.""" + cards = json.loads(file.read_text()) + return [Card(**card) for card in cards] + + def new_game( strategies: Sequence[Strategy], config: GameConfig,