Refactored
This commit is contained in:
@@ -1,6 +1,44 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def create_test_state() -> np.array:
|
||||
return np.array([['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']])
|
||||
|
||||
|
||||
def create_empty_state() -> np.array:
|
||||
return np.array([['-', '-', '-'], ['-', '-', '-'], ['-', '-', '-']])
|
||||
|
||||
|
||||
def to_state_string(state, state_nex=None):
|
||||
sp = ' '
|
||||
sp_arrow = ' => '
|
||||
sp_ = [sp, sp_arrow, sp]
|
||||
|
||||
def col(str_in, state):
|
||||
str_out = str_in
|
||||
for c in range(0, 3):
|
||||
char = state[r][c]
|
||||
if char == '-':
|
||||
char = ' '
|
||||
str_out += "|" + char
|
||||
str_out += '|'
|
||||
return str_out
|
||||
|
||||
state_str = ''
|
||||
for r in range(0, 3):
|
||||
if state is not None:
|
||||
state_str = col(state_str, state)
|
||||
|
||||
if state_nex is not None:
|
||||
state_str += sp_[r]
|
||||
state_str = col(state_str, state_nex)
|
||||
|
||||
if r != 2:
|
||||
state_str += '\x0A'
|
||||
|
||||
return state_str
|
||||
|
||||
|
||||
def get_potential_moves(state: np.array) -> np.array:
|
||||
st = state.reshape(state.size)
|
||||
indices = [idx for idx, s in enumerate(st) if '-' in s]
|
||||
|
||||
Reference in New Issue
Block a user