Spaces:
Runtime error
Runtime error
Commit
·
bd049e0
1
Parent(s):
4fe3d9c
Unit testing the decider questions
Browse files- app.py +1 -3
- decider_questions.py +1 -1
- decider_utils.py +1 -0
- run_unit_tests.py +0 -2
app.py
CHANGED
|
@@ -73,7 +73,6 @@ def run_1_game_turn(s_narr_transcript, s_n_turns_elapsed, s_user_transcript, s_u
|
|
| 73 |
s_narr_transcript = game_intro + NOTES_TO_THE_NARRATOR_AT_START
|
| 74 |
s_user_transcript = game_intro
|
| 75 |
|
| 76 |
-
|
| 77 |
elif s_user_input == "":
|
| 78 |
s_user_transcript += "You must choose an action.\n"
|
| 79 |
|
|
@@ -83,8 +82,7 @@ def run_1_game_turn(s_narr_transcript, s_n_turns_elapsed, s_user_transcript, s_u
|
|
| 83 |
elif decider_utils.yesno(QUESTION_IS_ACTION_LIKELY_LETHAL, s_user_input, default=NO):
|
| 84 |
finally_add2_both_tscripts += game_over_fail_txt("You have taken an action that is likely to result in killing someone.")
|
| 85 |
|
| 86 |
-
elif decider_utils.yesno(QUESTION_IS_USER_ENGAGED_WITH_BANDITS, s_narr_transcript, default=NO)
|
| 87 |
-
and decider_utils.special_case_is_running_away(s_user_input):
|
| 88 |
finally_add2_both_tscripts += "Invalid entry. You cannot outrun these bandits.\n"
|
| 89 |
|
| 90 |
elif decider_utils.yesno(QUESTION_IS_ACTION_MAGIC, s_user_input, default=NO):
|
|
|
|
| 73 |
s_narr_transcript = game_intro + NOTES_TO_THE_NARRATOR_AT_START
|
| 74 |
s_user_transcript = game_intro
|
| 75 |
|
|
|
|
| 76 |
elif s_user_input == "":
|
| 77 |
s_user_transcript += "You must choose an action.\n"
|
| 78 |
|
|
|
|
| 82 |
elif decider_utils.yesno(QUESTION_IS_ACTION_LIKELY_LETHAL, s_user_input, default=NO):
|
| 83 |
finally_add2_both_tscripts += game_over_fail_txt("You have taken an action that is likely to result in killing someone.")
|
| 84 |
|
| 85 |
+
elif decider_utils.yesno(QUESTION_IS_USER_ENGAGED_WITH_BANDITS, s_narr_transcript, default=NO) and decider_utils.special_case_is_running_away(s_user_input):
|
|
|
|
| 86 |
finally_add2_both_tscripts += "Invalid entry. You cannot outrun these bandits.\n"
|
| 87 |
|
| 88 |
elif decider_utils.yesno(QUESTION_IS_ACTION_MAGIC, s_user_input, default=NO):
|
decider_questions.py
CHANGED
|
@@ -2,6 +2,6 @@ QUESTION_IS_USER_HOME = "At the end of the above story, is the protagonist locat
|
|
| 2 |
QUESTION_DOES_USER_STILL_HAVE_AT_LEAST_30_GOLD = "At the end of the above story, does the protagonist still have at least 30 gold pieces?"
|
| 3 |
QUESTION_IS_USER_ENGAGED_WITH_BANDITS = "At the end of the above story, is the protagonist currently still engaged in a standoff with bandits?"
|
| 4 |
QUESTION_IS_ACTION_LIKELY_LETHAL = "Is the action just described likely to result in anyone dying?"
|
| 5 |
-
QUESTION_IS_ACTION_RUNNING_AWAY =
|
| 6 |
QUESTION_IS_ACTION_MAGIC = "Is the action just described an example of using supernatural magical spells / potions / etc?"
|
| 7 |
QUESTION_DID_PROTAGONIST_KILL = "In the story segment above, did the protagonist kill anyone?"
|
|
|
|
| 2 |
QUESTION_DOES_USER_STILL_HAVE_AT_LEAST_30_GOLD = "At the end of the above story, does the protagonist still have at least 30 gold pieces?"
|
| 3 |
QUESTION_IS_USER_ENGAGED_WITH_BANDITS = "At the end of the above story, is the protagonist currently still engaged in a standoff with bandits?"
|
| 4 |
QUESTION_IS_ACTION_LIKELY_LETHAL = "Is the action just described likely to result in anyone dying?"
|
| 5 |
+
QUESTION_IS_ACTION_RUNNING_AWAY = "Does that sentence describe the act of fleeing?"
|
| 6 |
QUESTION_IS_ACTION_MAGIC = "Is the action just described an example of using supernatural magical spells / potions / etc?"
|
| 7 |
QUESTION_DID_PROTAGONIST_KILL = "In the story segment above, did the protagonist kill anyone?"
|
decider_utils.py
CHANGED
|
@@ -36,6 +36,7 @@ def yesno(question, text, default):
|
|
| 36 |
# In certain cases, I need more special-case logic in order to behave correctly,
|
| 37 |
# which we verify using the unit tests in run_unit_tests.py:
|
| 38 |
|
|
|
|
| 39 |
def special_case_is_running_away(text):
|
| 40 |
might_really_be_fleeing = False
|
| 41 |
for keyword in ["run", "away", "hide", "escape", "flee", "sprint", "teleport"]:
|
|
|
|
| 36 |
# In certain cases, I need more special-case logic in order to behave correctly,
|
| 37 |
# which we verify using the unit tests in run_unit_tests.py:
|
| 38 |
|
| 39 |
+
|
| 40 |
def special_case_is_running_away(text):
|
| 41 |
might_really_be_fleeing = False
|
| 42 |
for keyword in ["run", "away", "hide", "escape", "flee", "sprint", "teleport"]:
|
run_unit_tests.py
CHANGED
|
@@ -11,7 +11,6 @@ from decider_utils import YES, NO, yesno, special_case_is_running_away
|
|
| 11 |
from decider_questions import *
|
| 12 |
|
| 13 |
|
| 14 |
-
|
| 15 |
assert YES == special_case_is_running_away("run away")
|
| 16 |
assert YES == special_case_is_running_away("I run away")
|
| 17 |
assert YES == special_case_is_running_away("flee")
|
|
@@ -23,4 +22,3 @@ assert NO == special_case_is_running_away("C")
|
|
| 23 |
assert NO == special_case_is_running_away("ok")
|
| 24 |
assert NO == special_case_is_running_away("say ok")
|
| 25 |
assert NO == special_case_is_running_away("say okay")
|
| 26 |
-
|
|
|
|
| 11 |
from decider_questions import *
|
| 12 |
|
| 13 |
|
|
|
|
| 14 |
assert YES == special_case_is_running_away("run away")
|
| 15 |
assert YES == special_case_is_running_away("I run away")
|
| 16 |
assert YES == special_case_is_running_away("flee")
|
|
|
|
| 22 |
assert NO == special_case_is_running_away("ok")
|
| 23 |
assert NO == special_case_is_running_away("say ok")
|
| 24 |
assert NO == special_case_is_running_away("say okay")
|
|
|