sgongora27 commited on
Commit
28deb4d
·
1 Parent(s): 81e0ed0

World 1 in English

Browse files
Files changed (3) hide show
  1. app.py +1 -0
  2. example_worlds.py +28 -37
  3. prompts.py +48 -21
app.py CHANGED
@@ -125,6 +125,7 @@ last_player_position = world.player.location
125
  number_of_turns = 0
126
  game_log_dictionary = {}
127
  game_log_dictionary["nickname"] = "anonymous"
 
128
  game_log_dictionary["world_id"] = world_id
129
  game_log_dictionary["narrative_model_name"] = narrative_model_name
130
  game_log_dictionary["reasoning_model_name"] = reasoning_model_name
 
125
  number_of_turns = 0
126
  game_log_dictionary = {}
127
  game_log_dictionary["nickname"] = "anonymous"
128
+ game_log_dictionary["language"] = language
129
  game_log_dictionary["world_id"] = world_id
130
  game_log_dictionary["narrative_model_name"] = narrative_model_name
131
  game_log_dictionary["reasoning_model_name"] = reasoning_model_name
example_worlds.py CHANGED
@@ -4,7 +4,7 @@ import random
4
  from world import Character, Item, Location, Puzzle, World
5
 
6
 
7
- def get_world(arg: str, language='en') -> World:
8
  if arg=='1':
9
  if language == 'es':
10
  return get_world_1_spanish()
@@ -111,61 +111,52 @@ def get_world_0_spanish() -> World:
111
  return the_world
112
 
113
  def get_world_1_english() -> World:
114
- item_1 = Item("Apple",
115
- ["A fruit that can be eaten", "It is round-shaped and red"])
116
  item_2 = Item("Key",
117
- ["A key to open a lock", "It is golden", "It is engraved with a strange coat of arms"])
118
- item_3 = Item("A grey Hammer",
119
- ["A great grey hammer that can be used to break things", "It is so heavy..."])
120
  item_4 = Item("Lock",
121
- ["A strong lock engraved with a coat of arms", "It seems that you cannot open it with your hands"])
122
- item_5 = Item("Note",
123
- ["A paper with a note", "You can read 'Go to the kitchen to know the truth'"])
124
- item_6 = Item("Flashlight",
125
- ["A flashlight without batteries"])
126
- item_7 = Item("A green Hammer",
127
- ["A small green hammer", "It is just a toy and you cannot break anything with it."])
128
- item_8 = Item("A wall of flames",
129
- ["The heat is really intense but it is a small fire anyway"])
130
- item_9 = Item("A metal flower",
131
- ["A strange flower"])
132
- item_10 = Item("A fire extinguisher",
133
- ["You can control small fires with this."])
134
 
135
  place_3 = Location ("Garden",
136
- ["A small garden below the kitchen"],
137
- items = [item_9])
138
  place_2 = Location("Kitchen",
139
- ["A beautiful well-lit kitchen"],
140
- items = [item_6,item_10])
141
  place_2.connecting_locations = [place_3]
142
- place_2.block_passage(place_3, item_8, symmetric=False)
 
143
 
144
- place_1 = Location("Cellar",
145
- ["There is a metal door locked by a lock", "You can see damp patches on the walls"],
146
- items = [item_2, item_3, item_5, item_7])
147
  place_1.connecting_locations = [place_2]
148
- place_1.block_passage(place_2, item_4)
149
 
150
- player = Character("Cid",
151
- ["A tall soldier"],
152
- inventory = [item_1],
153
  location = place_1)
154
- npc = Character("Elvira",
155
- ["A little girl", "Her favorite food is apple pie, but she enjoys eating any fruit", "She can't read yet"],
156
- location= place_1)
 
157
 
158
  the_world = World(player)
159
  the_world.add_locations([place_1,place_2,place_3])
160
- the_world.add_items([item_1,item_2,item_3,item_4,item_5,
161
- item_6, item_7,item_8, item_9, item_10])
162
  the_world.add_character(npc)
 
163
 
164
  return the_world
165
 
166
  def get_world_1_spanish() -> World:
167
 
168
- item_1 = Item("Tortuga",["La mascota de Emma", "Emma la llama 'Hojita'"])
169
  item_2 = Item("Llave",
170
  ["Una llave para abrir un candado", "Es dorada", "Tiene grabada la imagen de un extraño escudo de armas"])
