def heuristic(self, game): F = Flow(game.board) """ Gives a cost to the board state by measuring how far between growth points this also makes the cost max value when one path can't be moved :type game: Flow :return: double """ cost = len(game.paths) * 2 for color in game.paths: path = game.paths[color] if path.is_complete(): cost -= 2 continue gp1, gp2 = path.get_grow_points() # print abs((gp1[0] - gp2[0]) + (gp1[1] - gp2[1])), gp1, gp2 cost += abs((gp1[0] - gp2[0]) + (gp1[1] - gp2[1])) adjecent_points = utils.get_adjacent_points(gp1) if not F.is_valid(adjecent_points[0][0], adjecent_points[0][1]): if not F.is_valid(adjecent_points[1][0], adjecent_points[1][1]): if not F.is_valid(adjecent_points[2][0], adjecent_points[2][1]): if not F.is_valid(adjecent_points[3][0], adjecent_points[3][1]): cost = sys.maxint return cost # print game.board[1][1] # for i, value in enumerate(game.board): # for j in enumerate(game.board[i]): # if j[1] == '0': # cost += 1 return cost