diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-08 15:01:53 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-08 15:01:53 +0100 |
commit | 3656d3e8bfc7f074216191fbdc54d0c602a2d9ea (patch) | |
tree | 3c6ed807a8bf1f858b884991c00e5b35b6c9cf4c | |
parent | fa6e98d8ecf58d4ad4144636f58820d9102695c4 (diff) | |
download | wbs-3656d3e8bfc7f074216191fbdc54d0c602a2d9ea.tar.gz wbs-3656d3e8bfc7f074216191fbdc54d0c602a2d9ea.tar.bz2 wbs-3656d3e8bfc7f074216191fbdc54d0c602a2d9ea.zip |
Add prisoners dilemma prolog client
-rw-r--r-- | pd_client.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pd_client.pl b/pd_client.pl new file mode 100644 index 0000000..e0a83f3 --- /dev/null +++ b/pd_client.pl @@ -0,0 +1,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), + 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). |