class

GameState

Inherits JSON::Serializable < Reference < Object

Constants

MAX_JOURNAL_ENTRIES = 20

Maximum remembered-fact entries to keep in the journal.

MAX_LOG_ENTRIES = 20

Maximum log entries to keep (for context window efficiency)

Constructors

new(character_name : String = "Adventurer", hp : Int32 = 20, max_hp : Int32 = 20, current_room : String = "Starting Chamber")
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

add_companion(name : String, description : String) : String

Add a companion. If one with the same name already exists, update its description rather than creating a duplicate (keeps the name stable).

Source
add_item(name : String, description : String, quantity : Int32 = 1) : String

Add item to inventory (stacks if same type exists). Rejects blank names and non-positive quantities so tool/marker misuse cannot create invariant-violating inventory entries.

Source
add_journal_entry(entry : String) : String

Record a remembered fact in the journal (maintains max size). Case-insensitive de-duplication keeps the journal from filling with the same fact the DM re-remembers on later turns.

Source
alive?

Check if character is alive

Source
character_name
Source
character_name=(character_name : String)
Source
companions
Source
companions=(companions : Array(Companion))
Source
current_room
Source
current_room=(current_room : String)
Source
find_companion(name : String) : Companion | Nil

Find a companion by name (case-insensitive)

Source
find_item(name : String) : InventoryItem | Nil

Find an inventory item by name (case-insensitive)

Source
game_log
Source
game_log=(game_log : Array(String))
Source
hp=(hp : Int32)
Source
invariant_violations

Consistency checks used to stress-test the game under autopilot. Returns a list of human-readable invariant violations; an empty array means the state is internally consistent. This is the deterministic backbone of the stress test — it catches state bugs regardless of what the AI narrated.

Source
inventory
Source
inventory=(inventory : Array(InventoryItem))
Source
journal
Source
journal=(journal : Array(String))
Source
log(entry : String) : Nil

Add an entry to the game log (maintains max size)

Source
max_hp
Source
max_hp=(max_hp : Int32)
Source
modify_hp(amount : Int32) : String

Modify HP with clamping

Source
move_to(room : String) : String

Move the player to a new room. Rejects blank names so tool/marker misuse cannot leave current_room empty (an invariant violation). Returns a human-readable result; the caller is responsible for logging.

Source
recent_log(count : Int32 = 5) : Array(String)

Get recent log entries for context

Source
remove_companion(name : String) : String

Remove a companion by name.

Source
remove_item(name : String, quantity : Int32 = 1) : String

Remove item from inventory. Quantity must be positive so a negative value cannot silently increase a stack (existing.quantity -= quantity).

Source
replace_with!(other : GameState) : Nil

Replace this state's fields with those from another (used by load-game so the GameLoop can keep its existing state reference while swapping content).

Source
stats
Source
stats=(stats : Hash(String, Int32))
Source
stats_string

Format stats for display

Source
to_context_string

Generate context string for system prompt

Source
update_companion(name : String, new_name : String | Nil = nil, description : String | Nil = nil) : String

Update a companion's name and/or description (e.g. a true name is revealed). Refuses renames that would collide with a different existing companion, which would otherwise leave a case-insensitive duplicate in the list.

Source
visit(room : String) : Nil

Mark a room as visited

Source
visited?(room : String) : Bool

Check if a room has been visited before

Source
visited_rooms
Source
visited_rooms=(visited_rooms : Array(String))
Source