From 04f8b646c1c8a2435931bea9d1acffdde138f81e Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sat, 7 Nov 2026 08:06:01 +0300 Subject: publish --- src/knowledge-base.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/knowledge-base.c (limited to 'src/knowledge-base.c') 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 @@ +#include "knowledge-base.h" +#include + +#define QUESTION(symbol, label, yes, no) \ +[QUESTION_##symbol] = label, +char *question_labels[QUESTION_COUNT] = { + QUESTIONS +}; +#undef QUESTION + +#define QUESTION(symbol, label, yes, no) \ +[QUESTION_##symbol] = { yes, no }, +struct question_branch_labels question_branch_labels[QUESTION_COUNT] = { + QUESTIONS +}; +#undef QUESTION + +#define DECISION(symbol, label, ...) [DECISION_##symbol] = label, +char *decision_labels[DECISION_COUNT] = { + DECISIONS +}; +#undef DECISION + +#define DECISION(symbol, label, ...) [DECISION_##symbol] = { __VA_ARGS__ }, +struct decision_predicates decision_predicates[DECISION_COUNT] = { + DECISIONS +}; +#undef DECISION + +#define QUESTION(symbol, label, yes, no) \ + if (QUESTION_##symbol == question) \ + return decision_predicates[decision].symbol; +enum answer +get_decision_predicate (enum decision decision, enum question question) +{ + QUESTIONS + + return ANSWER_MALFORMED; +} +#undef QUESTION + +void +print_knowledge_base (void) +{ + puts ("QUESTIONS:"); + for (int i = 0; i < QUESTION_COUNT; ++i) + printf ("%2X", i + 1); + putchar ('\n'); + for (int i = 0; i < QUESTION_COUNT; ++i) { + printf ("%0*b: %s\n", 2*QUESTION_COUNT, + (1 << ANSWER_COUNT) - 1 << (QUESTION_COUNT - 1 - i)*ANSWER_COUNT, question_labels[i]); + } putchar ('\n'); + + puts ("DECISIONS:"); + for (int i = 0; i < QUESTION_COUNT; ++i) + printf ("%2X", i + 1); + putchar ('\n'); + for (int i = 0; i < DECISION_COUNT; ++i) { + for (int j = 0; j < QUESTION_COUNT; ++j) { + printf ("%0*b", ANSWER_COUNT, get_decision_predicate (i, j)); + } + printf (": %s\n", decision_labels[i]); + } +} -- cgit v1.3.1