- refacored state
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
import numpy as np
|
||||
from numpy.random import uniform
|
||||
|
||||
|
||||
class APlayer(object):
|
||||
def __init__(self, mark):
|
||||
self.mark = mark
|
||||
self.other_mark = 'O'
|
||||
if 'O' in mark:
|
||||
self.other_mark = 'X'
|
||||
|
||||
self.state = None
|
||||
self.state_last = None
|
||||
|
||||
def move(self, state: np.array):
|
||||
return state, False
|
||||
|
||||
def new_game(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def f_state_slices():
|
||||
nr = 3
|
||||
nc = 3
|
||||
result = []
|
||||
# Create row finishing states
|
||||
d1 = ()
|
||||
d2_r = ()
|
||||
for r in range(0, nr):
|
||||
d1 += (r,)
|
||||
for c in range(0, nc):
|
||||
d2 = (c,) * nc
|
||||
result.append((d1, d2))
|
||||
|
||||
# Create column finishing states
|
||||
for c in range(0, nc):
|
||||
d2 = (c,) * nc
|
||||
result.append((d2, d1))
|
||||
for c in range(0, nc):
|
||||
d2_r += (nc - c - 1,)
|
||||
|
||||
# Create diagonal finishing states #1
|
||||
result.append((d1, d1))
|
||||
|
||||
# Create diagonal finishing states #2
|
||||
result.append((d1, d2_r))
|
||||
|
||||
return result
|
||||
|
||||
def has_won(self, state: np.array):
|
||||
result = False
|
||||
ref = [self.mark, self.mark, self.mark]
|
||||
for f_state_slice in APlayer.f_state_slices():
|
||||
if np.all(state[f_state_slice] == ref):
|
||||
result = True
|
||||
break
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user