tree init
This commit is contained in:
parent
8c4eb355bf
commit
b61912aaed
46
main.py
46
main.py
@ -258,14 +258,25 @@ def rot_hash_board(board):
|
|||||||
|
|
||||||
|
|
||||||
class Node(object):
|
class Node(object):
|
||||||
def __init__(self, board):
|
def __init__(self, board, move, parent_node):
|
||||||
|
self.parent = parent_node
|
||||||
self.board = board
|
self.board = board
|
||||||
self.moves = gen_moves(board)
|
self.move = move
|
||||||
|
|
||||||
|
if self.parent:
|
||||||
|
self.moves = self.parent.moves + [move]
|
||||||
|
else:
|
||||||
|
if move:
|
||||||
|
self.moves = [move]
|
||||||
|
else:
|
||||||
|
self.moves = []
|
||||||
self.visited = False
|
self.visited = False
|
||||||
self.children = []
|
self.complete = False
|
||||||
|
|
||||||
|
self.children = gen_moves(self.board)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def iterative_main():
|
||||||
board = deepcopy(STARTING_BOARD)
|
board = deepcopy(STARTING_BOARD)
|
||||||
moves_this_game = []
|
moves_this_game = []
|
||||||
while True:
|
while True:
|
||||||
@ -282,9 +293,30 @@ def main():
|
|||||||
|
|
||||||
this_move = moves_this_game[-1]
|
this_move = moves_this_game[-1]
|
||||||
board = undo_move(this_move, board)
|
board = undo_move(this_move, board)
|
||||||
this_move = moves[0]
|
else:
|
||||||
moves_this_game.append(this_move)
|
this_move = moves[0]
|
||||||
board = play_move(this_move, board)
|
moves_this_game.append(this_move)
|
||||||
|
board = play_move(this_move, board)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
root = Node(board=STARTING_BOARD, move=None, parent_node=None)
|
||||||
|
node = root
|
||||||
|
while True:
|
||||||
|
if len(node.moves) == 0:
|
||||||
|
pawns_left = count_pawns(node.board)
|
||||||
|
if pawns_left == 1:
|
||||||
|
print("WIN")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# backtrack
|
||||||
|
node.visited = True
|
||||||
|
board = undo_move(node.move, node.board)
|
||||||
|
else:
|
||||||
|
# there is at least one move
|
||||||
|
move = moves[0]
|
||||||
|
new_board = play_move(move, node.board)
|
||||||
|
node = Node(new_board, move, node)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user