summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BSDmakefile7
-rw-r--r--battle.c37
-rw-r--r--pay.pl4
3 files changed, 46 insertions, 2 deletions
diff --git a/BSDmakefile b/BSDmakefile
index 0d6e469..650d0cf 100644
--- a/BSDmakefile
+++ b/BSDmakefile
@@ -4,10 +4,13 @@ tit4tat: tit4tat.c
gcc -std=c99 -Wall -o $@ $<
pd_server: pd_server.c
- gcc -o $@ $<
+ gcc -o $@ $>
prisoners_dilemma: prisoners_dilemma.pl
gplc -o $@ $>
+battle: battle.c pay.pl
+ gplc $>
+
clean:
- rm -f tit4tat prisoners_dilemma
+ rm -f tit4tat prisoners_dilemma battle
diff --git a/battle.c b/battle.c
new file mode 100644
index 0000000..4ee01df
--- /dev/null
+++ b/battle.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <string.h>
+
+#define __GPROLOG_FOREIGN_STRICT__
+#include "gprolog.h"
+
+int pay(char a, char b)
+{
+ int payment = -1;
+ PlTerm arg[3];
+
+ int func = Pl_Find_Atom("pay");
+
+ Pl_Query_Begin(PL_TRUE);
+
+ arg[0] = Pl_Mk_Char(a);
+ arg[1] = Pl_Mk_Char(b);
+ arg[2] = Pl_Mk_Variable();
+
+ if (Pl_Query_Call(func, 3, arg)) {
+ payment = Pl_Rd_Integer(arg[2]);
+ }
+ Pl_Query_End(PL_RECOVER);
+
+ return payment;
+}
+
+int
+main(int argc, char *argv[])
+{
+ Pl_Start_Prolog(argc, argv);
+
+ printf("pay: %d\n", pay('d', 'c'));
+
+ Pl_Stop_Prolog();
+ return 0;
+}
diff --git a/pay.pl b/pay.pl
new file mode 100644
index 0000000..bd263d9
--- /dev/null
+++ b/pay.pl
@@ -0,0 +1,4 @@
+pay(c,d,1).
+pay(d,d,2).
+pay(c,c,3).
+pay(d,c,4).