solution 1 found

This commit is contained in:
Daniel Tsvetkov 2021-12-29 21:28:51 +02:00
parent b61912aaed
commit 457e73c67f
2 changed files with 38 additions and 10 deletions

47
main.py
View File

@ -264,16 +264,33 @@ class Node(object):
self.move = move
if self.parent:
self.moves = self.parent.moves + [move]
self.prev_moves = self.parent.prev_moves + [move]
else:
if move:
self.moves = [move]
self.prev_moves = [move]
else:
self.moves = []
self.prev_moves = []
self.visited = False
self.complete = False
self.children = gen_moves(self.board)
self.moves = gen_moves(self.board)
self.children = {move: None for move in self.moves}
@property
def non_explored_moves(self):
rv = []
for move in self.children.keys():
node = self.get_node_from_move(move)
if not node.visited:
rv.append(move)
return rv
def get_node_from_move(self, move):
if self.children.get(move) is None:
self.children[move] = Node(play_move(move, deepcopy(self.board)), move, self)
return self.children[move]
def iterative_main():
@ -303,7 +320,7 @@ def main():
root = Node(board=STARTING_BOARD, move=None, parent_node=None)
node = root
while True:
if len(node.moves) == 0:
if len(node.non_explored_moves) == 0:
pawns_left = count_pawns(node.board)
if pawns_left == 1:
print("WIN")
@ -311,13 +328,23 @@ def main():
else:
# backtrack
node.visited = True
board = undo_move(node.move, node.board)
node = node.parent
else:
# there is at least one move
move = moves[0]
new_board = play_move(move, node.board)
node = Node(new_board, move, node)
move = node.non_explored_moves[0]
node = node.get_node_from_move(move)
def play_moves():
board = STARTING_BOARD
moves = input("> ")
for move in moves.split(','):
move = move.strip()[1:-1]
print(move)
board = play_move(move, board)
print_board(board)
if __name__ == "__main__":
main()
# main()
play_moves()

1
solution1 Normal file
View File

@ -0,0 +1 @@
['D2D4', 'B3D3', 'C1C3', 'E1C1', 'D3B3', 'A3C3', 'E3E1', 'G3E3', 'C4C2', 'C1C3', 'A4C4', 'C4C2', 'E4C4', 'G4E4', 'E4E2', 'E1E3', 'C5C3', 'C2C4', 'A5C5', 'D5B5', 'E6E4', 'G5E5', 'C7C5', 'C4C6', 'E7C7', 'C7C5', 'B5D5', 'D5F5', 'E3E5', 'F5D5', 'D5D7']