views:

44

answers:

0

Hi,

i have a problem with a variable in Prolog. I must resolve the tantrix domino in prolog, this is a game size by 56 hexagonal tile with 4 different color on sides. The tantrix domino consist to align the different tile so the colour match. Each tile can be rotated to match the colors with the previous tile.

In Prolog i have three different function: -rotation(X,Y,[]): X is the tile number, Y is the number of rotation (0 to 5) and [] is a list of colours of the tile after the rotation. -canMatch(tile1,rot1,tile2,rot2): tile1 is the firt tile, tile2 is the second tile, rot1 and rot2 are the rotation that two tile should take to match. -permutation([],[]): i find all the permutation of tiles that match.

So, i have a problem with the last function. I should save the last rotation: for example: tile1,zero,tile2,one tile2,one,tile3,five

Now without save variable i have zero in the first rotation for each tile for example: tile1,zero,tile2,one tile2,zero,tile3,four

this is the function permutation: permutation([],[]). permutation([X|L],P) :- permutation(L,L1),insert(X,L1,P),first(J,L1),canMatch(X,ROT1,J,ROT2), write(X),write(ROT1),write(J),write(ROT2),writeln(L).

first(J,L1): keep the first next tile

Any idea to save the last rotation?

Thanks Serena