4

I just stumbled upon a strange (and very annoying game) that I wanted to solve programmatically. It reminds a bit of Rubik's cube, but 2 dimensional. I'm struggling a bit on how to approach this...

There is a 9x9 square with some circles placed into the inner squares. For instance, one get's the following picture:

       A   B   C   D   E   F   G   H   I                      
     -------------------------------------                    
   9 |   |   | O |   |   | O |   |   |   | J                 
     -------------------------------------                    
   8 |   |   | O |   | O |   | O |   |   | K                  
     -------------------------------------                    
   7 |   |   |   | O |   |   | O | O |   | L                  
     -------------------------------------                    
   6 |   |   | O |   |   |   | O |   |   | M                  
     -------------------------------------                    
   5 |   |   | O |   |   |   |   |   |   | N                  
     -------------------------------------                    
   4 |   |   |   | O |   | O | O |   |   | O                  
     -------------------------------------                    
   3 |   |   |   |   | O |   | O |   |   | P                  
     -------------------------------------                    
   2 |   |   |   | O |   |   |   |   |   | Q                  
     -------------------------------------                    
   1 |   |   | O |   |   |   |   |   |   | R                  
     -------------------------------------                    
       0   Z   Y   X   W   V   U   T   S                      

One can use the numbers and letters arround the square to shift entire "rows" or "columns" to either left/right or up/down. Circles that would leave the game area to the right would reappear on the left and vise-versa, same accounts for top/bottom.

The goal is to rearrange the circles to a given pattern with a maximum amount of moves. For instance, one should rearrange the circles in the above picture to reflect the below picture in maximum 17 moves:

       A   B   C   D   E   F   G   H   I                      
     -------------------------------------      
   9 |   |   |   |   |   |   |   |   |   | J                  
     -------------------------------------      
   8 |   |   | O | O | O | O | O |   |   | K                  
     -------------------------------------      
   7 |   |   | O |   |   |   | O |   |   | L                  
     -------------------------------------        
   6 |   |   | O |   |   |   | O |   |   | M                  
     -------------------------------------                    
   5 |   |   | O |   |   |   | O |   |   | N          
     -------------------------------------              
   4 |   |   | O |   |   |   | O |   |   | O        
     -------------------------------------           
   3 |   |   | O | O | O | O | O |   |   | P       
     -------------------------------------         
   2 |   |   |   |   |   |   |   |   |   | Q                  
     -------------------------------------                    
   1 |   |   |   |   |   |   |   |   |   | R                  
     -------------------------------------         
       0   Z   Y   X   W   V   U   T   S                      

I would like to feed the starting and the end position of the circles to a program that delivers the shortest path possible. I'm struggling a bit to find an approach that doesn't just try all possible moves until a given maximum number of moves is reached.

Also it doesn't seem to be that easy to modify the approach that's being used to solve a Rubik's cube for instance...

Well, I thought it was a very interesting problem, and maybe somebody here has an illuminating idea.

UPDATE: Just trying all the possible moves doesn't really seem realistic after a first try. There are just too many permutations. I think this could be really hard to solve...if possible at all.

braX
  • 11,506
  • 5
  • 20
  • 33
inzanez
  • 366
  • 1
  • 16
  • 2
    Nice problem. Before you hurt your head though, I'd stop with this approach "I would like to feed the starting and the end position of the circles to a program that delivers the shortest path possible". I doubt you'll find such an optimal algorithm. You'd probably be better off with heuristics, or trying to do it within a certain bounded number of moves. The Rubik's cube algorithms that exist are the same- there's no "optimal algorithm" for this, and many bright minds have been working on it for over 30 years – Colm Bhandal Oct 15 '17 at 12:33
  • A exhaustive search of the problem space will reveal the optimum solution. But that'd probably take a really long time. But it's a good place to start, and then use heuristics to reduce the complexity. – Jim Mischel Oct 15 '17 at 13:43
  • Well, I just wonder if the heuristics approach of the 'Rubik's Cube' algorithm is good enough to reduce complexity to a level that a normal computer can handle. I'm not so sure anymore...:-) But I agree, it would make more sense to solve it with a certain amount of moves. But again, 40 moves maximum for instance still results in a huge amount of possibilities. – inzanez Oct 15 '17 at 20:12

0 Answers0