from dataclasses import dataclass, field from typing import List, Optional from enum import IntEnum import random class RelationType(IntEnum): HOSTILE = -1 UNDEFINED = 0 NEUTRAL = 1 FRIENDLY = 2 class MilitaryStrength(IntEnum): FULL = 4 STRONG = 3 WEAKENED = 2 DESPERATE = 1 BROKEN = 0 class Resources(IntEnum): ABUNDANT = 3 SUFFICIENT = 2 STRAINED = 1 DESPERATE = 0 class LeaderStatus(IntEnum): COMMANDING = 3 WOUNDED = 2 CAPTURED = 1 DEAD = 0 class Momentum(IntEnum): ASCENDANT = 3 STABLE = 2 DECLINING = 1 CRUMBLING = 0 @dataclass class Relation: state_name: str relation_type: int @dataclass class State: name: str # Core stats military_strength: MilitaryStrength resources: Resources leader_status: LeaderStatus momentum: Momentum # Governance ruled_by: Optional[str] = None # None = self-governing # Diplomacy and geography relations: dict[str, RelationType] = field(default_factory=dict) neighbors: dict[str, RelationType] = field(default_factory=dict) def __post_init__(self): self._validate_range("military_strength", self.military_strength, 0, 4) self._validate_range("resources", self.resources, 0, 3) self._validate_range("leader_status", self.leader_status, 0, 3) self._validate_range("momentum", self.momentum, 0, 3) # If no ruler specified, state rules itself if self.ruled_by is None: self.ruled_by = self.name @staticmethod def _validate_range(name: str, value: int, minimum: int, maximum: int): if not minimum <= value <= maximum: raise ValueError( f"{name} must be between {minimum} and {maximum}" ) def add_relation(self, state_name: str, relation_type: int): self.relations.append(Relation(state_name, relation_type)) def add_neighbor(self, state_name: str, relation_type: int): self.neighbors.append(Relation(state_name, relation_type)) @property def is_self_governing(self) -> bool: return self.ruled_by == self.name class World: def __init__(self): self.states = {} def add_state(self, state): self.states[state.name] = state def get_state(self, name): return self.states[name] def print_state_table(self): print( f"{'State':25}" f"{'Military':12}" f"{'Resources':12}" f"{'Leader':12}" f"{'Momentum':12}" f"{'Ruler':25}" ) for state in self.states.values(): print( f"{state.name:25}" f"{state.military_strength.name:12}" f"{state.resources.name:12}" f"{state.leader_status.name:12}" f"{state.momentum.name:12}" f"{state.ruled_by:25}" ) def set_relation( self, state_name: str, other_name: str, relation: RelationType ): state = self.get_state(state_name) if other_name in state.neighbors: state.neighbors[other_name] = relation else: state.relations[other_name] = relation def print_state(self, state_name): state = self.get_state(state_name) print(f"\n=== {state.name} ===") print(f"Military Strength: {state.military_strength.name}") print(f"Resources: {state.resources.name}") print(f"Leader Status: {state.leader_status.name}") print(f"Momentum: {state.momentum.name}") print(f"Ruled By: {state.ruled_by}") print("\nRelations:") if state.relations: for name, relation in state.relations.items(): print(f" {name}: {relation.name}") else: print(" None") print("\nNeighbors:") if state.neighbors: for name, relation in state.neighbors.items(): print(f" {name}: {relation.name}") else: print(" None") print() EVENT_CONFIG = { "relation_bonus": 8, "military_hostile_factor": 2, "resource_friendly_factor": 2, "momentum_factor": 3, "random_event_weight": 0.05, "undefined_relation_factor": 0.4, "debug": False } def relation_weight(state1, state2, relation): weight = 10 if relation == RelationType.FRIENDLY: weight += 10 elif relation == RelationType.HOSTILE: weight += 10 weight += state1.momentum weight += state2.momentum return weight def generate_events(world, num_events): # Build list of unique relationships possible_events = [] for state in world.states.values(): for other_name, relation in state.neighbors.items(): if other_name not in world.states: continue # if state.name < other_name: possible_events.append( (state.name, other_name, relation) ) for other_name, relation in state.relations.items(): if other_name not in world.states: continue # if state.name < other_name: possible_events.append( (state.name, other_name, relation) ) if not possible_events: return # Weight relationships by activity level relationship_weights = [] for state1_name, state2_name, relation in possible_events: state1 = world.get_state(state1_name) state2 = world.get_state(state2_name) weight = 10 if relation.name == "FRIENDLY": weight += EVENT_CONFIG["relation_bonus"] elif relation.name == "HOSTILE": weight += EVENT_CONFIG["relation_bonus"] elif relation.name == "UNDEFINED": weight *= EVENT_CONFIG["undefined_relation_factor"] weight += state1.momentum + state2.momentum if state1.ruled_by == state2.ruled_by: weight = 0 if EVENT_CONFIG["debug"]: print( f"{state1_name} - " f"{state2_name} - " f"{relation.name} - " f"Weight: {weight}" ) relationship_weights.append(weight) # Generate requested number of events for _ in range(num_events): state1_name, state2_name, relation = random.choices( possible_events, weights=relationship_weights, k=1 )[0] state1 = world.get_state(state1_name) state2 = world.get_state(state2_name) if EVENT_CONFIG["debug"]: print( f"Relation picked: {state1_name} - " f"{state2_name} - " f"{relation.name}" ) # Determine initiative state1_initiative = ( state1.military_strength + state1.resources + (state1.momentum * EVENT_CONFIG["momentum_factor"]) ) state2_initiative = ( state2.military_strength + state2.resources + (state2.momentum * EVENT_CONFIG["momentum_factor"]) ) initiator = random.choices( [state1, state2], weights=[ state1_initiative, state2_initiative ], k=1 )[0] target = state2 if initiator == state1 else state1 # Event type weighting friendly_weight = 1 neutral_weight = 5 hostile_weight = 1 military_advantage = ( initiator.military_strength - target.military_strength ) resource_advantage = ( initiator.resources - target.resources ) momentum_advantage = ( initiator.momentum - target.momentum ) if relation.name == "FRIENDLY": friendly_weight += EVENT_CONFIG["relation_bonus"] elif relation.name == "HOSTILE": hostile_weight += EVENT_CONFIG["relation_bonus"] else: neutral_weight += EVENT_CONFIG["relation_bonus"] if military_advantage <= 1: friendly_weight += EVENT_CONFIG["resource_friendly_factor"] if momentum_advantage <= 0: friendly_weight += EVENT_CONFIG["resource_friendly_factor"] if resource_advantage < 0: hostile_weight += EVENT_CONFIG["military_hostile_factor"] hostile_weight += max(0, military_advantage) * EVENT_CONFIG["military_hostile_factor"] hostile_weight += max(0, momentum_advantage) * EVENT_CONFIG["momentum_factor"] hostile_weight += target.resources random_weight = (friendly_weight + neutral_weight + hostile_weight) * EVENT_CONFIG["random_event_weight"] if EVENT_CONFIG["debug"]: print( f"Friendly weight: {friendly_weight}, " f"Neutral weight: {neutral_weight}, " f"Hostile weight: {hostile_weight}, " f"Random weight: {random_weight} - " f"Total weight: {friendly_weight + neutral_weight + hostile_weight + random_weight}" ) event_type = random.choices( ["friendly", "neutral", "hostile", "random"], weights=[ friendly_weight, neutral_weight, hostile_weight, random_weight ], k=1 )[0] initiator_spaced = initiator.name.replace("_", " ") target_spaced = target.name.replace("_", " ") if event_type == "random": random_event = random.choices( [ "the Inoshishi bandits are raiding!", "a yokai outbreak runs rampant!", "a mysterious disease sweeps over the two states!", "the states are blessed with a bountiful harvest!", "a prophesized event occurs." ], k=1 )[0] print( f"Resolve the following random event involving {initiator_spaced} and {target_spaced}: {random_event}" ) else: print( f"Resolve a {event_type} event " f"from {initiator_spaced} to {target_spaced}." ) def aishiji_initialization(): aishiji = World() lake_buiji = State( name="Lake_Buiji", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Hakuboya": RelationType.NEUTRAL, }, neighbors = { "Shiramori": RelationType.UNDEFINED, "Rumshof": RelationType.UNDEFINED, "Hishoryuiki": RelationType.NEUTRAL, "Infuku_no_Kuni": RelationType.HOSTILE, "Tsukigo": RelationType.UNDEFINED, "Yodomi": RelationType.NEUTRAL, } ) yodomi = State( name="Yodomi", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Tsukigo": RelationType.UNDEFINED, "Lake_Buiji": RelationType.NEUTRAL, "Infuku_no_Kuni": RelationType.NEUTRAL, "Sanjo": RelationType.HOSTILE, "New_Merovingia": RelationType.FRIENDLY, } ) tsukigo = State( name="Tsukigo", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Shiramori": RelationType.FRIENDLY, "Lake_Buiji": RelationType.UNDEFINED, "Yodomi": RelationType.UNDEFINED, "New_Merovingia": RelationType.UNDEFINED, "Avysos": RelationType.UNDEFINED, } ) avysos = State( name="Avysos", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Sanko": RelationType.HOSTILE, }, neighbors = { "Shiramori": RelationType.FRIENDLY, "Tsukigo": RelationType.UNDEFINED, "New_Merovingia": RelationType.FRIENDLY, "Tatsu-no-Umi-no-Kuni": RelationType.HOSTILE, } ) shiramori = State( name="Shiramori", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Kasumidani": RelationType.FRIENDLY, "Rumshof": RelationType.HOSTILE, "Lake_Buiji": RelationType.UNDEFINED, "Tsukigo": RelationType.FRIENDLY, "Avysos": RelationType.FRIENDLY, } ) new_merovingia = State( name="New_Merovingia", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Sanko": RelationType.HOSTILE, }, neighbors = { "Tsukigo": RelationType.UNDEFINED, "Yodomi": RelationType.FRIENDLY, "Sanjo": RelationType.HOSTILE, "Khotai": RelationType.NEUTRAL, "Tatsu-no-Umi-no-Kuni": RelationType.HOSTILE, "Avysos": RelationType.FRIENDLY, } ) khotai = State( name="Khotai", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "The_Crimson_Horde": RelationType.FRIENDLY, }, neighbors = { "New_Merovingia": RelationType.NEUTRAL, "Sanjo": RelationType.UNDEFINED, "Shiki-Shima_Archipelago": RelationType.UNDEFINED, "Tatsu-no-Umi-no-Kuni": RelationType.FRIENDLY, } ) sanjo = State( name="Sanjo", military_strength=MilitaryStrength.FULL, resources=Resources.STRAINED, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Yodomi": RelationType.HOSTILE, "Infuku_no_Kuni": RelationType.HOSTILE, "Shinitaru_Island": RelationType.UNDEFINED, "Shiki-Shima_Archipelago": RelationType.UNDEFINED, "Khotai": RelationType.UNDEFINED, "New_Merovingia": RelationType.HOSTILE, } ) tatsunouminokuni = State( name="Tatsu-no-Umi-no-Kuni", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Hakuboya": RelationType.HOSTILE, "Ripira_Mosir": RelationType.FRIENDLY, }, neighbors = { "Avysos": RelationType.FRIENDLY, "New_Merovingia": RelationType.HOSTILE, "Khotai": RelationType.FRIENDLY, } ) infukunokuni = State( name="Infuku_no_Kuni", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Sanko": RelationType.NEUTRAL, "Akujima": RelationType.FRIENDLY, }, neighbors = { "Lake_Buiji": RelationType.HOSTILE, "Hishoryuiki": RelationType.FRIENDLY, "Fukyuufumetsu": RelationType.HOSTILE, "Shinitaru_Island": RelationType.FRIENDLY, "Shiki-Shima_Archipelago": RelationType.NEUTRAL, "Sanjo": RelationType.HOSTILE, "Yodomi": RelationType.NEUTRAL, } ) hishoryuiki = State( name="Hishoryuiki", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Akujima": RelationType.FRIENDLY, }, neighbors = { "Rumshof": RelationType.HOSTILE, "Meirin_Sanmyaku": RelationType.FRIENDLY, "Fukyuufumetsu": RelationType.UNDEFINED, "Infuku no Kuni": RelationType.FRIENDLY, "Lake_Buiji": RelationType.NEUTRAL, } ) rumshof = State( name="Rumshof", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Kasumidani": RelationType.HOSTILE, "Meirin_Sanmyaku": RelationType.HOSTILE, "Hishoryuiki": RelationType.HOSTILE, "Lake_Buiji": RelationType.UNDEFINED, "Shiramori": RelationType.HOSTILE, } ) fukyuufumetsu = State( name="Fukyuufumetsu", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Meirin_Sanmyaku": RelationType.UNDEFINED, "Ripira_Mosir": RelationType.FRIENDLY, "Akujima": RelationType.UNDEFINED, "Shiki-Shima_Archipelago": RelationType.UNDEFINED, "Shinitaru_Island": RelationType.FRIENDLY, "Infuku_no_Kuni": RelationType.HOSTILE, "Hishoryuiki": RelationType.UNDEFINED, } ) meirin_sanmyaku = State( name="Meirin_Sanmyaku", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Solmaren": RelationType.UNDEFINED, "The_Crimson_Horde": RelationType.NEUTRAL, "Ripira_Mosir": RelationType.FRIENDLY, "Fukyuufumetsu": RelationType.UNDEFINED, "Hishoryuiki": RelationType.FRIENDLY, "Rumshof": RelationType.HOSTILE, "Kasumidani": RelationType.UNDEFINED, } ) kasumidani = State( name="Kasumidani", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.DEAD, momentum=Momentum.STABLE, relations = { }, neighbors = { "Hakuboya": RelationType.FRIENDLY, "Solmaren": RelationType.UNDEFINED, "Meirin_Sanmyaku": RelationType.UNDEFINED, "Rumshof": RelationType.FRIENDLY, "Shiramori": RelationType.FRIENDLY, } ) ripira_mosir = State( name="Ripira_Mosir", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Tatsu-no-Umi-no-Kuni": RelationType.FRIENDLY, "Sanko": RelationType.FRIENDLY, }, neighbors = { "The_Crimson_Horde": RelationType.UNDEFINED, "Arugin": RelationType.FRIENDLY, "Akujima": RelationType.NEUTRAL, "Shiki-Shima_Archipelago": RelationType.FRIENDLY, "Fukyuufumetsu": RelationType.FRIENDLY, "Meirin_Sanmyaku": RelationType.FRIENDLY, } ) arugin = State( name="Arugin", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.DECLINING, relations = { "Shinitaru_Island": RelationType.FRIENDLY, }, neighbors = { "Sanko": RelationType.HOSTILE, "Akujima": RelationType.NEUTRAL, "Ripira_Mosir": RelationType.FRIENDLY, "The_Crimson_Horde": RelationType.FRIENDLY, } ) crimson_horde = State( name="The_Crimson_Horde", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Khotai": RelationType.FRIENDLY, "Hakuboya": RelationType.FRIENDLY, }, neighbors = { "Sanko": RelationType.FRIENDLY, "Arugin": RelationType.FRIENDLY, "Ripira_Mosir": RelationType.UNDEFINED, "Meirin_Sanmyaku": RelationType.NEUTRAL, "Solmaren": RelationType.UNDEFINED, } ) sanko = State( name="Sanko", military_strength=MilitaryStrength.FULL, resources=Resources.SUFFICIENT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Avysos": RelationType.HOSTILE, "New_Merovingia": RelationType.HOSTILE, "Infuku_no_Kuni": RelationType.NEUTRAL, "Ripira_Mosir": RelationType.FRIENDLY, }, neighbors = { "Arugin": RelationType.HOSTILE, "The_Crimson_Horde": RelationType.FRIENDLY, "Solmaren": RelationType.UNDEFINED, "Hakuboya": RelationType.NEUTRAL, } ) solmaren = State( name="Solmaren", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Hakuboya": RelationType.FRIENDLY, "Sanko": RelationType.UNDEFINED, "The_Crimson_Horde": RelationType.UNDEFINED, "Meirin_Sanmyaku": RelationType.UNDEFINED, "Kasumidani": RelationType.UNDEFINED, } ) hakuboya = State( name="Hakuboya", military_strength=MilitaryStrength.FULL, resources=Resources.SUFFICIENT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Lake_Buiji": RelationType.NEUTRAL, "Tatsu-no-Umi-no-Kuni": RelationType.HOSTILE, "The_Crimson_Horde": RelationType.FRIENDLY, }, neighbors = { "Sanko": RelationType.NEUTRAL, "Solmaren": RelationType.FRIENDLY, "Kasumidani": RelationType.FRIENDLY, } ) shikishima = State( name="Shiki-Shima_Archipelago", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { }, neighbors = { "Infuku_no_Kuni": RelationType.NEUTRAL, "Fukyuufumetsu": RelationType.UNDEFINED, "Ripira_Mosir": RelationType.UNDEFINED, "Khotai": RelationType.UNDEFINED, "Sanjo": RelationType.UNDEFINED, "Shinitaru_Island": RelationType.NEUTRAL, "Akujima": RelationType.UNDEFINED, } ) shinitaru = State( name="Shinitaru_Island", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Ripira_Mosir": RelationType.FRIENDLY, "Arugin": RelationType.FRIENDLY, }, neighbors = { "Fukyuufumetsu": RelationType.FRIENDLY, "Akujima": RelationType.UNDEFINED, "Sanjo": RelationType.UNDEFINED, "Infuku-no-Kuni": RelationType.FRIENDLY, "Shiki-Shima_Archipelago": RelationType.NEUTRAL, } ) akujima = State( name="Akujima", military_strength=MilitaryStrength.FULL, resources=Resources.ABUNDANT, leader_status=LeaderStatus.COMMANDING, momentum=Momentum.STABLE, relations = { "Infuku_no_Kuni": RelationType.FRIENDLY, "Hishoryuiki": RelationType.FRIENDLY, }, neighbors = { "Arugin": RelationType.NEUTRAL, "Shiki-Shima_Archipelago": RelationType.UNDEFINED, "Shinitaru_Island": RelationType.UNDEFINED, "Fukyuufumetsu": RelationType.UNDEFINED, "Ripira_Mosir": RelationType.NEUTRAL, } ) aishiji.add_state(lake_buiji) aishiji.add_state(yodomi) aishiji.add_state(tsukigo) aishiji.add_state(avysos) aishiji.add_state(shiramori) aishiji.add_state(new_merovingia) aishiji.add_state(khotai) aishiji.add_state(sanjo) aishiji.add_state(tatsunouminokuni) aishiji.add_state(infukunokuni) aishiji.add_state(hishoryuiki) aishiji.add_state(rumshof) aishiji.add_state(fukyuufumetsu) aishiji.add_state(meirin_sanmyaku) aishiji.add_state(kasumidani) aishiji.add_state(ripira_mosir) aishiji.add_state(arugin) aishiji.add_state(crimson_horde) aishiji.add_state(sanko) aishiji.add_state(solmaren) aishiji.add_state(hakuboya) aishiji.add_state(shikishima) aishiji.add_state(shinitaru) aishiji.add_state(akujima) return aishiji def main(): world = aishiji_initialization() # Optional debug output world.print_state_table() print( "\nCommands:\n" "show: Show world table\n" "events [number]: Generate [number] events\n" "getstate [state_name]: Show all variables and relations of [state]\n" "set [state_name] [attribute] [value]: Set [attribute] of state [state_name] to [value] (available attributes: military_strength, resources, leader_status, momentum) \n" "relation [state_name_1] [state_name_2] [value]: Set the relation from [state_name_1] towards [state_name_2] to [value] (available types: friendly, neutral, undefined, hostile)\n" "delrelation [state_name_1] [state_name_2] [value]: Delete the relation [state_name_1] -> [state_name_2]\n" "debug: Toggle debug mode (show relation and event weights)\n" "quit: End the script\n\n" "Note: states with spaces in their name should use underscores instead." ) while True: command = input("\n> ").strip() if command == "quit": break elif command == "help": print( "Commands:\n" "show: Show world table\n" "events [number]: Generate [number] events\n" "getstate [state_name]: Show all variables and relations of [state]\n" "set [state_name] [attribute] [value]: Set [attribute] of state [state_name] to [value] (available attributes: military_strength, resources, leader_status, momentum) \n" "relation [state_name_1] [state_name_2] [value]: Set the relation [state_name_1] -> [state_name_2] to [value] (available types: friendly, neutral, undefined, hostile)\n" "delrelation [state_name_1] [state_name_2] [value]: Delete the relation [state_name_1] -> [state_name_2]\n" "debug: Toggle debug mode (show relation and event weights)\n" "quit: End the script\n\n" "Note: states with spaces in their name should use underscores instead." ) elif command == "show": world.print_state_table() elif command.startswith("events"): parts = command.split() if len(parts) == 2: num_events = int(parts[1]) else: num_events = 3 generate_events(world, num_events) elif command.startswith("getstate"): parts = command.split() if len(parts) != 2: print("Usage: getstate ") continue try: world.print_state(parts[1]) except KeyError: print("State not found. Note: states with spaces in their name should use underscores instead.") continue elif command.startswith("set"): parts = command.split() state_name = parts[1] attribute = parts[2] if attribute == "military_strength": try: value = MilitaryStrength[parts[3].upper()] except KeyError: print("Invalid military type.") continue elif attribute == "resources": try: value = Resources[parts[3].upper()] except KeyError: print("Invalid resources type.") continue elif attribute == "leader_status": try: value = LeaderStatus[parts[3].upper()] except KeyError: print("Invalid leader status type.") continue elif attribute == "momentum": try: value = Momentum[parts[3].upper()] except KeyError: print("Invalid momentum type.") continue elif attribute == "ruled_by": try: value = world.get_state(parts[3]) except KeyError: print("State not found. Note: states with spaces in their name should use underscores instead.") continue try: state = world.get_state(state_name) if attribute != "ruled_by": setattr(state, attribute, value) else: setattr(state, attribute, value.name) print( f"{state_name} {attribute} set to {value.name}" ) except KeyError: print("Something went wrong, try again.") continue elif command.startswith("relation"): parts = command.split() if len(parts) < 3: print( "Usage: relation " "" ) continue state1 = parts[1] state2 = parts[2] try: relation = RelationType[parts[3].upper()] except KeyError: print("Invalid relation type.") continue try: world.set_relation( state1, state2, relation, ) print( f"{state1} -> {state2} set to " f"{relation.name}" ) except KeyError: print("One of the states is incorrect, try again.") continue elif command.startswith("delrelation"): parts = command.split() if len(parts) < 3: print( "Usage: delrelation " ) continue state1 = parts[1] state2 = parts[2] try: state = world.get_state(state1) state.relations.pop(state2, None) state.neighbors.pop(state2, None) print( f"Removed relationship " f"{state1} -> {state2}" ) except KeyError: print("One of the states is incorrect, try again.") continue elif command == "debug": if EVENT_CONFIG["debug"]: EVENT_CONFIG["debug"] = False print("Debug mode disabled.") else: EVENT_CONFIG["debug"] = True print("Debug mode enabled.") else: print("Unknown command. Try 'help' to see available commands") if __name__ == "__main__": main()