Skip to content

Commit acf2275

Browse files
committed
The new style of TRACEABLE PROPOSITIONS and comprehenssive updates to adapt the new Predicate, Proposition, & Signature styles. This new framework can track a proposition through the time.
1 parent ad97fa8 commit acf2275

14 files changed

Lines changed: 418 additions & 434 deletions

File tree

textworld/challenges/simple.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from textworld.challenges import register
3030

3131
from textworld import GameOptions
32-
from textworld.generator.game import Quest, Event
32+
from textworld.generator.game import Quest, EventCondition
3333

3434
from textworld.utils import encode_seeds
3535

@@ -261,36 +261,36 @@ def make_game(settings: Mapping[str, str], options: Optional[GameOptions] = None
261261
# 1. Opening the container.
262262
quests.append(
263263
Quest(win_events=[
264-
Event(conditions={M.new_fact("open", bedroom_key_holder)})
264+
EventCondition(conditions={M.new_fact("open", bedroom_key_holder)})
265265
])
266266
)
267267

268268
# 2. Getting the key.
269269
quests.append(
270270
Quest(win_events=[
271-
Event(conditions={M.new_fact("in", bedroom_key, M.inventory)})
271+
EventCondition(conditions={M.new_fact("in", bedroom_key, M.inventory)})
272272
])
273273
)
274274

275275
# 3. Unlocking the bedroom door.
276276
quests.append(
277277
Quest(win_events=[
278-
Event(conditions={M.new_fact("closed", bedroom_kitchen.door)})
278+
EventCondition(conditions={M.new_fact("closed", bedroom_kitchen.door)})
279279
])
280280
)
281281

282282
# 4. Opening the bedroom door.
283283
quests.append(
284284
Quest(win_events=[
285-
Event(conditions={M.new_fact("open", bedroom_kitchen.door)})
285+
EventCondition(conditions={M.new_fact("open", bedroom_kitchen.door)})
286286
])
287287
)
288288

289289
if settings["rewards"] in ["dense", "balanced"]:
290290
# Escaping out of the bedroom.
291291
quests.append(
292292
Quest(win_events=[
293-
Event(conditions={M.new_fact("at", M.player, kitchen)})
293+
EventCondition(conditions={M.new_fact("at", M.player, kitchen)})
294294
])
295295
)
296296

@@ -299,7 +299,7 @@ def make_game(settings: Mapping[str, str], options: Optional[GameOptions] = None
299299
for door in doors_to_open:
300300
quests.append(
301301
Quest(win_events=[
302-
Event(conditions={M.new_fact("open", door)})
302+
EventCondition(conditions={M.new_fact("open", door)})
303303
])
304304
)
305305

@@ -308,15 +308,15 @@ def make_game(settings: Mapping[str, str], options: Optional[GameOptions] = None
308308
for room in rooms_to_visit:
309309
quests.append(
310310
Quest(win_events=[
311-
Event(conditions={M.new_fact("at", M.player, room)})
311+
EventCondition(conditions={M.new_fact("at", M.player, room)})
312312
])
313313
)
314314

315315
if settings["rewards"] in ["dense", "balanced"]:
316316
# Retrieving the food item.
317317
quests.append(
318318
Quest(win_events=[
319-
Event(conditions={M.new_fact("in", food, M.inventory)})
319+
EventCondition(conditions={M.new_fact("in", food, M.inventory)})
320320
])
321321
)
322322

@@ -325,22 +325,22 @@ def make_game(settings: Mapping[str, str], options: Optional[GameOptions] = None
325325
# Retrieving the food item.
326326
quests.append(
327327
Quest(win_events=[
328-
Event(conditions={M.new_fact("in", food, M.inventory)})
328+
EventCondition(conditions={M.new_fact("in", food, M.inventory)})
329329
])
330330
)
331331

332332
if settings["rewards"] in ["dense", "balanced", "sparse"]:
333333
# Putting the food on the stove.
334334
quests.append(
335335
Quest(win_events=[
336-
Event(conditions={M.new_fact("on", food, stove)})
336+
EventCondition(conditions={M.new_fact("on", food, stove)})
337337
])
338338
)
339339

340340
# 3. Determine the losing condition(s) of the game.
341341
quests.append(
342342
Quest(fail_events=[
343-
Event(conditions={M.new_fact("eaten", food)})
343+
EventCondition(conditions={M.new_fact("eaten", food)})
344344
])
345345
)
346346

textworld/challenges/spaceship/content_check_game.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ def make_game(settings: Mapping[str, str], options: Optional[GameOptions] = None
129129

130130
from textworld.challenges.spaceship.maker import test_commands
131131
test_commands(gm, [
132-
132+
'open Red box',
133+
'close Red box',
134+
# 'open Red box',
133135
# 'open Blue box',
134136
# 'open White box',
135137
# 'open Red box',
136138
# 'close red box',
137-
'check laptop for email',
138-
'open Red box',
139+
# 'check laptop for email',
140+
# 'open Red box',
139141

140142
])
141143

@@ -168,19 +170,26 @@ def quest_design(game):
168170
# })
169171
# quests.append(Quest(win_events=[win_quest], fail_events=[], reward=-1))
170172

171-
win_quest = EventCondition(conditions={game.new_fact("closed", game._entities['c_0'])},
172-
verb_tense={'closed': 'has been'})
173+
win_quest = EventCondition(conditions={game.new_fact("open", game._entities['c_0'])},
174+
output_verb_tense={'open': 'was'})
173175
quests.append(Quest(win_events=[win_quest], fail_events=[], reward=0))
174176

175-
win_quest = EventAction(action={game.new_rule_fact(game._kb.rules['open/c'],
177+
win_quest = EventAction(action={game.new_rule_fact(game._kb.rules['close/c'],
176178
game._entities['P'],
177179
game._entities['r_0'],
178180
game._entities['s_0'],
179181
game._entities['c_0'],
180-
game._entities['cpu_0'],
181-
additional=('has been', 'closed'),
182-
)})
183-
quests.append(Quest(win_events=[win_quest], fail_events=[]))
182+
game._entities['cpu_0'])})
183+
quests.append(Quest(win_events=[win_quest], fail_events=[], reward=1))
184+
185+
# win_quest1 = EventCondition(conditions={game.new_fact("has_been__closed", game._entities['c_0'])})
186+
# win_quest2 = EventAction(action={game.new_rule_fact(game._kb.rules['open/c'],
187+
# game._entities['P'],
188+
# game._entities['r_0'],
189+
# game._entities['s_0'],
190+
# game._entities['c_0'],
191+
# game._entities['cpu_0'])})
192+
# quests.append(Quest(win_events=[win_quest1, win_quest2], fail_events=[]))
184193

185194
game.quests = quests
186195

textworld/challenges/spaceship/maker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from textworld.helpers import start
99
from textworld.utils import make_temp_directory
1010
import textworld
11-
from textworld.generator.game import Event, Quest, GameOptions
11+
from textworld.generator.game import EventCondition, Quest, GameOptions
1212
from textworld.generator import World
1313

1414

@@ -1268,18 +1268,18 @@ def quest_design_2(game):
12681268
quests = []
12691269

12701270
# 1. Is the Player performing successful in the Sleeping Station
1271-
win_quest = Event(conditions={
1271+
win_quest = EventCondition(conditions={
12721272
game.new_fact("at", game._entities['P'], game._entities['r_0'])
12731273
})
12741274
quests.append(Quest(win_events=[win_quest], fail_events=[], reward=0))
12751275

1276-
fail_quest = Event(conditions={
1276+
fail_quest = EventCondition(conditions={
12771277
game.new_fact("event", game._entities['P'], game._entities['r_0']),
12781278
game.new_fact("at", game._entities['P'], game._entities['r_1']),
12791279
game.new_fact("open", game._entities['d_0']),
12801280
game.new_fact("unread/e", game._entities['cpu_0']),
12811281
})
1282-
win_quest = Event(conditions={
1282+
win_quest = EventCondition(conditions={
12831283
game.new_fact("event", game._entities['P'], game._entities['r_0']),
12841284
game.new_fact("at", game._entities['P'], game._entities['r_1']),
12851285
game.new_fact("open", game._entities['d_0']),
@@ -1288,7 +1288,7 @@ def quest_design_2(game):
12881288
quests.append(Quest(win_events=[win_quest], fail_events=[fail_quest]))
12891289

12901290
# 2.
1291-
win_quest = Event(conditions={game.new_fact("worn", game._entities['l_0'])})
1291+
win_quest = EventCondition(conditions={game.new_fact("worn", game._entities['l_0'])})
12921292
quests.append(Quest(win_events=[win_quest], fail_events=[]))
12931293

12941294
game.quests = quests
@@ -1300,14 +1300,14 @@ def quest_design(game):
13001300
quests = []
13011301

13021302
# 1. Player is in the Sleeping Station
1303-
win_quest = Event(conditions={game.new_fact("read/e", game._named_entities['laptop'])})
1303+
win_quest = EventCondition(conditions={game.new_fact("read/e", game._named_entities['laptop'])})
13041304
quests.append(Quest(win_events=[win_quest], fail_events=[]))
1305-
tp = Event(conditions={game.new_fact("unread/e", game._named_entities['laptop'])})
1305+
tp = EventCondition(conditions={game.new_fact("unread/e", game._named_entities['laptop'])})
13061306
fail_quest = tp
13071307
quests.append(Quest(win_events=[], fail_events=[fail_quest]))
13081308

13091309
# 2. Player is in US LAB to find Electronic Key 1
1310-
win_quest = Event(conditions={game.new_fact("in", game._named_entities['electronic key 1'], game._entities['I'])})
1310+
win_quest = EventCondition(conditions={game.new_fact("in", game._named_entities['electronic key 1'], game._entities['I'])})
13111311
quests.append(Quest(win_events=[win_quest], fail_events=[]))
13121312

13131313
# # 3. Player is in Russian Module and take digital Key 1 and/or push the button
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
# cloth
2-
type l : o {
3-
predicates {
4-
worn(l);
5-
takenoff(l);
6-
clean(l);
7-
dirty(l);
8-
}
9-
10-
rules {
11-
wear/l :: in(l, I) & takenoff(l) -> worn(l);
12-
takeoff/l :: worn(l) -> in(l, I) & takenoff(l);
13-
14-
wash/l :: $at(l,r) & dirty(l) -> clean(l);
15-
dirty/l :: $worn(l,P) & clean(l) -> dirty(l);
16-
}
17-
18-
reverse_rules {
19-
wear/l :: takeoff/l;
20-
wash/l :: dirty/l;
21-
}
22-
23-
constraints {
24-
l1 :: clean(l) & dirty(l) -> fail();
25-
l2 :: worn(l) & takenoff(l) -> fail();
26-
}
27-
28-
inform7 {
29-
type {
30-
kind :: "cloth-like";
31-
definition :: "cloth-like are wearable. cloth-like can be either clean or dirty. cloth-like are usually clean. cloth-like can be either worn in or worn out. cloth-like are usually worn out.";
32-
}
33-
34-
predicates {
35-
worn(l) :: "The {l} is worn in";
36-
takenoff(l) :: "The {l} is worn out";
37-
clean(l) :: "The {l} is clean";
38-
dirty(l) :: "The {l} is dirty";
39-
}
40-
41-
commands {
42-
wear/l :: "wear {l}" :: "_wearing the {l}";
43-
takeoff/l :: "take off {l}" :: "taking off the {l}";
44-
45-
clean/l :: "clean {l}" :: "cleaning the {l}";
46-
dirty/l :: "dirty {l}" :: "dirtying the {l}";
47-
}
48-
49-
code :: """
50-
Understand the command "wear" as something new.
51-
Understand "wear [something]" as _wearing.
52-
_wearing is an action applying to a thing.
53-
54-
Carry out _wearing:
55-
if a cloth-like (called cl) is worn out:
56-
Now the cl is worn in;
57-
otherwise:
58-
Say "You have this cloth on.".
59-
""";
60-
}
61-
}
1+
# # cloth
2+
# type l : o {
3+
# predicates {
4+
# worn(l);
5+
# takenoff(l);
6+
# clean(l);
7+
# dirty(l);
8+
# }
9+
10+
# rules {
11+
# wear/l :: in(l, I) & takenoff(l) -> worn(l);
12+
# takeoff/l :: worn(l) -> in(l, I) & takenoff(l);
13+
14+
# wash/l :: $at(l,r) & dirty(l) -> clean(l);
15+
# dirty/l :: $worn(l,P) & clean(l) -> dirty(l);
16+
# }
17+
18+
# reverse_rules {
19+
# wear/l :: takeoff/l;
20+
# wash/l :: dirty/l;
21+
# }
22+
23+
# constraints {
24+
# l1 :: clean(l) & dirty(l) -> fail();
25+
# l2 :: worn(l) & takenoff(l) -> fail();
26+
# }
27+
28+
# inform7 {
29+
# type {
30+
# kind :: "cloth-like";
31+
# definition :: "cloth-like are wearable. cloth-like can be either clean or dirty. cloth-like are usually clean. cloth-like can be either worn in or worn out. cloth-like are usually worn out.";
32+
# }
33+
34+
# predicates {
35+
# worn(l) :: "The {l} is worn in";
36+
# takenoff(l) :: "The {l} is worn out";
37+
# clean(l) :: "The {l} is clean";
38+
# dirty(l) :: "The {l} is dirty";
39+
# }
40+
41+
# commands {
42+
# wear/l :: "wear {l}" :: "_wearing the {l}";
43+
# takeoff/l :: "take off {l}" :: "taking off the {l}";
44+
45+
# clean/l :: "clean {l}" :: "cleaning the {l}";
46+
# dirty/l :: "dirty {l}" :: "dirtying the {l}";
47+
# }
48+
49+
# code :: """
50+
# Understand the command "wear" as something new.
51+
# Understand "wear [something]" as _wearing.
52+
# _wearing is an action applying to a thing.
53+
54+
# Carry out _wearing:
55+
# if a cloth-like (called cl) is worn out:
56+
# Now the cl is worn in;
57+
# otherwise:
58+
# Say "You have this cloth on.".
59+
# """;
60+
# }
61+
# }

textworld/challenges/spaceship/textworld_data/logic/container.twl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# container
22
type c : t {
33
predicates {
4-
open(c);
4+
open(c);
55
closed(c);
66

77
in(o, c);
88
}
99

1010
rules {
11-
open/c :: $at(P, r) & $at(s, r) & $on(c, s) & $event((vt, def), c) & closed(c) -> open(c);
12-
close/c :: $at(P, r) & $at(s, r) & $on(c, s) & open(c) -> closed(c);
11+
open/c :: $at(P, r) & $at(s, r) & $on(c, s) & $was__open(c) & closed(c) -> open(c);
12+
close/c :: $at(P, r) & $at(s, r) & $on(c, s) & $was__open(c) & open(c) -> closed(c);
1313

1414
open/c1 :: $at(P, r) & $at(s, r) & $on(c, s) & closed(c) -> open(c);
1515
close/c1 :: $at(P, r) & $at(s, r) & $on(c, s) & open(c) -> closed(c);

0 commit comments

Comments
 (0)