171
  item_3 = Item("Un martillo gris",
 
4
  from world import Character, Item, Location, Puzzle, World
5
 
6
 
7
+ def get_world(arg: str, language: str ='en') -> World:
8
  if arg=='1':
9
  if language == 'es':
10
  return get_world_1_spanish()
 
111
  return the_world
112
 
113
  def get_world_1_english() -> World:
114
+
115
+ item_1 = Item("Turtle",["A small turtle", "Emma's pet", "Emma calls it 'Hojita'"])
116
  item_2 = Item("Key",
117
+ ["A key to open a lock", "It is golden", "There is a strange coat of arms engraved on it"])
118
+ item_3 = Item("A grey hammer",
119
+ ["A big grey hammer that can be used to break things", "It is so heavy..."])
120
  item_4 = Item("Lock",
121
+ ["A strong lock with a coat of arms engraved on it", "It seems that it cannot be opened with your bare hands"])
122
+ item_5 = Item("A green hammer",
123
+ ["A small green hammer", "It is just a toy and you cannot break anything with it"])
 
 
 
 
 
 
 
 
 
 
124
 
125
  place_3 = Location ("Garden",
126
+ ["The garden of the house", "It is relatively small, about 5 square meters."],
127
+ items = [item_1])
128
  place_2 = Location("Kitchen",
129
+ ["The kitchen of the house", "It's not huge, but it's not the smallest kitchen in the world either.", "A lot of light comes in through the windows"])
 
130
  place_2.connecting_locations = [place_3]
131
+ place_2.block_passage(place_3, item_4)
132
+ place_3.connecting_locations = [place_2]
133
 
134
+ place_1 = Location("Art studio",
135
+ ["This is the art studio that Emma's mom has in the house"],
136
+ items = [item_3, item_5])
137
  place_1.connecting_locations = [place_2]
138
+ place_2.connecting_locations = [place_1]
139
 
140
+ player = Character("Emma",
141
+ ["A teenager of average height", "She is looking for her pet 'Hojita'"],
142
+ inventory = [],
143
  location = place_1)
144
+ npc = Character("Laura",
145
+ ["A woman in her 40s", "She is Emma's mom", "She is an artist, and loves oil painting"],
146
+ inventory = [item_2],
147
+ location= place_1)
148
 
149
  the_world = World(player)
150
  the_world.add_locations([place_1,place_2,place_3])
151
+ the_world.add_items([item_1,item_2,item_3,item_4,item_5])
 
152
  the_world.add_character(npc)
153
+ the_world.set_objective(item_1,place_2)
154
 
155
  return the_world
156
 
157
  def get_world_1_spanish() -> World:
158
 
159
+ item_1 = Item("Tortuga",["Una tortuga pequeña", "La mascota de Emma", "Emma la llama 'Hojita'"])
160
  item_2 = Item("Llave",
161
  ["Una llave para abrir un candado", "Es dorada", "Tiene grabada la imagen de un extraño escudo de armas"])
162
  item_3 = Item("Un martillo gris",
prompts.py CHANGED
@@ -85,7 +85,7 @@ def prompt_narrate_current_scene_spanish (world_state: str, previous_narrations:
85
  elif len(previous_narrations)==0:
86
  prompt += "Ten en cuenta que el jugador ya conoce a su personaje, y cómo se ve, así que no menciones nada sobre esto. Sin embargo, es la primera vez que el jugador visita este lugar, así que describelo. Es importante que menciones todos los componentes que hay en este lugar. Sin embargo, es mejor si no describes cada componente: basta con que los menciones con una mínima descripción poco específica. Es muy importante que nombres los lugares a los que puede acceder el jugador desde esta posición. \n"
87
  else:
88
- prompt += "Ten en cuenta que el jugador ya conoce a s upersonaje, y cómo se ve, así que no menciones nada sobre esto. Además, no es la primera vez que el jugador visita este lugar. A continuación te daré algunas narraciones previas de este mismo lugar (de la más antigua a la más nueva), así te puedes asegurar de no repetir los mismos detalles de nuevo:\n"
89
  for narration in previous_narrations:
90
  prompt+=f'- {narration}\n'
91
 
@@ -119,7 +119,7 @@ def prompt_world_update_spanish (world_state: str, input: str) -> str:
119
  - Moved object: <object> now is in <new_location>
120
  - Blocked passages now available: <now_reachable_location>
121
  - Your location changed: <new_location>
122
- (E) Por último, puedes agregar una narración de los cambios detecados en el estado del mundo (¡sin hacer avanzar la historia y sin crear detalles no incluidos en el estado del mundo!) usando el formato: #<tu mensaje final>#
123
  (F) Dentro de la sección de narración que agregues al final, entre símbolos #, también puedes responder preguntas que haga el jugador en su entrada, sobre los objetos o personajes que puede ver, o el lugar en el que se encuentra.
124
 
125
  Aquí hay algunos ejemplos (con la aclaración entre paréntesis sobre qué podría haber intentado hacer el jugador) sobre el formato, descritos en los puntos (D) y (E):
@@ -192,57 +192,84 @@ def prompt_world_update_spanish (world_state: str, input: str) -> str:
192
  return prompt
193
 
194
  def prompt_world_update_english (world_state: str, input: str) -> str:
195
- prompt = f"""You are a storyteller. You are managing a fictional world, and the player can interact with it. This is the state of the world at the moment:
196
- {world_state}\n\n
197
- Explain the changes in the world after the player actions in this input "{input}".
198
-
199
  Here are some clarifications:
200
- (A) If a passage is blocked, then the player must unblock it before being able to reach the place. Even if the player tells you that he is going to access the locked location, you have to be sure that he is complying with what you asked to allow him to unlock the access, for example by using a key or solving a puzzle.
201
- (B) Pay atenttion to the description of the components and their capabilities.
202
- (C) Do not assume that the player input always make sense; maybe those actions try to do something that the world does not allow.
203
  (D) Follow always the following format with the three categories, using "None" in each case if there are no changes and repeat the category for each case:
204
  - Moved object: <object> now is in <new_location>
205
  - Blocked passages now available: <now_reachable_location>
206
  - Your location changed: <new_location>
207
-
208
- Here you have some examples.
209
- Example 1
 
 
 
210
  - Moved object: <axe> now is in <Inventory>
211
  - Blocked passages now available: None
212
  - Your location changed: None
 
 
 
 
 
 
 
213
 
214
- Example 2
215
  - Moved object: None
216
  - Blocked passages now available: None
217
  - Your location changed: <Garden>
 
218
 
219
- Example 3
220
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
221
  - Blocked passages now available: None
222
  - Your location changed: None
 
223
 
224
- Example 4
225
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
226
  - Blocked passages now available: <Small room>
227
  - Your location changed: None
 
228
 
229
- Example 5
230
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
231
  - Blocked passages now available: <Small room>
232
  - Your location changed: <Small room>
 
233
 
234
- Example 6
235
  - Moved object: <book> now is in <John>, <pencil> now is in <Inventory>
236
  - Blocked passages now available: None
237
  - Your location changed: None
 
238
 
239
- Example 7
240
  - Moved object: <computer> now is in <Susan>
241
  - Blocked passages now available: None
242
  - Your location changed: None
243
-
244
 
245
- Finally, you can add a final short sentence narrating the detected changes in the state of the world (without moving the story forward and creating details not included in the state of the world!) or answering a question of the player about the state of the world, using the format: #<your final sentence>#
246
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  return prompt
 
85
  elif len(previous_narrations)==0:
86
  prompt += "Ten en cuenta que el jugador ya conoce a su personaje, y cómo se ve, así que no menciones nada sobre esto. Sin embargo, es la primera vez que el jugador visita este lugar, así que describelo. Es importante que menciones todos los componentes que hay en este lugar. Sin embargo, es mejor si no describes cada componente: basta con que los menciones con una mínima descripción poco específica. Es muy importante que nombres los lugares a los que puede acceder el jugador desde esta posición. \n"
87
  else:
88
+ prompt += "Ten en cuenta que el jugador ya conoce a su personaje, y cómo se ve, así que no menciones nada sobre esto. Además, no es la primera vez que el jugador visita este lugar. A continuación te daré algunas narraciones previas de este mismo lugar (de la más antigua a la más nueva), así te puedes asegurar de no repetir los mismos detalles de nuevo:\n"
89
  for narration in previous_narrations:
90
  prompt+=f'- {narration}\n'
91
 
 
119
  - Moved object: <object> now is in <new_location>
120
  - Blocked passages now available: <now_reachable_location>
121
  - Your location changed: <new_location>
122
+ (E) Por último, puedes agregar una narración de los cambios detecados en el estado del mundo (¡sin hacer avanzar la historia y sin crear detalles no incluidos en el estado del mundo!) usando el formato: #tu mensaje final#
123
  (F) Dentro de la sección de narración que agregues al final, entre símbolos #, también puedes responder preguntas que haga el jugador en su entrada, sobre los objetos o personajes que puede ver, o el lugar en el que se encuentra.
124
 
125
  Aquí hay algunos ejemplos (con la aclaración entre paréntesis sobre qué podría haber intentado hacer el jugador) sobre el formato, descritos en los puntos (D) y (E):
 
192
  return prompt
193
 
194
  def prompt_world_update_english (world_state: str, input: str) -> str:
195
+ prompt = f"""You are a storyteller. You are managing a fictional world, and the player can interact with it. Following a specific format, that I will specify below, your task is to find the changes in the world after the actions in the player input. Specifically, you will have to find what objects were moved, which previously blocked passages are now unblocked, and if the player moved to a new place.
196
+
 
 
197
  Here are some clarifications:
198
+ (A) Pay attention to the description of the components and their capabilities.
199
+ (B) If a passage is blocked, then the player must unblock it before being able to reach the place. Even if the player tells you that he is going to access the locked location, you have to be sure that he is complying with what you asked to allow him to unlock the access, for example by using a key or solving a puzzle.
200
+ (C) Do not assume that the player input always makes sense; maybe those actions try to do something that the world does not allow.
201
  (D) Follow always the following format with the three categories, using "None" in each case if there are no changes and repeat the category for each case:
202
  - Moved object: <object> now is in <new_location>
203
  - Blocked passages now available: <now_reachable_location>
204
  - Your location changed: <new_location>
205
+ (E) Finally, you can narrate the changes you've detected in the world state (without moving the story forward and without making up details not included in the world state!) using the format: #your final message#
206
+ (F) In the narration section that you add at the end, between # symbols, you can also answer questions that the player asks in their input, about the objects or characters they can see, or the place they are in.
207
+
208
+ Here I give you some examples (in parentheses, a clarification about what the player might have tried to do) for the asked format, as described in items (D) and (E):
209
+
210
+ Example 1 (The player took the axe and put it in the inventory)
211
  - Moved object: <axe> now is in <Inventory>
212
  - Blocked passages now available: None
213
  - Your location changed: None
214
+ #You put the axe in your bag#
215
+
216
+ Example 2 (The player unblocks the passage to the basement)
217
+ - Moved object: None
218
+ - Blocked passages now available: <Basement>
219
+ - Your location changed: None
220
+ # The basement is now reachable #
221
 
222
+ Example 3 (The player now is in the garden)
223
  - Moved object: None
224
  - Blocked passages now available: None
225
  - Your location changed: <Garden>
226
+ # You enter the garden #
227
 
228
+ Example 4 (The player puts objects in the bag and leaves the axe on the floor)
229
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
230
  - Blocked passages now available: None
231
  - Your location changed: None
232
+ # You put the banana and the bottle in your bag. The axe lies on the floor of the Main hall #
233
 
234
+ Example 5 (The player puts objects in the bag and leaves the axe on the floor and unblocks the passage to the Small room)
235
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
236
  - Blocked passages now available: <Small room>
237
  - Your location changed: None
238
+ # You put the banana and the bottle in your bag. The axe lies on the floor of the Main hall. Now you can reach the Small room. #
239
 
240
+ Example 6 (The player puts objects in the bag and leaves the axe on the floor, unblocks the passage and goes to the Small room)
241
  - Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
242
  - Blocked passages now available: <Small room>
243
  - Your location changed: <Small room>
244
+ # You put the banana and the bottle in your bag. The axe lies on the floor of the Main hall. The Small room is now unblocked, and you moved there. #
245
 
246
+ Example 7 (The player puts the pencil in the bag and gives the book to John)
247
  - Moved object: <book> now is in <John>, <pencil> now is in <Inventory>
248
  - Blocked passages now available: None
249
  - Your location changed: None
250
+ # John now has the book. You put the pencil in your bag #
251
 
252
+ Example 8 (The player gives the computer to Susan)
253
  - Moved object: <computer> now is in <Susan>
254
  - Blocked passages now available: None
255
  - Your location changed: None
256
+ # Susan put the computer in her bag #
257
 
258
+ Example 9 (The player does something that has not the expected outcome)
259
+ - Moved object: None
260
+ - Blocked passages now available: None
261
+ - Your location changed: None
262
+ # Nothing happened... #
263
+
264
+ Example 10 (The player asks a question)
265
+ - Moved object: None
266
+ - Blocked passages now available: None
267
+ - Your location changed: None
268
+ # Answer to the player's question #
269
+
270
+
271
+ Now, give the changes in the world following the specified format, after this player input "{input}" on this world state:
272
+
273
+ {world_state}"""
274
 
275
  return prompt