graphs – Finding an optimal solution in a tile painting game

I’m crossposting this question from Mathematics Stack Exchange since it seems better suited here.
Images are posted as links because I don’t have enough points, sorry.

The Problem

Find the shortest sequence of moves that makes up the optimal solution of a level. If there is more than one optimal solution, just find one of them.

Game Rules

The game level is made up of two types of tiles: walls and floors. The player’s task is to paint the whole level using a ball that can be moved in four directions (up, down, left, right). When a direction is chosen, the ball will move in the indicated direction until it hits the wall (it cannot be stopped midway).

The tile the player starts on is automatically painted at the beginning of the game.

There are many games of this type on the Google Play store like Amaze! by Crazy Labs or Roller Splat! by VOODOO.

Here’s one you can play in a browser.


Here is an example of a very simple game level.

image – Simple game level

The optimal solution requires 3 moves: ↓, →, ↑.

Helper Graph

For each level it is possible to create a graph showing in which positions the player can find themselves after a move and in which directions they can move the ball.

For the level above, the graph looks like this, where S is the initial position.

image – Graph representation

This is how a graph looks overlaid on a level.

image – Overlaid graph

These graphs are directional, you can’t always go directly back to the previous position.

In the example below, if the player moves the ball to the right and then moves left, they will find themselves at a different vertex of the graph than the initial one.

image – step0
image – step1
image – step2

Solution attempt

The simplest solution is to search all possible paths and choose the shortest one. The maximum length of the solution must be limited to avoid an infinite loop.

Using the DFS algorithm, search through all possible paths:

  1. Starting from the spawn position, branches are created to look for a solution in every possible direction.
  2. A branch reaches a vertex of the graph, chooses one of the possible directions to go and continues exploring. From the same vertex new branches that will look for a solution in every other possible direction are created.
  3. When a branch passes through all the floor tiles of the level, it ends its exploration. The solution found is saved if it is better than the previous best solution.
  4. If the length of the branch’s solution exceeds the length limit, it gets disposed of.

This algorithm allows to find a solution of levels, but only with a length limit of no more than 12 steps. The complexity of this solution is O(3^n) (because after each step there may be 3 directions to choose from).

By applying a number of optimisations, the computation time for this algorithm can be significantly reduced.


  1. Marking unidirectional vertices as fully visited.
    If a vertex has only one edge, we can be sure that once it has been visited once, it will definitely not need to be revisited.

  2. Mark vertices with fully visited neighbours as fully visited.
    Edges leading to fully visited vertices need not be taken into account when choosing the next solution step. If a vertex has only one edge that does not lead to fully visited vertices, it can be treated as unidirectional, i.e., it can be marked as fully visited.

  3. Removing unnecessary loops.
    If the branch finds itself in a previously visited vertex, and has not painted any additional tiles since visiting it, the solution is bound to be suboptimal.
    This is the most effective of the presented optimisations, it reduces the number of branches needed to find a solution by 5-30 times, depending on the level layout.

  4. Removing branches that are too long.
    Branches longer than the current best solution found can be discarded.

Applying these optimisations allows us to find a solution for levels requiring up to 20 steps (which take about 5 minutes to compute on my computer). Extending the maximum length by each additional step increases the number of branches needed by 1.2 to 2 times (depending on the level layout).

Suggested further optimisations

Further optimisations can be added to this approach, e.g:

  1. Using Tarjan’s algorithm to split the level into strongly connected components. Once all the floor tiles in a connected component have been painted, the whole component can be marked as fully visited.

  2. Earlier discaring of branches that have no chance to paint all remaining tiles in fewer moves than the current best solution.

Certainly such optimizations would speed up the algorithm, but will not overcome its geometrically increasing complexity.

Can you propose a different approach, that could find the optimal solution with a lower complexity, or another optimization that can speed up this approach?

photos – Which is the best Stucco Painting Experts Company In Albuquerque?

photos – Which is the best Stucco Painting Experts Company In Albuquerque? – Ask Different

photos – Which is the best Stucco Painting Experts Company In Albuquerque?

photos – Which is the best Stucco Painting Experts Company In Albuquerque? – Ask Different

Where’s this wall painting in Warsaw?

Can anyone tell me where I can find this painting?

Thanks so much

germany – Identify location (and painter) of old painting

I have received this painting from my grandma recently. However, she is unable to identify the location of this painting. Additionally, I am unsure about the name of the painter (lower right corner). I think I know what it is, but I will not add it to prevent priming you guys.
Also, if you have any ideas to where I could post this question too, I am open to suggestions!

(!(Complete image))(1))1)1





Name zoomed in

animation – Blender to Unity weight painting doesn’t carry over nicely

How to get Blender weight painting to work smoothly in Unity?

Here’s my workflow:
-Do weight painting in Blender.
-Do animations in Blender.
-Export FBX.
-Import in Unity
-Set avatar to humanoid(bones are a perfect match)

But the animation doesn’t play as smoothly as in Blender and deformations do not stretch correctly.

In Unity:

enter image description here

In Blender:

enter image description here

The animations work correctly overall, just doesn’t in some parts such as the knee.

customs and immigration – UK tax on an amber painting coming from abroad

Unsure if this is in the right section of Stack Exchange but, I have a family member coming to the UK (from outside of the EU) in the near immediate future.

They will be bringing a painting with them that contains at least 100g of Amber, if not more. It’s a gift.

Will they have to declare this upon arrival?
And will they have to pay tax on this?

I am not sure how much the painting costs exactly, but it’s less than £100 for sure. It’s coming from Ukraine.

Are there any official bodies I can contact in the UK to find out for sure?

Again, apologies if this is in the incorrect section.

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies 5000 Private Proxies - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies New Proxy Lists Every Day Buy Cheap Private Proxies; Best Quality USA Private Proxies