I need to make a program in Prolog where a guy gets to the gas station, gets a soda and a newspaper and back to his car, the outcome should look something like this:
?- go.
>> goto(gas_station).
You are in the gas_station.
>> goto(car).
You can't get there from here.
>> open(car_door).
>> open(gas_station_door).
>> take(soda).
You now have a soda.
>> goto(car).
You are in the car
Thanks for getting the newspaper.
This is what i did so far:
place(car).
place(gas_station).
item(player , soda).
item(player , newspaper).
at(soda , gas_station).
at(newspaper , gas_station).
at(player , gas_station) :- door(car_door , open),
door(gas_station_door, open), nl.
at(player , gas_station) :-
write('Can't get there'), nl.
open(X) :-
assert(door(X , open).
goto(X) :-
at(player , X),
retract(at(player , X),
write('You are in the gas station.'),
nl.
take(X) :-
item(player , X),
write('You now have a soda and a newspaper'),
nl.
I am new to Prolog, i just want to know if what i did so far is somewhat correct, if i am on the right track, and how to continue from here because i am stack, i am not sure if it works how it is supposed to or how to get the guy back to the car, i would appreciate any help, thanks.