i am new to prolog for starters , i have tried giving the cube an initial state then used this app to scan it to give me set of possible solutions , etc etc , i am probably winging it but idk why it keeps giving the query false
just to be clear this is not an overall code that will solve every random state ever , i am definitely not at that stage of understanding prolog and this code is probably awful but go easy on me .
here is the code
% Definining the initial state
initial_state([
[yellow, blue, white],
[white, red, red],
[blue, yellow, yellow],
[red, white, orange],
[orange, blue, red],
[red, green, orange],
[green, red, green],
[blue, green, yellow],
[green, orange, blue],
[blue, green, yellow],
[red, orange, green],
[white, blue, white],
[red, orange, blue],
[orange, white, white],
[red, white, green],
[white, yellow, orange],
[green, yellow, yellow],
[yellow, blue, orange]
]).
% Defininig the solving moves
solving_moves([
r, d_, f2, u2, f, l, d2, f, u_, b2, d_, b_, r2, d2, l, f2, u2,
r, b2, l, b2, l
]).
% Defining the colors
color(green).
color(orange).
color(red).
color(white).
color(yellow).
color(blue).
% Defining the rotation predicates
rotate_right([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
rotate_left([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
rotate_up([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
rotate_down([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
rotate_front([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
rotate_back([A, B, C, D, E, F, G, H, I], [G, D, A, H, E, B, I, F, C]).
% Applying a move to the cube state
apply_move(r, Cube, NewCube) :-
rotate_right(Cube, NewCube).
apply_move(d_, Cube, NewCube) :-
rotate_down(Cube, NewCube),rotate_down(Cube, NewCube),rotate_down(Cube, NewCube).
apply_move(f2, Cube, NewCube) :-
rotate_front(Cube, NewCube),
rotate_front(Cube, NewCube).
apply_move(u2, Cube, NewCube) :-
rotate_up(Cube, NewCube),rotate_up(Cube, NewCube).
apply_move(f, Cube, NewCube) :-
rotate_front(Cube, NewCube).
apply_move(l, Cube, NewCube) :-
rotate_left(Cube, NewCube).
apply_move(d2, Cube, NewCube) :-
rotate_down(Cube, NewCube),
rotate_down(Cube, NewCube).
apply_move(f, Cube, NewCube) :-
rotate_front(Cube, NewCube).
apply_move(u_, Cube, NewCube) :-
rotate_up(Cube, NewCube),
rotate_up(Cube, NewCube),
rotate_up(Cube, NewCube).
apply_move(b2, Cube, NewCube) :-
rotate_back(Cube, NewCube),
rotate_back(Cube, NewCube).
apply_move(d_, Cube, NewCube) :-
rotate_down(Cube, NewCube),
rotate_down(Cube, NewCube),
rotate_down(Cube, NewCube).
apply_move(b_, Cube, NewCube) :-
rotate_back(Cube, NewCube),
rotate_back(Cube, NewCube),
rotate_back(Cube, NewCube).
apply_move(r2, Cube, NewCube) :-
rotate_right(Cube, NewCube),
rotate_right(Cube, NewCube).
apply_move(d2, Cube, NewCube) :-
rotate_down(Cube, NewCube),
rotate_down(Cube, NewCube).
apply_move(l, Cube, NewCube) :-
rotate_left(Cube, NewCube).
apply_move(f2, Cube, NewCube) :-
rotate_front(Cube, NewCube),
rotate_front(Cube, NewCube).
apply_move(u2, Cube, NewCube) :-
rotate_up(Cube, NewCube),
rotate_up(Cube, NewCube).
apply_move(r, Cube, NewCube) :-
rotate_right(Cube, NewCube).
apply_move(b2, Cube, NewCube) :-
rotate_back(Cube, NewCube),
rotate_back(Cube, NewCube).
apply_move(l, Cube, NewCube) :-
rotate_left(Cube, NewCube).
apply_move(b2, Cube, NewCube) :-
rotate_back(Cube, NewCube),
rotate_back(Cube, NewCube).
apply_move(l, Cube, NewCube) :-
rotate_left(Cube, NewCube).
% Applying a list of moves to the cube state
apply_moves([], Cube, Cube).
apply_moves([Move|Moves], Cube, FinalCube) :-
apply_move(Move, Cube, NewCube),
apply_moves(Moves, NewCube, FinalCube).
% Solving the cube
solve_cube(Solution) :-
initial_state(InitialState),
solving_moves(Moves),
apply_moves(Moves, InitialState, Solution).
inter galactic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.