aboutsummaryrefslogtreecommitdiff
path: root/src/knowledge-base.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/knowledge-base.c')
-rw-r--r--src/knowledge-base.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/knowledge-base.c b/src/knowledge-base.c
new file mode 100644
index 0000000..58a9d07
--- /dev/null
+++ b/src/knowledge-base.c
@@ -0,0 +1,64 @@
1#include "knowledge-base.h"
2#include <stdio.h>
3
4#define QUESTION(symbol, label, yes, no) \
5[QUESTION_##symbol] = label,
6char *question_labels[QUESTION_COUNT] = {
7 QUESTIONS
8};
9#undef QUESTION
10
11#define QUESTION(symbol, label, yes, no) \
12[QUESTION_##symbol] = { yes, no },
13struct question_branch_labels question_branch_labels[QUESTION_COUNT] = {
14 QUESTIONS
15};
16#undef QUESTION
17
18#define DECISION(symbol, label, ...) [DECISION_##symbol] = label,
19char *decision_labels[DECISION_COUNT] = {
20 DECISIONS
21};
22#undef DECISION
23
24#define DECISION(symbol, label, ...) [DECISION_##symbol] = { __VA_ARGS__ },
25struct decision_predicates decision_predicates[DECISION_COUNT] = {
26 DECISIONS
27};
28#undef DECISION
29
30#define QUESTION(symbol, label, yes, no) \
31 if (QUESTION_##symbol == question) \
32 return decision_predicates[decision].symbol;
33enum answer
34get_decision_predicate (enum decision decision, enum question question)
35{
36 QUESTIONS
37
38 return ANSWER_MALFORMED;
39}
40#undef QUESTION
41
42void
43print_knowledge_base (void)
44{
45 puts ("QUESTIONS:");
46 for (int i = 0; i < QUESTION_COUNT; ++i)
47 printf ("%2X", i + 1);
48 putchar ('\n');
49 for (int i = 0; i < QUESTION_COUNT; ++i) {
50 printf ("%0*b: %s\n", 2*QUESTION_COUNT,
51 (1 << ANSWER_COUNT) - 1 << (QUESTION_COUNT - 1 - i)*ANSWER_COUNT, question_labels[i]);
52 } putchar ('\n');
53
54 puts ("DECISIONS:");
55 for (int i = 0; i < QUESTION_COUNT; ++i)
56 printf ("%2X", i + 1);
57 putchar ('\n');
58 for (int i = 0; i < DECISION_COUNT; ++i) {
59 for (int j = 0; j < QUESTION_COUNT; ++j) {
60 printf ("%0*b", ANSWER_COUNT, get_decision_predicate (i, j));
61 }
62 printf (": %s\n", decision_labels[i]);
63 }
64}