|
24 | 24 | DONE = "DONE"
|
25 | 25 | INACTIVE = "INACTIVE"
|
26 | 26 | ACTIVE = "ACTIVE"
|
| 27 | +TIMEOUT = "TIMEOUT" |
27 | 28 |
|
28 | 29 | GUESS = "guess"
|
29 | 30 | ASK = "ask"
|
@@ -98,43 +99,40 @@ def guesser_action(active, inactive, step):
|
98 | 99 | if active.action and keyword_guessed(active.action):
|
99 | 100 | guessed = True
|
100 | 101 | score = 20 - int(step / 3)
|
101 |
| - active.reward = score |
102 |
| - inactive.reward = score |
103 |
| - active.status = DONE |
104 |
| - inactive.status = DONE |
105 |
| - active.observation.keyword = keyword |
106 |
| - active.observation.category = category |
| 102 | + end_game(active, inactive, score, DONE, DONE) |
| 103 | + return guessed |
| 104 | + |
| 105 | +def end_game(active, inactive, reward, status, inactive_status): |
| 106 | + active.observation.keyword = keyword |
| 107 | + active.observation.category = category |
107 | 108 | inactive.observation.keyword = keyword
|
108 | 109 | inactive.observation.category = category
|
109 |
| - return guessed |
| 110 | + active.reward = reward |
| 111 | + inactive.reward = reward |
| 112 | + active.status = status |
| 113 | + inactive.status = inactive_status |
| 114 | + |
110 | 115 |
|
111 | 116 | def answerer_action(active, inactive):
|
112 | 117 | active.observation.keyword = keyword
|
113 | 118 | active.observation.category = category
|
114 | 119 | response = active.action
|
115 | 120 | if not response:
|
116 | 121 | response = "none"
|
117 |
| - active.status = ERROR |
| 122 | + end_game(active, inactive, -1, ERROR, DONE) |
118 | 123 | elif "yes" in response.lower():
|
119 | 124 | response = "yes"
|
120 | 125 | elif "no" in response.lower():
|
121 | 126 | response = "no"
|
122 | 127 | else:
|
123 | 128 | response = "maybe"
|
124 |
| - active.status = ERROR |
| 129 | + end_game(active, inactive, -1, ERROR, DONE) |
125 | 130 | active.observation.answers.append(response)
|
126 | 131 | inactive.observation.answers.append(response)
|
127 | 132 |
|
128 | 133 | def increment_turn(active, inactive, step, guessed):
|
129 | 134 | if step == 59 and not guessed:
|
130 |
| - active.observation.keyword = keyword |
131 |
| - active.observation.category = category |
132 |
| - inactive.observation.keyword = keyword |
133 |
| - inactive.observation.category = category |
134 |
| - active.reward = -1 |
135 |
| - inactive.reward = -1 |
136 |
| - active.status = DONE |
137 |
| - inactive.status = DONE |
| 135 | + end_game(active, inactive, -1, DONE, DONE) |
138 | 136 | elif active.observation.turnType == "guess":
|
139 | 137 | active.observation.turnType = "ask"
|
140 | 138 | elif active.observation.turnType == "ask":
|
@@ -166,21 +164,33 @@ def interpreter(state, env):
|
166 | 164 |
|
167 | 165 | step = state[0].observation.step
|
168 | 166 |
|
| 167 | + end_early = (active1 and active1.status) in (TIMEOUT, ERROR) or (active2 and active2.status in (TIMEOUT, ERROR)) |
| 168 | + |
169 | 169 | if active1 is not None:
|
170 | 170 | guessed = False
|
171 | 171 | if active1.observation.role == GUESSER:
|
172 | 172 | guessed = guesser_action(active1, inactive1, step)
|
173 | 173 | else:
|
174 | 174 | answerer_action(active1, inactive1)
|
175 |
| - increment_turn(active1, inactive1, step, guessed) |
| 175 | + if active1.status in (TIMEOUT, ERROR): |
| 176 | + end_game(active1, inactive1, -1, active1.status, DONE) |
| 177 | + elif end_early: |
| 178 | + end_game(active1, inactive1, 0, DONE, DONE) |
| 179 | + else: |
| 180 | + increment_turn(active1, inactive1, step, guessed) |
176 | 181 |
|
177 | 182 | if active2 is not None:
|
178 | 183 | guessed = False
|
179 | 184 | if active2.observation.role == GUESSER:
|
180 | 185 | guessed = guesser_action(active2, inactive2, step)
|
181 | 186 | else:
|
182 | 187 | answerer_action(active2, inactive2)
|
183 |
| - increment_turn(active2, inactive2, step, guessed) |
| 188 | + if active2.status in (TIMEOUT, ERROR): |
| 189 | + end_game(active2, inactive2, -1, active2.status, DONE) |
| 190 | + elif end_early: |
| 191 | + end_game(active2, inactive2, 0, DONE, DONE) |
| 192 | + else: |
| 193 | + increment_turn(active2, inactive2, step, guessed) |
184 | 194 |
|
185 | 195 | return state
|
186 | 196 |
|
|
0 commit comments