crappy algorithm
This commit is contained in:
parent
b30c1a7ffe
commit
842291d6d6
52
cli.py
52
cli.py
|
@ -1,8 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from board2 import Board
|
||||
from board2 import BoardTools
|
||||
from pos import TwoDPos
|
||||
from pos import TwoDUtils
|
||||
from node import Node
|
||||
|
||||
class StateError(BaseException):
|
||||
pass
|
||||
|
||||
piecemaps = {
|
||||
0: '.',
|
||||
|
@ -11,6 +16,36 @@ piecemaps = {
|
|||
}
|
||||
mappings = TwoDUtils.reverse
|
||||
|
||||
def tree_of_node(node):
|
||||
parent = node
|
||||
print("considering board with moveset " + str(parent.inner.moves))
|
||||
|
||||
possible = parent.inner.possible()
|
||||
if len(possible) != 0:
|
||||
print("permuting!")
|
||||
for i in possible:
|
||||
copy = parent.inner.copy()
|
||||
copy.append(i)
|
||||
childnode = Node()
|
||||
childnode.inner = copy
|
||||
parent.children.append(childnode)
|
||||
for i in parent.children:
|
||||
tree_of_node(i)
|
||||
else:
|
||||
print("calculated score")
|
||||
rawscore = BoardTools.winning(None, parent.inner.metaboard())
|
||||
if rawscore == Board.cross:
|
||||
score = -1
|
||||
elif rawscore == Board.nought:
|
||||
score = 1
|
||||
elif rawscore == Board.tie:
|
||||
score = 0
|
||||
else:
|
||||
score = None
|
||||
raise StateError("aaaa")
|
||||
|
||||
print("score" + str(score))
|
||||
|
||||
def render(board):
|
||||
print("123 456 789")
|
||||
moves = board.possible()
|
||||
|
@ -36,7 +71,7 @@ def render(board):
|
|||
|
||||
print("to play: " + str(board.turn))
|
||||
|
||||
def help():
|
||||
def help_text():
|
||||
print("m - make a move")
|
||||
print("p - see coordinates of legal moves")
|
||||
print("t - see whose turn it is")
|
||||
|
@ -59,7 +94,7 @@ def main():
|
|||
b = Board()
|
||||
print("type h for help")
|
||||
while True:
|
||||
try:
|
||||
# try:
|
||||
cmd = input("> ")
|
||||
spl = cmd.split(' ')
|
||||
if spl[0] == "m":
|
||||
|
@ -71,11 +106,18 @@ def main():
|
|||
elif spl[0] == "r":
|
||||
render(b)
|
||||
elif spl[0] == "h":
|
||||
render(b)
|
||||
help_text()
|
||||
elif spl[0] == "z":
|
||||
# create node from current board
|
||||
node = Node()
|
||||
node.inner = b
|
||||
|
||||
tree_of_node(node)
|
||||
|
||||
elif spl[0] == "q":
|
||||
break;
|
||||
except:
|
||||
print("error occured")
|
||||
# except:
|
||||
# print("error occured")
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue