Hello, I’m back again.
I’m stuck in my assignment (the same) but this time in more complex predicates
I think that I’m in the right path of reasoning but there are some things I can’t manipulate well enough to use in my code to solve the specific problem I’m going to explain.
Also, I don’t know if I should make another post of this or continue in this one?
If I need to please tell me
So here is some context.
Let’s say I have 3 rooms, room1, room2 & room3.
The shapes don’t really matter here so ill take the square I talked about previously.
All of them are square.
I can move in a room Up Down Left and Right (only by 1).
Each movement takes 1 unit of time to use(it doesn’t matter for my current problem it’s just for context)
If I have a special item(diagonalizer), it allows me to move in diagonal.
Each room have portals (I don’t know how many) that can teleport our current state in another room.
And we can come back too (Using a portal cost 1 unit of time).
room1 room2 room3
. . . . . . . . . x . . . . e
. t . . . . . . . . . . . x .
. . . . . . . t . . . . . . .
. . . . . . . . . . . . . . .
s . . . . . . . . . . . . . .
These are the rooms.
s= start ->pos(Line,Column)
t&x = portals
Here is how I see my problem.
state here means where am i (the position, the room and the time i’ve spent moving)
%Movments in a room.
move((state(pos(Line,Column), room(Index, shape(Shape,Dimension)), item(TheItem))),
(state(pos(Line2,Column2), room(Index2, shape(Shape2,Dimension2)), item(CollectedItem))),
%Verify if the movement is done in the same room
%If the index of the room is different, then there is a portal???
Index =:= Index2, Shape =:= Shape2, %this might change
%Verify if the resulting position of the movement is in the shape.
%Definition of possible movements
Right is Column+1, Left is Column-1, Up is Line+1, Down is Line-1,
%This is an if else statement inside another one.
%If the item is a diagonalizer, then we can move in diag,
%CollectedItem is a diagonaliser and Time remains unchanged.
%else, we cant move in diag, CollectedItem is nothing and Time
(item(TheItem) -> CollectedItem = diagonalizer, Time is TimeSpent,
member(Line2,[Up,Down]), member(Column2,[Left,Right]) ; %else
CollectedItem = nothing,
Time is TimeSpent+1,
(Column=:=Column2 -> member(Line2,[Up,Down]); Line2=:=Line, member(Column2,[Left,Right])) ).
As you can see, what my predicate move does is: it take a current state and verify if everything is correct (like if the positions are inside the shapes) to move us to the second state. It also takes the previous time spent and returns the new time cost with that movement.
I’m problem is :
I thought about adding a list of portals to room like this :
portals would be some position
pos(Line,Collums) that represents if there is a portal in that position.(btw i really don’t know if i think right to solve that)
The thing is, how can even access that lists and tell my predicate move that if we are in a portal, then allow the index to be different. And verify that the portal takes us to the right index / position in the next room. Is it possible to deconstruct the elements of the list to use them?
In a OOP language i would have used a portal class but i dont see how to do it in here .
This is how i see my portals inside the list:
portail(pos(Line,Column), Id). % Id to recognize them x)
My brain hurts .
I’m sorry it’s a lot of code but I needed to give the context for you to understand me.
If there is something unclear tell, me :S.
Thanks a lot.