TODO: Move method into model, as it deals with relationship between units.

+ FIXME: Some fields are left out for some reason.

# basic optimization: only check a hex-„square“ around the blob.

- dist = ~~0.5*(abs(x)+abs(y)+abs(z)~~)

+ dist = self.distance(self.hex_x, self.hex_y, self.hex_x + x, self.hex_y + y)

if dist <= self.max_move:

# don’t list those places which are already taken.

hexunit = self.hexmap.get(pos, None)

- if not path: # ~~no path to target~~

+ if not path: # target not reachable in any way.

for pos in path[:self.max_move]:

+ def twopos2fourhex(self, pos1, pos2):

+ return pos1[0], pos1[1], pos2[0], pos2[1]

+ def free_neighbor_nodes(self, pos):

+ return [(h[0] + pos[0], h[1] + pos[1]) for h in hex_vectors[1:] if self.hexmap.get((h[0] + pos[0], h[1] + pos[1]), None) is None]

+ def dist_heuristic(self, pos1, pos2):

+ """The estimated distance between two nodes."""

+ return self.distance(*self.twopos2fourhex(pos1, pos2))

"""Find the cheapest path towards the goal hex.

:return: the list of hexes to traverse or None (if no path could be found).

- def twopos2fourhex(pos1, pos2):

- return pos1[0], pos1[1], pos2[0], pos2[1]

- def free_neighbor_nodes(pos):

- return [(h[0] + pos[0], h[1] + pos[1]) for h in hex_vectors[1:] if self.hexmap.get((h[0] + pos[0], h[1] + pos[1]), None) is None]

- def dist_heuristic(pos1, pos2):

- """The estimated distance between two nodes."""

- return hexgrid_distance(*twopos2fourhex(pos1, pos2))

#: TODO: replace by weighted distances which allow different terrains to have different real costs between neighboring nodes.

+ dist = self.dist_heuristic

def reconstruct(previous, current):

p = reconstruct(previous, previous[current])

return reconstruct(previous, previous[goal])

- for neighbor in free_neighbor_nodes(current):

+ for neighbor in self.free_neighbor_nodes(current):

if neighbor in closed: continue

g_tentative = g[current] + dist(current, neighbor)

if not neighbor in openset:

- h[neighbor] = dist_heuristic(neighbor, goal)

+ h[neighbor] = self.dist_heuristic(neighbor, goal)

tentative_is_better = True

elif g_tentative < g[neighbor]:

tentative_is_better = True

# if we have no enemies, just don’t move

return self.hex_x, self.hex_y

+ # otherwise find the possible target which is closest to an enemy

nearest = possible_targets[0]

dist_nearest = self.distance(nearest[0], nearest[1], enemies[0].hex_x, enemies[0].hex_y)

for field in possible_targets: