0

I'm wondering how to run BFS algorithm for rubik cube that is an input parameter of my function. So far I have created functions rotateUp(cubeIn, cubeOut), rotateDown(cubeIn, cubeOut2), rotateFront(cubeIn, cubeOut), rotateBack(cubeIn, cubeOut), rotateLeft(cubeIn, cubeOut), rotateRight(cubeIn, cubeOut) to rotate every single side of rubik cube.

Now I'm about to run some recursive function, where I can rotate my cube every possible way and then chceck if rubik cube is solved.

I already tried this solution but its going only deeper and deeper:

bfs(cubeIn) :-
        rotateUp(cubeIn, cubeOut1), bfs(cubeOut1),
        rotateDown(cubeIn, cubeOut2), bfs(cubeOut2),
        rotateFront(cubeIn, cubeOut3), bfs(cubeOut3),
        rotateBack(cubeIn, cubeOut4), bfs(cubeOut4),
        rotateLeft(cubeIn, cubeOut5), bfs(cubeOut5),
        rotateRight(cubeIn, cubeOut6), bfs(cubeOut6).

So I wanted to implement BFS algorithm for my rubik cube issue and I made this one:

bfs(cubeIn) :-
        rotateUp(cubeIn, cubeOut1),
        rotateDown(cubeIn, cubeOut2),
        rotateFront(cubeIn, cubeOut3),
        rotateBack(cubeIn, cubeOut4),
        rotateLeft(cubeIn, cubeOut5),
        rotateRight(cubeIn, cubeOut6),
        bfs(cubeOut1),bfs(cubeOut2),bfs(cubeOut3),
        bfs(cubeOut4),bfs(cubeOut5),bfs(cubeOut6).

But in the end it is still not working like BFS. Don't you have any idea what I'm doing wrong there?

Petr Bečka
  • 774
  • 3
  • 16
  • 39
  • ?? variables **must** start uppercase – CapelliC Apr 29 '17 at 16:48
  • @CapelliC let's say it is a pseudocode, I have more operations inside bfs(), I just wanted to show what I'm about to create.. – Petr Bečka Apr 29 '17 at 17:07
  • So, how do you pass the state around ? of course, you could do with some hack - binding **constants** like cubeOut1 to actual data structures, but seems completely useless... maybe you should show something like `bfs(CubeIn) :- rotateUp(CubeIn, CubeOut1), rotateDown(CubeOut1, CubeOut2), ...` – CapelliC Apr 29 '17 at 17:11
  • First only define **one** transition, then use [this](http://stackoverflow.com/q/30328433/772868) – false Apr 29 '17 at 20:00
  • I am not using BFS for solver but still this: [Quaternion rotation do not works as excepted](http://stackoverflow.com/a/39024016/2521214) might get you some ideas – Spektre Apr 30 '17 at 07:56

0 Answers0