World

exception textworld.generator.world.NoFreeExitError[source]

Bases: Exception

class textworld.generator.world.World(kb=None)[source]

Bases: object

add_fact(fact)[source]
Return type

None

add_facts(facts)[source]
Return type

None

classmethod deserialize(serialized_facts, kb=None)[source]
Return type

World

find_object_by_id(id)[source]
Return type

Optional[WorldObject]

find_room_by_id(id)[source]
Return type

Optional[WorldRoom]

classmethod from_facts(facts, kb=None)[source]
Return type

World

classmethod from_map(map, kb=None)[source]
Parameters

map (Graph) – Graph defining the structure of the world.

Return type

World

get_all_objects_in(obj)[source]
Return type

List[WorldObject]

get_entities_per_type(type)[source]

Get all entities of a certain type.

Return type

List[WorldEntity]

get_facts_in_scope()[source]
Return type

List[Proposition]

get_objects_in_inventory()[source]
Return type

List[WorldObject]

get_visible_objects_in(obj)[source]
Return type

List[WorldObject]

populate(nb_objects, rng=None, object_types_probs=None)[source]
Return type

List[Proposition]

populate_room(nb_objects, room, rng=None, object_types_probs=None)[source]
Return type

List[Proposition]

populate_room_with(objects, room, rng=None)[source]
Return type

List[Proposition]

populate_with(objects, rng=None)[source]
Return type

List[Proposition]

serialize()[source]
Return type

List

set_player_room(start_room=None)[source]
Return type

None

property entities
Return type

ValuesView[WorldEntity]

property facts
Return type

List[Proposition]

property objects
Return type

List[WorldObject]

property player_room
Return type

WorldRoom

property rooms
Return type

List[WorldRoom]

property state
Return type

State

class textworld.generator.world.WorldEntity(*args, **kwargs)[source]

Bases: textworld.logic.Variable

A WorldEntity is an abstract concept representing anything with a name and a type.

Create a Variable.

Parameters
  • name – The (unique) name of the variable.

  • type (optional) – The type of the variable. Defaults to the same as the name.

Return type

None

classmethod create(var)[source]
Return type

Union[WorldRoom, WorldObject]

get_attributes()[source]
Return type

List[Proposition]

property id
Return type

str

name
type
class textworld.generator.world.WorldObject(*args, **kwargs)[source]

Bases: textworld.generator.world.WorldEntity

A WorldObject is anything we can directly interact with.

Create a Variable.

Parameters
  • name – The (unique) name of the variable.

  • type (optional) – The type of the variable. Defaults to the same as the name.

name
type
class textworld.generator.world.WorldRoom(*args, **kwargs)[source]

Bases: textworld.generator.world.WorldEntity

WorldRooms can be linked with each other through exits.

Create a Variable.

Parameters
  • name – The (unique) name of the variable.

  • type (optional) – The type of the variable. Defaults to the same as the name.

name
type
textworld.generator.world.connect(room1, direction, room2, door=None)[source]

Generate predicates that connect two rooms.

Parameters
  • room1 (Variable) – A room variable.

  • direction (str) – Direction that we need to travel to go from room1 to room2.

  • room2 (Variable) – A room variable.

  • door (Optional[Variable]) – The door separating the two rooms. If None, there is no door between the rooms.

Return type

List[Proposition]

textworld.generator.world.graph2state(G, rooms)[source]

Convert Graph object to a list of Proposition.

Parameters
  • G (Graph) – Graph defining the structure of the world.

  • rooms (Dict[str, Variable]) – information about the rooms in the world.

Return type

List[Proposition]

textworld.generator.graph_networks.create_map(rng, n_nodes, h, w, possible_door_states=['open', 'closed', 'locked'])[source]
textworld.generator.graph_networks.create_small_map(rng, n_rooms, possible_door_states=['open', 'closed', 'locked'])[source]
textworld.generator.graph_networks.direction(x, y)[source]
textworld.generator.graph_networks.extremes(G)[source]

Find left most and bottom nodes in the cartesian sense.

textworld.generator.graph_networks.gen_layout(rng, n_nodes=5, h=10, w=10)[source]

Generate a map with n_nodes rooms by picking a subgraph from a h,w grid.

textworld.generator.graph_networks.get_path(G, room1, room2)[source]
textworld.generator.graph_networks.mark_doors(G, rng, possible_door_states=['open', 'closed', 'locked'])[source]

Put doors between neighbouring articulation points.

textworld.generator.graph_networks.plot_graph(g, show=True)[source]

Plot cartesian graph on a grid.

textworld.generator.graph_networks.relabel(G)[source]

Relabel G so that its origin is (0, 0)

textworld.generator.graph_networks.reverse_direction(direction)[source]
textworld.generator.graph_networks.shortest_path(G, source, target)[source]

Return shortest path in terms of directions.

textworld.generator.graph_networks.xy_diff(x, y)[source]