Spaces:
Build error
Build error
Fix bug in state update
Browse filesFix tests to include that bug test and refactor step_test
Files changed (2)
160 unmodified lines161162163164165166167168160 unmodified linesoffset = 1 + cint * WORDLE_N * 3if goal_word[i] != c:if c in goal_word and goal_word.count(c) > processed_letters.count(c):# Char at position i = no, and in other positions maybe, other chars stay as they arestate[offset:offset + 3 * WORDLE_N] = [0, 1, 0] * WORDLE_Nstate[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]reward += CHAR_REWARD * 0.1else:160 unmodified lines161162163164165166167168169170171160 unmodified linesoffset = 1 + cint * WORDLE_N * 3if goal_word[i] != c:if c in goal_word and goal_word.count(c) > processed_letters.count(c):# Char at position i = no, and in other positions maybe except it had a value before, other chars stay as they arefor char_idx in range(0, WORDLE_N * 3, 3):char_offset = offset + char_idxif tuple(state[char_offset: char_offset + 3]) == (0, 0, 0):state[char_offset: char_offset + 3] = [0, 1, 0]state[offset + 3 * i:offset + 3 * i + 3] = [1, 0, 0]reward += CHAR_REWARD * 0.1else:
6 unmodified lines7891011121397 unmodified lines1111121131141151164 unmodified lines1211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172186 unmodified lines"APPAA","APPAB","APPAC","APPAD","BPPAB","BPPAC",97 unmodified linesexcept ValueError:passdef test_step(wordleEnv):wordleEnv.reset(seed=13)4 unmodified linesassert state.remaining_steps(cur_state) == wordleEnv.max_turnsassert state.remaining_steps(new_state) == wordleEnv.max_turns-1# Expect B to be all 1,0,0offset = 1+3*5*(ord('B')-ord('A'))assert tuple(new_state[offset:offset+15]) == tuple([1, 0, 0]*5)# Expect A to be right in position 0 4 and maybe otherwiseoffset = 1assert tuple(new_state[offset:offset+15]) == (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 0)# Expect P to be right in position 2 3 and maybe otherwiseoffset = 1 + 3*5*(ord('P') - ord('A'))assert tuple(new_state[offset:offset+15]) == (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 0, 0)# Expect C to be maybesoffset = 1 + 3*5*(ord('C') - ord('A'))assert tuple(new_state[offset:offset+15]) == (1, 0, 0,1, 0, 0,1, 0, 0,1, 0, 0,0, 0, 0)cur_state = wordleEnv.statenew_state, reward, done, _ = wordleEnv.step(1)assert state.remaining_steps(cur_state) == wordleEnv.max_turns-1assert state.remaining_steps(new_state) == wordleEnv.max_turns-2# Expect B to be all 1,0,0offset = 1+3*5*(ord('B')-ord('A'))assert tuple(new_state[offset:offset+15]) == tuple([1, 0, 0]*5)# Expect A to be right in position 0 4 and maybe otherwiseoffset = 1assert tuple(new_state[offset:offset+15]) == (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 0)# Expect P to be right in position 2 3 and maybe otherwiseoffset = 1 + 3*5*(ord('P') - ord('A'))assert tuple(new_state[offset:offset+15]) == (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 0, 0)new_state, reward, done, _ = wordleEnv.step(2)assert state.remaining_steps(new_state) == wordleEnv.max_turns-3# Expect B to be all 1,0,0offset = 1 + 3*5*(ord('B')-ord('A'))assert tuple(new_state[offset:offset+15]) == tuple([1, 0, 0]*5)# Expect C to be all 1,0,0offset = 1+3*5*(ord('C')-ord('A'))assert tuple(new_state[offset:offset+15]) == tuple([1, 0, 0]*5)# Expect A to be right in position 0 4 and maybe otherwiseoffset = 1assert tuple(new_state[offset:offset+15]) == (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 0)# Expect P to be right in position 2 3 and maybe otherwiseoffset = 1 + 3*5*(ord('P') - ord('A'))assert tuple(new_state[offset:offset+15]) == (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 0, 0)new_state, reward, done, _ = wordleEnv.step(0)# Expect A to be right in position 0 4 and 5offset = 1assert tuple(new_state[offset:offset+15]) == (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 1)# Expect P to be right in position 2 3 and not otherwiseoffset = 1 + 3*5*(ord('P') - ord('A'))assert tuple(new_state[offset:offset+15]) == (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,1, 0, 0)assert state.remaining_steps(new_state) == wordleEnv.max_turns-4assert doneassert wordleEnv.done6 unmodified lines7891011121397 unmodified lines1111121131141151161171181194 unmodified lines1241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202216 unmodified lines"APPAA","APPAB","APPAC","APAPD","BPPAB","BPPAC",97 unmodified linesexcept ValueError:passdef letter_test(char, state, letter_state):offset = 1+3*5*(ord(char)-ord('A'))assert tuple(state[offset:offset+15]) == letter_statedef test_step(wordleEnv):wordleEnv.reset(seed=13)4 unmodified linesassert state.remaining_steps(cur_state) == wordleEnv.max_turnsassert state.remaining_steps(new_state) == wordleEnv.max_turns-1# Expect B to be all 1,0,0letter_test('B', new_state, tuple([1, 0, 0]*5))# Expect A to be right in position 0 3, no in 1 2 and 0 otherwiseletter_state = (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 0)letter_test('A', new_state, letter_state)# Expect P to be right in position 1 2, no in 0 2 and 0 otherwiseletter_state = (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 0, 0)letter_test('P', new_state, letter_state)# Expect C to be no everywhere except in 4letter_state = (1, 0, 0,1, 0, 0,1, 0, 0,1, 0, 0,0, 0, 0)letter_test('C', new_state, letter_state)cur_state = wordleEnv.statenew_state, reward, done, _ = wordleEnv.step(3)assert state.remaining_steps(cur_state) == wordleEnv.max_turns-1assert state.remaining_steps(new_state) == wordleEnv.max_turns-2# Expect D to be all 1,0,0letter_state = tuple([1, 0, 0]*5)letter_test('D', new_state, letter_state)# Expect A to be right in position 0 3 and Maybe in 4letter_state = (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 1, 0)print(new_state, letter_state)letter_test('A', new_state, letter_state)# Expect P to be right in position 1 2 no in 3 and maybe in 4letter_state = (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 1, 0)letter_test('P', new_state, letter_state)new_state, reward, done, _ = wordleEnv.step(2)assert state.remaining_steps(new_state) == wordleEnv.max_turns-3# Expect B to be all 1,0,0letter_state = tuple([1, 0, 0]*5)letter_test('C', new_state, letter_state)# Expect C to be all 1,0,0letter_state = tuple([1, 0, 0]*5)letter_test('C', new_state, letter_state)# Expect A to be right in position 0 3 and, no 3 and maybe otherwiseletter_state = (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 1, 0)letter_test('A', new_state, letter_state)# Expect P to be right in position 1 2, no in 0 3 and maybe otherwiseletter_state = (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,0, 1, 0)letter_test('P', new_state, letter_state)new_state, reward, done, _ = wordleEnv.step(0)# Expect A to be right in position 0 3 and 4letter_state = (0, 0, 1,1, 0, 0,1, 0, 0,0, 0, 1,0, 0, 1)letter_test('A', new_state, letter_state)# Expect P to be right in position 1 2 and not otherwiseletter_state = (1, 0, 0,0, 0, 1,0, 0, 1,1, 0, 0,1, 0, 0)letter_test('P', new_state, letter_state)assert state.remaining_steps(new_state) == wordleEnv.max_turns-4assert doneassert wordleEnv.done
wordle_env/state.py+5-2
wordle_env/test_wordle.py+85-82