add evaulation function
This commit is contained in:
parent
9d7cfee1f9
commit
467e53b1ce
1
TODO
1
TODO
|
@ -3,6 +3,7 @@ TODO
|
|||
|
||||
- make an interface for picking moves
|
||||
- make an interface, period
|
||||
- back-propagate values up the tree
|
||||
|
||||
BUGS
|
||||
----
|
||||
|
|
18
cli.py
18
cli.py
|
@ -16,7 +16,20 @@ piecemaps = {
|
|||
}
|
||||
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
|
||||
print("considering board with moveset " + str(parent.inner.moves))
|
||||
|
||||
|
@ -30,7 +43,7 @@ def tree_of_node(node):
|
|||
childnode.inner = copy
|
||||
parent.children.append(childnode)
|
||||
for i in parent.children:
|
||||
tree_of_node(i)
|
||||
tree_of_node(i, count - 1)
|
||||
else:
|
||||
print("calculated score")
|
||||
rawscore = BoardTools.winning(None, parent.inner.metaboard())
|
||||
|
@ -45,6 +58,7 @@ def tree_of_node(node):
|
|||
raise StateError("aaaa")
|
||||
|
||||
print("score" + str(score))
|
||||
return score
|
||||
|
||||
def render(board):
|
||||
print("123 456 789")
|
||||
|
|
15
pos.py
15
pos.py
|
@ -21,10 +21,17 @@ class TwoDPos:
|
|||
l = 1
|
||||
def __init__(self, mode, param):
|
||||
if mode == TwoDPos.g:
|
||||
self.pos = (
|
||||
TwoDUtils.mappings[param[0]],
|
||||
int(param[1]) - 1,
|
||||
)
|
||||
try:
|
||||
self.pos = (
|
||||
TwoDUtils.mappings[param[0]],
|
||||
int(param[1]) - 1,
|
||||
)
|
||||
except KeyError:
|
||||
self.pos = (
|
||||
int(param[0]) - 1,
|
||||
int(param[1]) - 1,
|
||||
)
|
||||
|
||||
elif mode == TwoDPos.l:
|
||||
self.pos = (
|
||||
param[0] * 3 + param[2],
|
||||
|
|
Loading…
Reference in New Issue