# A* heuristic for the game Blockage

There is a flash game that you can very easily find on Google called Blockage.

Rules & Goal of the game : Get all coloured blocks from their initial position to a corresponding target spot of the same color. Once a block is placed on a target spot of the same color, it cannot move anymore. You can select a specific block and move it left or right. Blocks are also subject to gravity (moving them vertically until they hit a wall or another block). There can be many blocks of the same color and more blocks than target spots. Obstacles include walls and other blocks (two blocks cannot be at the same position).

I would like to implement an $A^*$ algorithm that finds the sequence of steps to win this game.

I am currently thinking about a good heuristic $h(n)$ to use. The best one I could find is the following : the sum of the Manhattan distances between each colored block and its closest target.

Any idea on a better heuristic?

• Ok! I've added the rules :) – Dory Oct 29 '17 at 19:57
• In AIMA, there is a "heuristic" for creating heuristics; Take the rules and relax them. This often gives natural heuristics that never overestimate the cost. Have you tried this approach? – Pål GD Oct 29 '17 at 21:52
• Yes. The heuristic I proposed in my post is in fact implicitly relaxing the gravity constraint. However, I just realized that it makes the heuristic non-admissible because gravity tends to decrease the cost from start to goal when Manhattan distance would overestimate it. For the moment the only heuristic I can think of is something like "the horizontal distance between target and block". But I feel like it's a poor heuristic. – Dory Oct 30 '17 at 10:42