Your approach seems reasonable: from SWI-Prolog docs: "I / O blocking can be handled using the read_term / 3 timeout parameter.
This is not very informative: changing the timeout per user leads to some error (I will test more and will report to the SWI_prolog mailing list, if necessary) even under catch / 3.
It seems to work
..., current_input(I), wait_for_input([I], A, 30), ...
If the input is not specified (a shorter time to check here ...)
?- current_input(I), wait_for_input([I],A,5). I = <stream>(0x7fa75bb31880), A = [].
EDIT : variable A will contain a list containing a list of streams with ready-made input: I just reported the case when the user does not enter anything before the timeout expires. To get the actual input, use the attached code:
tql :- current_player(I), writef('Its %d. players turn: ', [I]), flush_output, current_input(Input), wait_for_input([Input], [Input], 5), read(Input, Move), writeln(Move). current_player(1).
NTN
source share