Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blocks World in prolog

Status
Not open for further replies.

steven890

Programmer
Nov 20, 2008
7
GR
I try to solve the blocks world prolbem in prolog but i a, facing some difficulties ani I need your help.
Firstly I do not know how to print the current situation of the blocks for example
b
a c d
=====
and secondly how can i change the programm in order the user to be able to give the initial state.
Thanks in advance
 
b
a c d
=====
How do you managed this situation in your code ?

It's the same for the second question.
 
i use on(b,a) which means b is above a.
and on(c,table) which means c is on table.
I follow the same for the other blocks.
 
OK.
You can build a list of boxes piled [[b, a, table], [c, table], [d, table]], you get the lenght of the highest one, and then you can print the situation.
 
and how can i make it in order the initial situation to be given from the user?
 
If I have understood your request (!?) I think this is technical so I give you my solution in SWI-Prolog :
Code:
:- dynamic (on/2).

get_car(In, Out) :-
	atom_codes(Out, [In]).


set(B) :-
	format('On which object is the block ~w ? ', [B]),
	read(X),
	assert(on(B, X)).

test :-
	write('How many blocks ? '), read(X),
	Max is 96 + X,
	numlist(97, Max, L),
	maplist(get_car, L, L1),
	maplist(set, L1).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top