I am currently learning to program in Prolog, and am working on an assignment which involves a world of size n and has 3 blocks that are picked up and moved based on where the user wants to move it. I have a basic bare bone structure of the program, however, the issue I am having is getting the user's input, storing the integer of the world size and using variable throughout the program. I managed to get the user input, but when I use it elsewhere in the code, the value is not what it should be.
For example. If I enter 14 for n, and then in the position clause I output the size, I get World Size: _6324 instead of 14. This seems to be causing other issues in my code, and I cannot figure out how to solve this issue. What am I doing wrong, and how would I solve this? Also, what does _6324 mean?
Here is the initial code which asks for the user input and outputs the current set of data, including the world size:
%Setting world: world of lenght n, block size of 3
:-assert(at(a,0)).
:-assert(at(b,2)).
:-assert(at(c,5)).
%Gets the initial size of the world from the user
start :- write('What the world length?: '), read(Length),
assert(world_length(Length)), nl, position.
%outputs the initial positions of each block
position:- write("Initial Positions: "),nl,
write('World Size: '), write(Length),nl,
at(a,X), write(a), write(' is at position '), write(X),nl,
at(b,Y), write(b), write(' is at position '), write(Y),nl,
at(c,Z), write(c), write(' is at position '), write(Z),nl,nl,
write('Instructions: To move a block, simply type in move(block, position).'), nl.