diff --git a/game_simulation/agents/agent.py b/game_simulation/agents/agent.py index 17b6aaf..fa29947 100644 --- a/game_simulation/agents/agent.py +++ b/game_simulation/agents/agent.py @@ -1,6 +1,11 @@ import random from utils.text_generation import generate, get_rating import networkx as nx +from utils.promt import prompt_meta +from utils.time import global_time +from utils.logs import log_output +from utils.states import locations, town_areas +from utils.configs import log_actions, log_plans, log_ratings, log_memories, print_locations, print_actions, print_plans, print_ratings, print_memories class Agent: @@ -54,22 +59,74 @@ def __init__(self, name, description, starting_location, world_graph, use_openai def __repr__(self): return f"Agent({self.name}, {self.description}, {self.location})" - def plan(self, global_time, prompt_meta): + def tick(self): + self.plan() + + if self.location not in log_output: + log_output[self.location] = "" + + if log_plans: + log_output[self.location] += f"{self.name} plans: {self.plans}\n" + if print_plans: + print(f"{self.name} plans: {self.plans}") + + agents = locations.get_location(self.location).get_people() + other_agents = [agent for agent in agents if agent.name != self.name] + action = self.execute_action() + + if log_actions: + log_output[self.location] += f"{self.name} action: {action}\n" + if print_actions: + print(f"{self.name} action: {action}") + + for other_agent in other_agents: + memory = f'[Time: {global_time}. Person: {self.name}. Memory: {action}]' + other_agent.memories.append(memory) + if log_memories: + log_output[self.location] += f"{other_agent.name} remembers: {memory}\n" + if print_memories: + print(f"{other_agent.name} remembers: {memory}") + + for agent in agents: + agent.compress_memories(global_time) + agent.rate_memories() + if log_ratings: + log_output[self.location] += f"{agent.name} memory ratings: {agent.memory_ratings}\n" + if print_ratings: + print(f"{agent.name} memory ratings: {agent.memory_ratings}") + + place_ratings = self.rate_locations() + + if log_ratings: + log_output[self.location] += f"=== UPDATED LOCATION RATINGS {global_time} FOR {self.name}===\n" + log_output[self.location] += f"{self.name} location ratings: {place_ratings}\n" + if print_ratings: + print(f"=== UPDATED LOCATION RATINGS {global_time} FOR {self.name}===\n") + print(f"{self.name} location ratings: {place_ratings}\n") + + old_location = self.location + + new_location_name = place_ratings[0][0] + self.move(new_location_name) + + if print_locations: + log_output[self.location] += f"=== UPDATED LOCATIONS AT TIME {global_time} FOR {self.name}===\n" + log_output[self.location] += f"{self.name} moved from {old_location} to {new_location_name}\n" + if print_ratings: + print(f"=== UPDATED LOCATIONS AT TIME {global_time} FOR {self.name}===\n") + print(f"{self.name} moved from {old_location} to {new_location_name}\n") + + return + + def plan(self,): """ Generates the agent's daily plan. - - Parameters: - ----------- - global_time : int - The current time in the simulation. - prompt_meta : str - The prompt used to generate the plan. """ prompt = "You are {}. The following is your description: {} You just woke up. What is your goal for today? Write it down in an hourly basis, starting at {}:00. Write only one or two very short sentences. Be very brief. Use at most 50 words.".format(self.name, self.description, str(global_time)) self.plans = generate(prompt_meta.format(prompt), self.use_openai) - def execute_action(self, other_agents, location, global_time, town_areas, prompt_meta): + def execute_action(self,): """Executes the agent's action based on their current situation and interactions with other agents. @@ -79,8 +136,6 @@ def execute_action(self, other_agents, location, global_time, town_areas, prompt A list of other Agent objects in the simulation. location : Location The current Location object where the agent is located. - global_time : int - The current time in the simulation. town_areas : dict A dictionary of Location objects representing different areas in the simulated environment. prompt_meta : str @@ -91,19 +146,20 @@ def execute_action(self, other_agents, location, global_time, town_areas, prompt action : str The action executed by the agent. """ + location = locations.get_location(self.location) + other_agents = [agent for agent in location.get_people() if agent.name != self.name] + people = [agent.name for agent in other_agents] - people = [agent.name for agent in other_agents if agent.location == location] - prompt = "You are {}. Your plans are: {}. You are currently in {} with the following description: {}. It is currently {}:00. The following people are in this area: {}. You can interact with them.".format(self.name, self.plans, location.name, town_areas[location.name], str(global_time), ', '.join(people)) - people_description = [f"{agent.name}: {agent.description}" for agent in other_agents if agent.location == location.name] + people_description = [f"{agent.name}: {agent.description}" for agent in other_agents] prompt += ' You know the following about people: ' + '. '.join(people_description) prompt += "What do you do in the next hour? Use at most 10 words to explain." action = generate(prompt_meta.format(prompt), self.use_openai) return action - def update_memories(self, other_agents, global_time, action_results): + def update_memories(self, other_agents, action_results): """ Updates the agent's memories based on their interactions with other agents. @@ -112,8 +168,6 @@ def update_memories(self, other_agents, global_time, action_results): ----------- other_agents : list A list of other Agent objects in the simulation. - global_time : int - The current time in the simulation. action_results : dict A dictionary of the results of each agent's action. """ @@ -122,7 +176,7 @@ def update_memories(self, other_agents, global_time, action_results): if agent.location == self.location: self.memories.append('[Time: {}. Person: {}. Memory: {}]\n'.format(str(global_time), agent.name, action_results[agent.name])) - def compress_memories(self, global_time, MEMORY_LIMIT=10): + def compress_memories(self, MEMORY_LIMIT=10): """ Compresses the agent's memories to a more manageable and relevant set. @@ -145,7 +199,7 @@ def compress_memories(self, global_time, MEMORY_LIMIT=10): memory_string_to_compress = '.'.join([a[0] for a in relevant_memories]) return '[Recollection at Time {}:00: {}]'.format(str(global_time), memory_string_to_compress) - def rate_memories(self, locations, global_time, prompt_meta): + def rate_memories(self,): """ Rates the agent's memories based on their relevance and importance. @@ -182,7 +236,7 @@ def rate_memories(self, locations, global_time, prompt_meta): return memory_ratings - def rate_locations(self, locations, global_time, prompt_meta): + def rate_locations(self,): """ Rates different locations in the simulated environment based on the agent's preferences and experiences. @@ -191,8 +245,6 @@ def rate_locations(self, locations, global_time, prompt_meta): ----------- locations : Locations The Locations object representing different areas in the simulated environment. - global_time : int - The current time in the simulation. prompt_meta : str The prompt used to rate the locations. diff --git a/game_simulation/locations/locations.py b/game_simulation/locations/locations.py index 8b57310..c9c8b25 100644 --- a/game_simulation/locations/locations.py +++ b/game_simulation/locations/locations.py @@ -18,10 +18,21 @@ class Location: def __init__(self, name, description): self.name = name self.description = description + self.people = [] def __str__(self): return self.name + def add_people(self, people): + if isinstance(people, list): + self.people = self.people + people + else: + self.people = self.people + [people] + + def get_people(self): + return self.people + + def describe(self): print(self.description) @@ -52,6 +63,9 @@ def __init__(self): def add_location(self, name, description): self.locations[name] = Location(name, description) + def get_locations(self): + return self.locations + def get_location(self, name): return self.locations.get(name) diff --git a/game_simulation/main.py b/game_simulation/main.py index a67b343..7af3c50 100644 --- a/game_simulation/main.py +++ b/game_simulation/main.py @@ -1,71 +1,22 @@ -import json -import networkx as nx -from agents.agent import Agent -from locations.locations import Locations -from utils.text_generation import summarize_simulation - -# Set default value for prompt_meta if not defined elsewhere -prompt_meta = '### Instruction:\n{}\n### Response:' - -# Initialize global time and simulation variables -global_time = 0 -repeats = 5 - -log_locations = False -log_actions = True -log_plans = False -log_ratings = False -log_memories = False - -print_locations = True -print_actions = True -print_plans = True -print_ratings = True -print_memories = False - -use_openai=True - -# Start simulation loop -whole_simulation_output = "" -# Load town areas and people from JSON file -with open('simulation_config.json', 'r') as f: - town_data = json.load(f) -town_people = town_data['town_people'] -town_areas = town_data['town_areas'] - -# Create world_graph -world_graph = nx.Graph() -last_town_area = None -for town_area in town_areas.keys(): - world_graph.add_node(town_area) - world_graph.add_edge(town_area, town_area) # Add an edge to itself - if last_town_area is not None: - world_graph.add_edge(town_area, last_town_area) - last_town_area = town_area - -# Add the edge between the first and the last town areas to complete the cycle -world_graph.add_edge(list(town_areas.keys())[0], last_town_area) +from utils.text_generation import summarize_simulation +from utils.time import global_time +from utils.logs import log_output +from utils.states import locations, whole_simulation_output, town_areas, town_people, world_graph +from utils.configs import repeats, log_locations, print_locations, use_openai +from agents.agent import Agent # Initialize agents and locations -agents = [] -locations = Locations() - +for name, description in town_areas.items(): + locations.add_location(name, description) for name, description in town_people.items(): starting_location = description['starting_location'] - agents.append(Agent(name, description['description'], starting_location, world_graph, use_openai)) - -for name, description in town_areas.items(): - locations.add_location(name, description) + agent = Agent(name, description['description'], starting_location, world_graph, use_openai) + locations.get_location(starting_location).add_people(agent) for repeat in range(repeats): - #log_output for one repeat - log_output = "" - - print(f"====================== REPEAT {repeat} ======================\n") - log_output += f"====================== REPEAT {repeat} ======================\n" if log_locations: log_output += f"=== LOCATIONS AT START OF REPEAT {repeat} ===\n" log_output += str(locations) + "\n" @@ -73,71 +24,19 @@ print(f"=== LOCATIONS AT START OF REPEAT {repeat} ===") print(str(locations) + "\n") - # Plan actions for each agent - for agent in agents: - agent.plan(global_time, prompt_meta) - if log_plans: - log_output += f"{agent.name} plans: {agent.plans}\n" - if print_plans: - print(f"{agent.name} plans: {agent.plans}") - - # Execute planned actions and update memories - for agent in agents: - # Execute action - action = agent.execute_action(agents, locations.get_location(agent.location), global_time, town_areas, prompt_meta) - if log_actions: - log_output += f"{agent.name} action: {action}\n" - if print_actions: - print(f"{agent.name} action: {action}") - - # Update memories - for other_agent in agents: - if other_agent != agent: - memory = f'[Time: {global_time}. Person: {agent.name}. Memory: {action}]' - other_agent.memories.append(memory) - if log_memories: - log_output += f"{other_agent.name} remembers: {memory}\n" - if print_memories: - print(f"{other_agent.name} remembers: {memory}") - - # Compress and rate memories for each agent - for agent in agents: - agent.compress_memories(global_time) - agent.rate_memories(locations, global_time, prompt_meta) - if log_ratings: - log_output += f"{agent.name} memory ratings: {agent.memory_ratings}\n" - if print_ratings: - print(f"{agent.name} memory ratings: {agent.memory_ratings}") - - # Rate locations and determine where agents will go next - for agent in agents: - place_ratings = agent.rate_locations(locations, global_time, prompt_meta) - if log_ratings: - log_output += f"=== UPDATED LOCATION RATINGS {global_time} FOR {agent.name}===\n" - log_output += f"{agent.name} location ratings: {place_ratings}\n" - if print_ratings: - print(f"=== UPDATED LOCATION RATINGS {global_time} FOR {agent.name}===\n") - print(f"{agent.name} location ratings: {place_ratings}\n") - - old_location = agent.location - - new_location_name = place_ratings[0][0] - agent.move(new_location_name) - - if print_locations: - log_output += f"=== UPDATED LOCATIONS AT TIME {global_time} FOR {agent.name}===\n" - log_output += f"{agent.name} moved from {old_location} to {new_location_name}\n" - if print_ratings: - print(f"=== UPDATED LOCATIONS AT TIME {global_time} FOR {agent.name}===\n") - print(f"{agent.name} moved from {old_location} to {new_location_name}\n") - - print(f"----------------------- SUMMARY FOR REPEAT {repeat} -----------------------") - - print(summarize_simulation(log_output=log_output)) - - whole_simulation_output += log_output + # Plan actions for each location and agent + for location_key in locations.get_locations(): + print(f"====================== {location_key} REPEAT {repeat} ======================\n") + log_output[location_key] = f"====================== {location_key} REPEAT {repeat} ======================\n" + location = locations.get_location(location_key) + for agent in location.get_people(): + agent.tick() + print(log_output[location_key]) + print(summarize_simulation(log_output=log_output[location_key])) + + whole_simulation_output += log_output[location_key] + print(f"----------------------- SUMMARY FOR REPEAT {repeat} -----------------------") - # Increment time global_time += 1 # Write log output to file diff --git a/game_simulation/simulation_config.json b/game_simulation/simulation_config.json index 631b0ad..028e7cc 100644 --- a/game_simulation/simulation_config.json +++ b/game_simulation/simulation_config.json @@ -1,33 +1,32 @@ { - "general": { - "global_time_limit": 24, - "max_attempts": 2, - "memory_limit": 10, - "prompt_meta": "### Instruction:\n{}\n### Response:" - }, - "town_areas": { - "Phandalin Town Square": "Town square of the town of Phandalin.", - "Stonehill Inn": "In the center of town stands a large, newly built roadhouse of fieldstone and rough-hewn timbers. The common room is filled with locals nursing mugs of ale or cider, all of them eyeing you with curiosity.", - "Barthen's Provisions": "Barthen’s is the biggest trading post in Phandalin. Its shelves stock most ordinary goods and supplies, including backpacks, bedrolls, rope, and rations. The place is open from sunup to sundown.", - "Edermath Orchard": "A tidy little cottage beside an apple orchard." - }, - "town_people": { - "Toblen Stonehill": { - "description": "Owns a trading post.", - "starting_location": "Stonehill Inn" - }, - "Daran Edermath": { - "description": "Daran Edermath is a retired adventurer who lives in a tidy little cottage beside an apple orchard. A fit, silver-haired half-elf well over a hundred years old, Daran is a fighter who served as a marshal and herald for many years in the lands of the Dragon Coast, far to the southeast. Upon retiring, he returned to the Neverwinter region, his original home.", - "starting_location": "Edermath Orchard" - }, - "Linene Graywind": { - "description": "Runs a trading post.", - "starting_location": "Barthen's Provisions" - }, - "Halia Thornton": { - "description": "An ambitious and calculating human woman. She is the guildmaster of Phandalin Miner’s Exchange, a trading post where local miners have their valuable finds weighed, measured, and paid out. In her attempts to establish the Miner's Exchange as the closest thing the town has to a governing authority, she acts as more than a simple merchant.", - "starting_location": "Phandalin Town Square" - } + "general": { + "global_time_limit": 24, + "max_attempts": 2, + "memory_limit": 10, + "prompt_meta": "### Instruction:\n{}\n### Response:" + }, + "town_areas": { + "Pittsburgh Town Square": "Town square of the town of Pittsburgh.", + "Stonehill Inn": "In the center of town stands a large, newly built roadhouse of fieldstone and rough-hewn timbers. The common room is filled with locals nursing mugs of ale or cider, all of them eyeing you with curiosity.", + "Barthen's Provisions": "Barthen’s is the biggest trading post in Pittsburgh. Its shelves stock most ordinary goods and supplies, including backpacks, bedrolls, rope, and rations. The place is open from sunup to sundown.", + "Edermath Orchard": "A tidy little cottage beside an apple orchard." + }, + "town_people": { + "Alexa": { + "description": "Owns a book store in town. Always wants know more", + "starting_location": "Stonehill Inn" + }, + "Daran Edermath": { + "description": "Daran Edermath is a retired adventurer who lives in a tidy little cottage beside an apple orchard. A fit, silver-haired half-elf well over a hundred years old, Daran is a fighter who served as a marshal and herald for many years in the lands of the Dragon Coast, far to the southeast. Upon retiring, he returned to the Neverwinter region, his original home.", + "starting_location": "Stonehill Inn" + }, + "Sam": { + "description": "Sam is an Architect and loves to help the city expand", + "starting_location": "Barthen's Provisions" + }, + "Halia Thornton": { + "description": "An ambitious and calculating human woman. She is the guildmaster of Pittsburgh Miner’s Exchange, a trading post where local miners have their valuable finds weighed, measured, and paid out. In her attempts to establish the Miner's Exchange as the closest thing the town has to a governing authority, she acts as more than a simple merchant.", + "starting_location": "Pittsburgh Town Square" } + } } - \ No newline at end of file diff --git a/game_simulation/simulation_log.txt b/game_simulation/simulation_log.txt index 81a127e..1738957 100644 --- a/game_simulation/simulation_log.txt +++ b/game_simulation/simulation_log.txt @@ -1,65 +1,74 @@ ====================== REPEAT 0 ====================== -Toblen Stonehill action: I get out of bed and have breakfast. Then, I go to the market to buy supplies for the trading post. After that, I arrive at the trading post and unload the supplies. Finally, I start trading. -Daran Edermath action: Daran wakes up and starts his day by making breakfast, then going for a walk in the apple orchard. He works on a new painting for a while before making lunch and writing a letter to an old friend. In the afternoon, he takes a walk in the woods before making dinner and reading a book before bed. -Linene Graywind action: I get out of bed and make breakfast. Then I go to the trading post and start trading. -Halia Thornton action: I will wake up and get dressed. I will have breakfast. I will go to the Miner's Exchange. I will work on establishing the Exchange as a governing authority. I will have dinner. I will go to bed. -=== UPDATED LOCATIONS AT TIME 0 FOR Toblen Stonehill=== -Toblen Stonehill moved from Stonehill Inn to Stonehill Inn +Alexa action: In the next hour, I wake up, make coffee, check inventory, place orders for new books, check social media, and close up shop. +Daran Edermath action: I will wake up and have breakfast. Then, I will go for a walk in the orchard. +Sam action: I wake up and have breakfast. Then, I go to work and start my new city expansion project. I meet with clients and go home for dinner. Finally, I relax for the rest of the night. +Halia Thornton action: I will check on the miners at the Exchange, meet with the blacksmith, visit the tavern, send a message to the mayor, and go for a walk around town. +=== UPDATED LOCATIONS AT TIME 0 FOR Alexa=== +Alexa moved from Stonehill Inn to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 0 FOR Daran Edermath=== -Daran Edermath moved from Edermath Orchard to Edermath Orchard -=== UPDATED LOCATIONS AT TIME 0 FOR Linene Graywind=== -Linene Graywind moved from Barthen's Provisions to Barthen's Provisions +Daran Edermath moved from Edermath Orchard to Pittsburgh Town Square +=== UPDATED LOCATIONS AT TIME 0 FOR Sam=== +Sam moved from Barthen's Provisions to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 0 FOR Halia Thornton=== -Halia Thornton moved from Phandalin Town Square to Phandalin Town Square +Halia Thornton moved from Pittsburgh Town Square to Pittsburgh Town Square ====================== REPEAT 1 ====================== -Toblen Stonehill action: I wake up, get dressed, and go to my trading post. -Daran Edermath action: I wake up and make breakfast. I then go for a walk in the woods and work on a jigsaw puzzle. I make dinner and watch the sunset. I read a book and then go to bed. -Linene Graywind action: I wake up at 1:00 and get out of bed. I take a shower at 2:00 and get dressed at 3:00. I eat breakfast at 4:00 and then go to work at 5:00. I open the store at 6:00 and help customers until 9:00. I do paperwork until 10:00 and then close the store. I go home at 11:00 and eat lunch at 12:00. I take a nap at 1:00 and then get up at 2:00. I make dinner at 3:00 and eat dinner at 4:00. I watch TV at 5:00 and then go to bed at 6:00. -Halia Thornton action: I will go to the Miner's Exchange and work on establishing it as the governing authority of Phandalin. -=== UPDATED LOCATIONS AT TIME 1 FOR Toblen Stonehill=== -Toblen Stonehill moved from Stonehill Inn to Stonehill Inn +Alexa action: I wake up and get out of bed. I make breakfast and then go to the book store. I work on inventory and help customers. I close up shop and then go home. I relax and then go to bed. +Daran Edermath action: 1:00: Get out of bed. +2:00: Eat breakfast. +3:00: Go for a walk in the apple orchard. +4:00: Work on some gardening. +5:00: Make lunch. +6:00: Take a nap. +7:00: Check the mailbox. +8:00: Make dinner. +9:00: Read a book. +10:00: Go to bed. +Sam action: I work on the design for the new city expansion. +Halia Thornton action: I will establish the Miner's Exchange as the closest thing the town has to a governing authority. I will get the local miners to bring their valuable finds to the Exchange. I will weigh, measure, and pay out the miners' finds. I will establish the Exchange as the go-to place for all things mining-related. +=== UPDATED LOCATIONS AT TIME 1 FOR Alexa=== +Alexa moved from Pittsburgh Town Square to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 1 FOR Daran Edermath=== -Daran Edermath moved from Edermath Orchard to Edermath Orchard -=== UPDATED LOCATIONS AT TIME 1 FOR Linene Graywind=== -Linene Graywind moved from Barthen's Provisions to Barthen's Provisions +Daran Edermath moved from Pittsburgh Town Square to Pittsburgh Town Square +=== UPDATED LOCATIONS AT TIME 1 FOR Sam=== +Sam moved from Pittsburgh Town Square to Stonehill Inn === UPDATED LOCATIONS AT TIME 1 FOR Halia Thornton=== -Halia Thornton moved from Phandalin Town Square to Phandalin Town Square +Halia Thornton moved from Pittsburgh Town Square to Stonehill Inn ====================== REPEAT 2 ====================== -Toblen Stonehill action: I wake up and get breakfast at the tavern. I go to the stables and check on the animals. I go to the market and see what's new. I go back to the trading post and start working. I take a break for dinner. I finish up work for the day. I go to the tavern for a drink. I go to bed. -Daran Edermath action: Daran Edermath wakes up at 2:00 and eats breakfast at 2:30. He goes for a walk in the apple orchard at 3:00 and works on some gardening at 4:00. He makes dinner at 5:00 and relaxes and reads a book at 6:00. He goes to bed at 7:00. -Linene Graywind action: I wake up at 2:00 and get dressed at 2:30. I eat breakfast at 3:00 and start work at 4:00. I check inventory at 5:00 and help customers at 6:00. I close up shop at 7:00. -Halia Thornton action: Get out of bed, have breakfast, go over today's goals, meet with Sildar, train with sword, check on miners, eat dinner, go over today's events, go to bed. -=== UPDATED LOCATIONS AT TIME 2 FOR Toblen Stonehill=== -Toblen Stonehill moved from Stonehill Inn to Phandalin Town Square +Alexa action: I wake up at 2:00 and get ready for the day. At 3:00, I open my bookstore in Pittsburgh Town Square. I help customers find books until 4:00, when I close the store. +Daran Edermath action: I wake up and have breakfast, then go for a walk in the apple orchard. +Sam action: I help the city expand by working on plans and helping to build new structures. +Halia Thornton action: I wake up at 2:00 and get dressed at 2:30. I make breakfast at 3:00 and then head to the Miner's Exchange at 3:30. I arrive at the Miner's Exchange at 4:00 and begin work at 4:30. +=== UPDATED LOCATIONS AT TIME 2 FOR Alexa=== +Alexa moved from Pittsburgh Town Square to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 2 FOR Daran Edermath=== -Daran Edermath moved from Edermath Orchard to Edermath Orchard -=== UPDATED LOCATIONS AT TIME 2 FOR Linene Graywind=== -Linene Graywind moved from Barthen's Provisions to Barthen's Provisions +Daran Edermath moved from Pittsburgh Town Square to Pittsburgh Town Square +=== UPDATED LOCATIONS AT TIME 2 FOR Sam=== +Sam moved from Stonehill Inn to Stonehill Inn === UPDATED LOCATIONS AT TIME 2 FOR Halia Thornton=== -Halia Thornton moved from Phandalin Town Square to Stonehill Inn +Halia Thornton moved from Stonehill Inn to Stonehill Inn ====================== REPEAT 3 ====================== -Toblen Stonehill action: I wake up, eat breakfast, open the trading post, trade with customers, close the trading post, eat dinner, and go to bed. -Daran Edermath action: Daran Edermath gets out of bed and eats breakfast. He then goes for a walk in the apple orchard, checking on the apple trees. After lunch, he relaxes for a bit before going to bed. -Linene Graywind action: I get out of bed and get breakfast. I start work at 4:00 and take a break at 5:00. I eat dinner at 6:00 and relax at 7:00. -Halia Thornton action: I wake up and get dressed. I arrive at the Miner's Exchange at 4:00 and begin work. -=== UPDATED LOCATIONS AT TIME 3 FOR Toblen Stonehill=== -Toblen Stonehill moved from Phandalin Town Square to Phandalin Town Square +Alexa action: I get out of bed and take a shower. I eat breakfast and then go to the bookstore. I stock shelves and help customers until the store closes. Then I go home and make dinner. +Daran Edermath action: I get out of bed, eat breakfast, go for a walk in the apple orchard, work on some gardening, make dinner, read a book, and go to bed. +Sam action: I wake up at 3:00 and get out of bed at 3:30. I start work on my new project at 4:00 and take a break at 5:00. I finish work on my new project at 6:00 and go to bed at 7:00. +Halia Thornton action: Work on establishing the Miner's Exchange as the primary source of trade in the town. +=== UPDATED LOCATIONS AT TIME 3 FOR Alexa=== +Alexa moved from Pittsburgh Town Square to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 3 FOR Daran Edermath=== -Daran Edermath moved from Edermath Orchard to Edermath Orchard -=== UPDATED LOCATIONS AT TIME 3 FOR Linene Graywind=== -Linene Graywind moved from Barthen's Provisions to Stonehill Inn +Daran Edermath moved from Pittsburgh Town Square to Stonehill Inn +=== UPDATED LOCATIONS AT TIME 3 FOR Sam=== +Sam moved from Stonehill Inn to Stonehill Inn === UPDATED LOCATIONS AT TIME 3 FOR Halia Thornton=== -Halia Thornton moved from Stonehill Inn to Phandalin Town Square +Halia Thornton moved from Stonehill Inn to Pittsburgh Town Square ====================== REPEAT 4 ====================== -Toblen Stonehill action: I look for signs of the bandits. -Daran Edermath action: I wake up at 4:00 AM and eat breakfast at 5:00 AM. I go for a walk at 6:00 AM and check the traps at 7:00 AM. I go to town at 8:00 AM and buy groceries at 9:00 AM. I talk to the villagers at 10:00 AM and go home at 11:00 AM. I make lunch at 12:00 PM and eat lunch at 1:00 PM. I take a nap at 2:00 PM and wake up at 3:00 PM. I check the traps at 4:00 PM, go for a walk at 5:00 PM, and go to town at 6:00 PM. I talk to the villagers at 7:00 PM and go home at 8:00 PM. I make dinner at 9:00 PM and eat dinner at 10:00 PM. I go to bed at 11:00 PM. -Linene Graywind action: I wake up and get dressed. I make breakfast and then open the trading post. I start trading with customers and take a break at 9:00. I continue trading and then close the trading post at 11:00. I eat lunch and then rest for an hour. I prepare for tomorrow and then go to bed. -Halia Thornton action: I go to the Miner's Exchange. -=== UPDATED LOCATIONS AT TIME 4 FOR Toblen Stonehill=== -Toblen Stonehill moved from Phandalin Town Square to Stonehill Inn +Alexa action: I wake up at 5:00 and make breakfast. I go to the bookstore at 6:00 and help customers at 8:00. I close the store at 10:00. +Daran Edermath action: I wake up and have breakfast. I go for a walk in the orchard. I work on a new song. I make lunch. I work in the garden. I practice swordplay. I check the traps for game. I make a list of things to do tomorrow. +Sam action: I work on city expansion plans. +Halia Thornton action: I wake up and get dressed. I go to the Miner's Exchange and open for business. I weigh and measure the miners' findings. I pay the miners for their findings. I close the Miner's Exchange for the day. +=== UPDATED LOCATIONS AT TIME 4 FOR Alexa=== +Alexa moved from Pittsburgh Town Square to Barthen's Provisions === UPDATED LOCATIONS AT TIME 4 FOR Daran Edermath=== -Daran Edermath moved from Edermath Orchard to Barthen's Provisions -=== UPDATED LOCATIONS AT TIME 4 FOR Linene Graywind=== -Linene Graywind moved from Stonehill Inn to Stonehill Inn +Daran Edermath moved from Stonehill Inn to Edermath Orchard +=== UPDATED LOCATIONS AT TIME 4 FOR Sam=== +Sam moved from Stonehill Inn to Pittsburgh Town Square === UPDATED LOCATIONS AT TIME 4 FOR Halia Thornton=== -Halia Thornton moved from Phandalin Town Square to Phandalin Town Square +Halia Thornton moved from Pittsburgh Town Square to Pittsburgh Town Square diff --git a/game_simulation/utils/configs.py b/game_simulation/utils/configs.py new file mode 100644 index 0000000..2d6fbe2 --- /dev/null +++ b/game_simulation/utils/configs.py @@ -0,0 +1,15 @@ +repeats = 5 + +log_locations = False +log_actions = True +log_plans = False +log_ratings = False +log_memories = False + +print_locations = True +print_actions = True +print_plans = True +print_ratings = True +print_memories = False + +use_openai=True \ No newline at end of file diff --git a/game_simulation/utils/logs.py b/game_simulation/utils/logs.py new file mode 100644 index 0000000..af81843 --- /dev/null +++ b/game_simulation/utils/logs.py @@ -0,0 +1,2 @@ +# this will contain history of all the logs for each scenes +log_output = {} \ No newline at end of file diff --git a/game_simulation/utils/promt.py b/game_simulation/utils/promt.py new file mode 100644 index 0000000..29df377 --- /dev/null +++ b/game_simulation/utils/promt.py @@ -0,0 +1 @@ +prompt_meta = '### Instruction:\n{}\n### Response:' diff --git a/game_simulation/utils/states.py b/game_simulation/utils/states.py new file mode 100644 index 0000000..71b1901 --- /dev/null +++ b/game_simulation/utils/states.py @@ -0,0 +1,29 @@ +import json +import networkx as nx +from locations.locations import Locations + +# Load town areas and people from JSON file +with open('simulation_config.json', 'r') as f: + town_data = json.load(f) + +town_people = town_data['town_people'] +town_areas = town_data['town_areas'] + +locations = Locations() + +# Create world_graph +world_graph = nx.Graph() +last_town_area = None +for town_area in town_areas.keys(): + world_graph.add_node(town_area) + world_graph.add_edge(town_area, town_area) # Add an edge to itself + if last_town_area is not None: + world_graph.add_edge(town_area, last_town_area) + last_town_area = town_area + +# Add the edge between the first and the last town areas to complete the cycle +world_graph.add_edge(list(town_areas.keys())[0], last_town_area) + +whole_simulation_output = "" + + diff --git a/game_simulation/utils/time.py b/game_simulation/utils/time.py new file mode 100644 index 0000000..ea50bcd --- /dev/null +++ b/game_simulation/utils/time.py @@ -0,0 +1 @@ +global_time = 0 \ No newline at end of file diff --git a/game_simulation/world/__init__.py b/game_simulation/world/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/game_simulation/world/spaces.py b/game_simulation/world/spaces.py new file mode 100644 index 0000000..171a197 --- /dev/null +++ b/game_simulation/world/spaces.py @@ -0,0 +1,65 @@ +class Space: + """ + A class to represent a space in the simulated environment. + + Attributes: + ---------- + name : str + The name of the space. + description : str + A brief description of the space. + + Methods: + ------- + describe(): + Prints the description of the space. + """ + + def __init__(self, name, description, shape="cube", scale=[1,1,1], position=[0,0,0]): + self.name = name + self.description = description + self.shape = shape + self.scale = scale + + + def __str__(self): + return self.name + + def describe(self): + print(self.description) + +class Spaces: + """ + A class to represent a collection of spaces in the simulated environment. + + Attributes: + ---------- + spaces : dict + A dictionary of spaces, with keys as the space names and values as space objects. + + Methods: + ------- + add_space(name, description): + Adds a new space to the collection. + + get_space(name): + Returns the space object with the given name. + + __str__(): + Returns a string representation of the collection of spaces. + """ + + def __init__(self): + self.spaces = {} + + def add_space(self, name, description): + self.spaces[name] = Space(name, description) + + def get_space(self, name): + return self.spaces.get(name) + + def __str__(self): + return '\n'.join([str(space) for space in self.spaces.values()]) + + +