add evaulation function

This commit is contained in:
randomuser 2022-09-14 19:56:11 -05:00
parent 9d7cfee1f9
commit 467e53b1ce
3 changed files with 28 additions and 6 deletions

1
TODO
View File

@ -3,6 +3,7 @@ TODO
- make an interface for picking moves - make an interface for picking moves
- make an interface, period - make an interface, period
- back-propagate values up the tree
BUGS BUGS
---- ----

18
cli.py
View File

@ -16,7 +16,20 @@ piecemaps = {
} }
mappings = TwoDUtils.reverse mappings = TwoDUtils.reverse
def tree_of_node(node): def tree_of_node(node, count=5):
if count == 1:
score = 0
for i in range(9):
for j in range(9):
p = TwoDPos(TwoDPos.g, (i + 1, j + 1))
a, b, c, d = p.local()
if node.inner.board[a][b][c][d] == Board.cross:
score += 1
elif node.inner.board[a][b][c][d] == Board.nought:
score -= 1
return score
parent = node parent = node
print("considering board with moveset " + str(parent.inner.moves)) print("considering board with moveset " + str(parent.inner.moves))
@ -30,7 +43,7 @@ def tree_of_node(node):
childnode.inner = copy childnode.inner = copy
parent.children.append(childnode) parent.children.append(childnode)
for i in parent.children: for i in parent.children:
tree_of_node(i) tree_of_node(i, count - 1)
else: else:
print("calculated score") print("calculated score")
rawscore = BoardTools.winning(None, parent.inner.metaboard()) rawscore = BoardTools.winning(None, parent.inner.metaboard())
@ -45,6 +58,7 @@ def tree_of_node(node):
raise StateError("aaaa") raise StateError("aaaa")
print("score" + str(score)) print("score" + str(score))
return score
def render(board): def render(board):
print("123 456 789") print("123 456 789")

15
pos.py
View File

@ -21,10 +21,17 @@ class TwoDPos:
l = 1 l = 1
def __init__(self, mode, param): def __init__(self, mode, param):
if mode == TwoDPos.g: if mode == TwoDPos.g:
self.pos = ( try:
TwoDUtils.mappings[param[0]], self.pos = (
int(param[1]) - 1, TwoDUtils.mappings[param[0]],
) int(param[1]) - 1,
)
except KeyError:
self.pos = (
int(param[0]) - 1,
int(param[1]) - 1,
)
elif mode == TwoDPos.l: elif mode == TwoDPos.l:
self.pos = ( self.pos = (
param[0] * 3 + param[2], param[0] * 3 + param[2],