game.objective still overwritten by change_grammar() when quests exist (regression of #239)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 55/100
Direzione di ricerca
Inizia in game.py, all'interno di change_grammar(), e ispeziona la logica di conservazione dell'obiettivo in build(); esamina il caso di test esistente test_manually_defined_objective. Aggiungi la copertura per una quest con una politica vincente e verifica che un obiettivo impostato manualmente rimanga invariato dopo la compilazione e il caricamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Issue #239 reported that manually setting quest.desc or game.objective gets overwritten by the text generation process during build()/compile(). PR #240 added a fix that copies _objective from a previous build before change_grammar() runs.
However, the fix is incomplete. In build(), the copy happens at line 788-789 before change_grammar() is called at line 803. change_grammar() then unconditionally overwrites the objective at line 460 of game.py:
self.objective = describe_event(Event(policy), self, self.grammar)
This means the preserved objective gets clobbered whenever the game has quests with a winning policy (i.e. most games).
The test added in PR #240 (test_manually_defined_objective) only tests a game with no quests, so it doesn't catch this.
Steps to Reproduce
import textworld
from textworld import GameMaker
M = GameMaker()
r1 = M.new_room("bedroom")
M.set_player(r1)
key = M.new(type="k", name="key", desc="This is a skeleton key.")
r1.add(key)
quest = M.set_quest_from_commands(["take key"])
game = M.build()
game.objective = "Find a valuable object."
game_file = M.compile("/tmp/test_game.z8")
# Load and check - the objective has been overwritten
loaded = textworld.Game.load("/tmp/test_game.json")
assert loaded.objective == "Find a valuable object.", f"Expected custom objective, got: {loaded.objective[:80]}..."
The assertion fails because change_grammar() in the second build() (triggered by compile()) overwrites the objective with auto-generated text.
Proposed Fix
In game.py, change_grammar() should only set the objective if one hasn't already been set:
# Before (line 460):
self.objective = describe_event(Event(policy), self, self.grammar)
# After:
if self._objective is None:
self.objective = describe_event(Event(policy), self, self.grammar)
Workaround
Until this is fixed, you can work around it by calling M.build(), setting game.objective, then compiling manually with textworld.generator.compile_game(game, options) instead of M.compile().
Environment
- TextWorld 1.7.0
- Python 3.12
- macOS
- Lingua principale
- Jupyter Notebook
- Stelle
- 1.4k
- Fork
- 207
- Merge medio
- 8g 22h
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/TextWorld
-
Memory Leaks Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
-
bug enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
Tutte le issue di microsoft/TextWorld
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
godotengine/godot#123776 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
HarbourMasters/Shipwright#7243 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
[Feature] 奇物选择添加优先级 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
syfoud/Simulated_Scepter#174 ·