summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2023-05-20 17:20:46 -0400
committerBenji Dial <benji@benjidial.net>2023-05-20 17:20:46 -0400
commit338549f9cd49fa0f3001826c6605663fa6dd019b (patch)
tree63ce1efb3c1cfc3ee3480de77832869cbb2691c1 /include
downloadlib94-338549f9cd49fa0f3001826c6605663fa6dd019b.tar.gz
first commit
Diffstat (limited to 'include')
-rw-r--r--include/lib94/lib94.hpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/include/lib94/lib94.hpp b/include/lib94/lib94.hpp
new file mode 100644
index 0000000..1d061ec
--- /dev/null
+++ b/include/lib94/lib94.hpp
@@ -0,0 +1,88 @@
+#ifndef LIB94_HPP
+#define LIB94_HPP
+
+#include <filesystem>
+#include <optional>
+#include <variant>
+#include <string>
+#include <random>
+#include <vector>
+#include <queue>
+#include <set>
+
+#ifndef CORE_SIZE
+#define CORE_SIZE 8000
+#endif
+
+typedef uint32_t number_t;
+
+enum opcode : uint8_t {
+ DAT, MOV, ADD, SUB,
+ MUL, DIV, MOD, JMP,
+ JMZ, JMN, DJN, SEQ,
+ SNE, SLT, SPL, NOP
+};
+
+enum modifier : uint8_t {
+ A, B, AB, BA,
+ F, X, I
+};
+
+enum mode : uint8_t {
+ IMMEDIATE, DIRECT,
+ A_INDIRECT, B_INDIRECT,
+ A_DECREMENT, B_DECREMENT,
+ A_INCREMENT, B_INCREMENT
+};
+
+struct instruction {
+ opcode op;
+ modifier mod;
+ mode amode;
+ mode bmode;
+ number_t anumber;
+ number_t bnumber;
+};
+
+struct warrior {
+ std::string name;
+ std::string author;
+
+ number_t org;
+
+ std::vector<instruction> instructions;
+};
+
+void seed_prng(uint_fast64_t seed);
+
+std::variant<warrior *, std::string> compile_warrior(std::string source);
+bool save_warrior(const warrior &w, const std::filesystem::path &to);
+std::optional<warrior *> load_warrior(const std::filesystem::path &from);
+
+void clear_core(const instruction &background);
+void clear_core_random();
+
+//warrior pointers need to remain valid for other
+//functions to return valid things during the round
+bool init_round(const std::vector<const warrior *> &warriors);
+
+size_t alive_warrior_count();
+
+//asserts that there is a next warrior
+const warrior *get_next_warrior();
+const std::queue<number_t> &get_processes(const warrior *for_warrior);
+//asserts that there is a next process
+number_t get_next_process(const warrior *for_warrior);
+
+const std::set<number_t> &get_modified_addresses();
+void clear_modified_addresses();
+
+const instruction &get_instruction(number_t address);
+
+//asserts that there is a next warrior
+void single_step();
+
+const warrior *run_until_warrior_death();
+const warrior *run_until_winner();
+
+#endif