game.objective still overwritten by change_grammar() when quests exist (regression of #239)
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 55/100
Línea de trabajo
Empieza en game.py, en change_grammar(), e inspecciona la lógica de preservación del objetivo en build(); revisa el caso de prueba existente test_manually_defined_objective. Añade cobertura para una misión con una política ganadora y verifica que un objetivo establecido manualmente permanezca sin cambios después de compilar y cargar.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 1.5k
- Forks
- 206
- Merge medio
- 3 d 17 h
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/TextWorld
-
Memory LeaksAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
-
bug enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Todos los issues de microsoft/TextWorld
Issues similares
-
S: Untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Trauma-Station/Trauma-Station#5058 ·
Los mantenedores suelen responder en 1 día
-
Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
BeeStation/BeeStation-Hornet#14818 ·
Los mantenedores suelen responder en 1 día
-
original-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Mosquito: LOOP_ANT_LOCK reads the IFF detonator coverPosiblemente ocupada @cbass2404 la tomó hoy. AbiertoMosquito
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
DCS-Skunkworks/dcs-bios#1925 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Vakore/ZappierGames#101 ·