def finishTree(grid, depth=0): tree = {} grid = Translate.GridMax(grid)[0] if depth > 5: return {grid: 'Depth'} if gameOver(grid) != 0: tree[grid] = gameOver(grid) else: tree[grid] = fillTwo(grid) for item in fillTwo(grid): addDict(tree, finishTree(item, depth + 1)) return tree
def fillTwo(grid): results = [] if gameOver(grid) != 0: return gameOver(grid) #return [grid] if grid.count(1) > grid.count(2): return fillOne(grid) for x in grid.getEmptySpaces(): grid1 = grid[:] grid1[x] = 1 if gameOver(grid1) != 0: results.append(grid1) continue results += fillOne(grid1) return results
def filterGameOver(grid, y=None): try: x = gameOver(grid) except: return 0 else: if y == None: return 1 elif x == y: return 1 else: return 0