santit96 commited on
Commit
8dea508
·
1 Parent(s): 29cd0c4

Fix bug in state update

Browse files

Now only set the character as state "not" if it is not in the word at all

Files changed (1) hide show
  1. wordle_env/state.py +6 -6
wordle_env/state.py CHANGED
@@ -77,11 +77,11 @@ def update_from_mask(state: WordleState, word: str, mask: List[int]) -> WordleSt
77
  offset = 1 + cint * WORDLE_N * 3
78
  if mask[i] == SOMEWHERE:
79
  prior_maybe.append(c)
80
- # Char at position i = no, and in other positions maybe, other chars stay as they are
81
- for j in range(WORDLE_N):
82
- # Only flip no if previously was yes or no
83
- if sum(state[offset + 3 * j:offset + 3 * j + 3]) == 0:
84
- state[offset + 3 * j:offset + 3 * j + 3] = [0, 1, 0]
85
  state[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]
86
  elif mask[i] == NO:
87
  # Need to check this first in case there's prior maybe + yes
@@ -168,7 +168,7 @@ def update(state: WordleState, word: str, goal_word: str) -> Tuple[WordleState,
168
  state[char_offset: char_offset + 3] = [0, 1, 0]
169
  state[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]
170
  reward += CHAR_REWARD * 0.1
171
- else:
172
  # Char at all positions = no
173
  state[offset:offset + 3 * WORDLE_N] = [1, 0, 0] * WORDLE_N
174
  processed_letters.append(c)
 
77
  offset = 1 + cint * WORDLE_N * 3
78
  if mask[i] == SOMEWHERE:
79
  prior_maybe.append(c)
80
+ # Char at position i = no, and in other positions maybe except it had a value before, other chars stay as they are
81
+ for char_idx in range(0, WORDLE_N * 3, 3):
82
+ char_offset = offset + char_idx
83
+ if tuple(state[char_offset: char_offset + 3]) == (0, 0, 0):
84
+ state[char_offset: char_offset + 3] = [0, 1, 0]
85
  state[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]
86
  elif mask[i] == NO:
87
  # Need to check this first in case there's prior maybe + yes
 
168
  state[char_offset: char_offset + 3] = [0, 1, 0]
169
  state[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]
170
  reward += CHAR_REWARD * 0.1
171
+ elif c not in goal_word:
172
  # Char at all positions = no
173
  state[offset:offset + 3 * WORDLE_N] = [1, 0, 0] * WORDLE_N
174
  processed_letters.append(c)