diff --git a/TODO b/TODO index b3f841e..1eaee50 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,7 @@ TODO - make an interface for picking moves - make an interface, period +- back-propagate values up the tree BUGS ---- diff --git a/cli.py b/cli.py index 1148d29..cf009e3 100644 --- a/cli.py +++ b/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") diff --git a/pos.py b/pos.py index e1671d7..8189a09 100644 --- a/pos.py +++ b/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],