def calcmoves(self): """ Updates the board possible moves using the game logic. The result is a dict with starting positions as keys and possible end positions as values. """ self.moves = {} for i in range(5): for j in range(9): if self[i][j] != NULL: self.moves[(i,j)] = logic.refine(self, (i,j), self.adjacent((i,j))) logic.clean(self, self.moves)
def successors(board, color): if board.children: return board.children stack = [] children = [] for pos in board.colored(color): if pos not in board.moves: continue start = pos chain = [] tuples = [] b = board.copy() tuples = board.moves[pos] while tuples: for move in tuples: cb = b.copy() newpos = move[0] cb.remove(logic.captured(cb, pos, move)) cb.move(pos, newpos) if move[1] != P: tups = logic.refine(cb, newpos, cb.adjacent(newpos), [((start), 0)] + chain) else: tups = [] chain.append(move) stack.append((cb.copy(), newpos, chain[:], tups[:])) del chain[-1] b, pos, chain, tuples = stack[-1] del stack[-1] while not tuples: children.append((b, start, chain)) try: b, pos, chain, tuples = stack[-1] del stack[-1] except IndexError: break return children