in textworld/generator/inform7/world2inform7.py [0:0]
def gen_source(self, seed: int = 1234) -> str:
source = ""
source += "Use MAX_STATIC_DATA of 500000.\n" # To generate game with 300+ locations.
source += "When play begins, seed the random-number generator with {}.\n\n".format(seed)
source += self.define_inform7_kinds()
# Mention that rooms have a special text attribute called 'internal name'.
source += "A room has a text called internal name.\n\n"
# Define custom addons.
source += self.kb.inform7_addons_code + "\n"
# Declare all rooms.
room_names = [room.id for room in self.game.world.rooms]
source += "The " + " and the ".join(room_names) + " are rooms.\n\n"
source += self.gen_source_for_rooms() + "\n"
# Declare all objects
for vtype in self.game.kb.types:
if vtype in ["P", "I"]:
continue # Skip player and inventory.
entities = self.game.world.get_entities_per_type(vtype)
if len(entities) == 0:
continue # No entity of that specific type.
kind = self.kb.inform7_variables[vtype]
names = [entity.id for entity in entities]
source += "The " + " and the ".join(names) + " are {}s.\n".format(kind)
# All objects are privately-named and we manually define all "Understand as" phrases needed.
source += "The " + " and the ".join(names) + " are privately-named.\n"
# Process the objects.
source += "\n"
source += self.gen_source_for_objects(self.game.world.objects)
source += "\n\n"
# Place the player.
source += "The player is in {}.\n\n".format(self.entity_infos[self.game.world.player_room.id].id)
objective = self.game.objective.replace("\n", "[line break]")
maximum_score = 0
game_winning_conditions = []
quest_completed_template = "quest{quest_id} completed is true"
for quest_id, quest in enumerate(self.game.quests):
if not quest.optional and len(quest.win_events) > 0:
game_winning_conditions.append(quest_completed_template.format(quest_id=quest_id))
if not quest.optional or quest.reward > 0:
maximum_score += quest.reward
if quest.repeatable:
maximum_score = np.inf
quest_completed = textwrap.dedent("""\