AI Module
The AI module contains personality, character classes, goals, and decision-making.
Personality
- class simulation_framework.src.ai.personality.Personality(curiosity: 'float' = 0.5, bravery: 'float' = 0.5, sociability: 'float' = 0.5, greed: 'float' = 0.5, patience: 'float' = 0.5, aggression: 'float' = 0.3, industriousness: 'float' = 0.5, caution: 'float' = 0.5)[source]
Bases:
object
- classmethod create_archetype(archetype: str) Personality [source]
Create personality based on common archetypes
- get_action_modifier(action_type: str) float [source]
Get personality modifier for different action types
- get_dominant_traits(threshold: float = 0.6) list[str] [source]
Return traits that are above the threshold
- get_exploration_desire(known_area_percentage: float) float [source]
Calculate desire to explore based on how much is known
- classmethod randomize(seed: int | None = None) Personality [source]
- should_engage_in_combat(enemy_strength: float, own_strength: float, potential_loot_value: float = 0.0) bool [source]
Determine if agent should engage in combat
- should_initiate_trade(potential_profit: float, relationship: float = 0.5) bool [source]
Determine if agent should initiate a trade
- similarity_to(other: Personality) float [source]
Calculate similarity between two personalities (0-1, higher is more similar)
Character Class
- class simulation_framework.src.ai.character_class.CharacterClass(name: 'str', description: 'str', skill_affinities: 'Dict[str, float]' = <factory>, preferred_actions: 'List[str]' = <factory>, starting_stats_bonus: 'Dict[str, int]' = <factory>, equipment_preferences: 'List[str]' = <factory>)[source]
Bases:
object
- calculate_effectiveness(activity_type: str, skill_levels: Dict[str, int]) float [source]
Calculate how effective this class is at a given activity
- classmethod create_alchemist() CharacterClass [source]
- classmethod create_blacksmith() CharacterClass [source]
- classmethod create_explorer() CharacterClass [source]
- classmethod create_farmer() CharacterClass [source]
- classmethod create_hunter() CharacterClass [source]
- classmethod create_mage() CharacterClass [source]
- classmethod create_trader() CharacterClass [source]
- classmethod create_warrior() CharacterClass [source]
- class simulation_framework.src.ai.character_class.SkillType(value)[source]
Bases:
Enum
An enumeration.
- ARCHERY = 'archery'
- COMBAT = 'combat'
- CRAFTING = 'crafting'
- EXPLORATION = 'exploration'
- FISHING = 'fishing'
- FORAGING = 'foraging'
- MAGIC = 'magic'
- MINING = 'mining'
- TRADING = 'trading'
- WOODCUTTING = 'woodcutting'
- simulation_framework.src.ai.character_class.get_character_class(name: str) CharacterClass | None [source]
Get a character class by name
- simulation_framework.src.ai.character_class.get_random_character_class() CharacterClass [source]
Get a random character class
Goals
- class simulation_framework.src.ai.goal.AttackEnemyGoal(target_id: int, priority: int = 8)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.CraftItemGoal(item_name: str, quantity: int = 1, priority: int = 5)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.ExploreGoal(target_area: Tuple[int, int, int] | None = None, priority: int = 4)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.FleeFromDangerGoal(danger_source_id: int, priority: int = 9)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.GatherResourceGoal(resource_type: str, target_quantity: int = 10, priority: int = 6)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.Goal(priority: int = 5, name: str = 'Goal')[source]
Bases:
ABC
- get_estimated_duration(agent: Entity, world: World) int [source]
Estimate how many ticks this goal will take
- abstract get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- abstract get_utility(agent: Entity, world: World) float [source]
Calculate utility score for this goal (0-1)
- abstract is_complete(agent: Entity, world: World) bool [source]
Check if this goal has been completed
- abstract is_valid(agent: Entity, world: World) bool [source]
Check if this goal is still valid/achievable
- class simulation_framework.src.ai.goal.RestGoal(priority: int = 3)[source]
Bases:
Goal
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
- class simulation_framework.src.ai.goal.TradeGoal(target_id: int | None = None, offered_items: List[Tuple[str, int]] | None = None, requested_items: List[Tuple[str, int]] | None = None, priority: int = 5)[source]
Bases:
Goal
Goal for trading items with other entities
- get_next_action(agent: Entity, world: World) Action | None [source]
Get the next action to work towards this goal
Decision Maker
- class simulation_framework.src.ai.decision_maker.DecisionMaker[source]
Bases:
object
- evaluate_all_goals(agent: Entity, world: World, current_goals: List[Goal]) List[Tuple[Goal, float]] [source]
Evaluate utility of all possible goals
Spatial Memory
Spatial Memory System for Agent World Knowledge.
Agents remember explored tiles, resource locations, and entity sightings. Reduces need for constant world scanning.
- class simulation_framework.src.ai.spatial_memory.EntityMemory(entity_id: int, last_seen_position: Tuple[int, int], last_seen_tick: int, entity_type: str, was_hostile: bool = False)[source]
Bases:
object
Memory of another entity
- class simulation_framework.src.ai.spatial_memory.ResourceMemory(position: Tuple[int, int], resource_type: str, last_seen_tick: int, last_seen_quantity: int = 0, was_depleted: bool = False, depletion_tick: int = 0)[source]
Bases:
object
Memory of a resource location
- class simulation_framework.src.ai.spatial_memory.SpatialMemory(memory_duration: int = 100)[source]
Bases:
object
Agent’s memory of the world.
Stores information about: - Explored tiles - Known resource locations - Entity sightings - Terrain layout
- get_exploration_percentage(world_size: Tuple[int, int]) float [source]
Calculate percentage of world explored
- get_known_entity(entity_id: int) EntityMemory | None [source]
Get memory of an entity
- get_known_resources(resource_type: str, agent_position: Tuple[int, int], current_tick: int, max_age: int | None = None) List[Tuple[float, Tuple[int, int]]] [source]
Get known resource locations sorted by distance.
Returns list of (distance, position) tuples. Filters out old memories and known depleted resources.
- get_nearby_entities(agent_position: Tuple[int, int], max_distance: float, current_tick: int, max_age: int = 50) List[EntityMemory] [source]
Get memories of nearby entities
- get_nearest_known_resource(resource_type: str, agent_position: Tuple[int, int], current_tick: int) Tuple[int, int] | None [source]
Get nearest known resource position
- remember_entity(entity_id: int, position: Tuple[int, int], entity_type: str, was_hostile: bool, current_tick: int) None [source]
Remember seeing an entity