Title more or less says it all. I got the following code in SWI-PROLOG:
get_card(1):-
nb_getval(playerOneHand, Hand),
write("Select which cards you want to play:"), nl,
read(Input),
handle_input(Input).
get_card(2):-
nb_getval(playerTwoHand, Hand),
write("Select which cards you want to play:"), nl,
read(Input),
handle_input(Input).
Expected input-format right now is something like [ 0, 1 ].
to play your first two cards, [ 0 ].
to only play your first card, so on and so forth. While I know this is beyond horrible as far as input formats go, the priority right now is to atleast get it working, then move on to a better UI from there.
This is what happens:
I'm very new to Prolog so bear with me, but this is how I'm looking at it: It seems to be "skipping" over our read
and is now expecting a new command to be entered instead (ENTER has been pressed in the above picture).
I feel like the solution should be very simple but unfortunately is nothing I can seem to wrap my head around. Thanks in advance!
EDIT: Example code that can be ran to reproduce the issue, unless it's only happening on my system for some reason:
% Initialize globals
?- nb_setval(playerOneHand, []).
?- nb_setval(playerTwoHand, []).
handle_input(Input, Hand):-
write("Input is "), write(Input), nl,
write("Hand is "), write(Hand), nl.
get_card(1):-
nb_getval(playerOneHand, Hand),
write("Select which cards you want to play: "), nl,
read(Input),
handle_input(Input, Hand).
get_card(2):-
nb_getval(playerTwoHand, Hand),
write("Select which cards you want to play: "), nl,
read(Input),
handle_input(Input, Hand).
?- write("Player 1: "), get_card(1), nl,
write("Player 2: "), get_card(2), nl.
Using SWI-Prolog and the given code in a test.pl
file, it is simply consulted via the terminal interface (File -> Consult -> test.pl
). Trying to give SWI-Prolog ANY kind of input then results in the issue at hand.
[
), so right now the issue is something else I feel like. – Xariezswipl.exe
is broken and cannot do proper input and output, andswipl-win.exe
works: stackoverflow.com/questions/23133168/… . Also, please make your description really clear, e.g. "I put the following code into filefoo.pl
", "I loadfoo.pl
into SWI-Prolog as follows", etc. – Isabelle Newbie