1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
start(Module):-start(Module, localhost).
start(Module, Host):-start(Module, Host, 8068).
start(Module, Host, Port):-
socket('AF_INET', Socket),
hostname_address(Host, HostAddress),
socket_connect(Socket, 'AF_INET'(HostAddress, Port),
StreamIn, StreamOut),
launch(Module, StreamIn, StreamOut),
close(StreamIn), close(StreamOut), socket_close(Socket).
launch(Module, StreamIn, StreamOut) :-
atom_concat('rules/', Module, Path), consult(Path),
do([], StreamIn, StreamOut, Module, [], []).
do(e, _, _, _, _, _) :- !.
do(Choice, StreamIn, StreamOut, Module, ModuleState, Hist) :-
call(Module, Hist, ModuleDecision, ModuleState, NewModuleState),
write(StreamOut, ModuleDecision), flush_output(StreamOut),
loop(StreamIn, StreamOut, Module, NewModuleState, [Choice|Hist]).
loop(StreamIn, StreamOut, Module, ModuleState, Hist) :-
read_atom(StreamIn, Choice), write(Choice),
do(Choice, StreamIn, StreamOut, Module, ModuleState, Hist).
|