Skip to content

Commit

Permalink
Change to a tie on timeout or error, enforce max length for guess or …
Browse files Browse the repository at this point in the history
…question (#260)

* change to a tie on timeout or error, enforce max length for guess or response

* fix timeouts

* CR
  • Loading branch information
bovard authored May 3, 2024
1 parent a769e3f commit 54e2ad3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions kaggle_environments/envs/llm_20_questions/llm_20_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def guesser_action(active, inactive, step):
if not active.action:
active.status = ERROR
elif active.observation.turnType == ASK:
active.observation.questions.append(active.action)
inactive.observation.questions.append(active.action)
question = active.action[:2000]
active.observation.questions.append(question)
inactive.observation.questions.append(question)
elif active.observation.turnType == GUESS:
active.observation.guesses.append(active.action)
inactive.observation.guesses.append(active.action)
guess = active.action[:100]
active.observation.guesses.append(guess)
inactive.observation.guesses.append(guess)
if active.action and keyword_guessed(active.action):
guessed = True
score = 20 - int(step / 3)
Expand Down Expand Up @@ -165,15 +167,17 @@ def interpreter(state, env):
step = state[0].observation.step

end_early = (active1 and active1.status) in (TIMEOUT, ERROR) or (active2 and active2.status in (TIMEOUT, ERROR))
either_guessed = False

if active1 is not None:
guessed = False
if active1.observation.role == GUESSER:
guessed = guesser_action(active1, inactive1, step)
either_guessed = guessed
else:
answerer_action(active1, inactive1)
if active1.status in (TIMEOUT, ERROR):
end_game(active1, inactive1, -1, active1.status, DONE)
end_game(active1, inactive1, 0, active1.status, DONE)
elif end_early:
end_game(active1, inactive1, 0, DONE, DONE)
else:
Expand All @@ -183,15 +187,16 @@ def interpreter(state, env):
guessed = False
if active2.observation.role == GUESSER:
guessed = guesser_action(active2, inactive2, step)
either_guessed = either_guessed or guessed
else:
answerer_action(active2, inactive2)
if active2.status in (TIMEOUT, ERROR):
end_game(active2, inactive2, -1, active2.status, DONE)
end_game(active2, inactive2, 0, active2.status, DONE)
elif end_early:
end_game(active2, inactive2, 0, DONE, DONE)
else:
increment_turn(active2, inactive2, step, guessed)

return state


Expand Down

0 comments on commit 54e2ad3

Please sign in to comment.