diff options
author | Jan Klemkow <j.klemkow@wemelug.de> | 2012-11-11 09:52:20 +0100 |
---|---|---|
committer | Jan Klemkow <j.klemkow@wemelug.de> | 2012-11-11 09:52:20 +0100 |
commit | c71183f2277cf6465af9a989f36d24a3bb6c18cf (patch) | |
tree | 0702de1ad6aec3dcb3ccb46fdcff74f32a7191b5 | |
parent | cefe0246166fd68ae0877a37717d0b18b3551750 (diff) | |
parent | b3c30b9f59b25ed14abec0b1569b62787cc448ba (diff) | |
download | wbs-c71183f2277cf6465af9a989f36d24a3bb6c18cf.tar.gz wbs-c71183f2277cf6465af9a989f36d24a3bb6c18cf.tar.bz2 wbs-c71183f2277cf6465af9a989f36d24a3bb6c18cf.zip |
Merge branch 'master' of ssh://git.bnfr.net/git/wbs
-rw-r--r-- | pd_client_swipl.pl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pd_client_swipl.pl b/pd_client_swipl.pl new file mode 100644 index 0000000..1739be7 --- /dev/null +++ b/pd_client_swipl.pl @@ -0,0 +1,28 @@ +start(Module):-start(Module, localhost). +start(Module, Host):-start(Module, Host, 8068). + +start(Module, Host, Port):- + tcp_socket(Socket), + tcp_connect(Socket, Host:Port, StreamIn, StreamOut), + launch(Module, StreamIn, StreamOut), + tcp_close_socket(Socket). + +launch(Module, StreamIn, StreamOut) :- + atom_concat('rules/', Module, Path), consult(Path), + do(StreamIn, StreamOut, Module, [], []). + +do(_, _, _, _, [e|_]) :- !. +do(StreamIn, StreamOut, Module, ModuleState, Hist) :- + call(Module, Hist, ModuleDecision, ModuleState, NewModuleState), + write(StreamOut, ModuleDecision), flush_output(StreamOut), + format('Own choose:\t~w\n', [ModuleDecision]), + loop(StreamIn, StreamOut, Module, NewModuleState, Hist). + +loop(StreamIn, StreamOut, Module, ModuleState, Hist) :- + get_code(StreamIn, ChoiceCode), byte_to_atom(ChoiceCode, Choice), + format('Opponent chose:\t~w\n', [Choice]), + do(StreamIn, StreamOut, Module, ModuleState, [Choice|Hist]). + +% -1 = EOF +byte_to_atom(-1, e):-!. +byte_to_atom(Byte, Atom):-atom_codes(Atom, [Byte]). |