aboutsummaryrefslogtreecommitdiff
path: root/world.h
diff options
context:
space:
mode:
Diffstat (limited to 'world.h')
-rw-r--r--world.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/world.h b/world.h
new file mode 100644
index 0000000..ccbdbcf
--- /dev/null
+++ b/world.h
@@ -0,0 +1,94 @@
+#pragma once
+
+#include <iostream>
+#include <string>
+#include <array>
+#include <vector>
+#include <cstdint>
+#include "params.h"
+
+using namespace std;
+
+
+struct Location{
+ int bank; // 0-based
+ int pos; // 0-based
+};
+
+
+enum class arg_t{
+ number,
+ var,
+ name,
+ constant,
+ undeflabel,
+};
+
+struct Argument{
+ arg_t type;
+ bool remote;
+ int num;
+ string name;
+
+ ~Argument();
+};
+
+struct Instruction{
+ ins_t op;
+ vector<Argument> args;
+
+ static Instruction make(ins_t op,vector<Argument> args);
+};
+
+using Script = vector<Instruction>;
+
+class Team;
+class World;
+
+class Robot{
+ Location ip={0,0};
+ int waited=0;
+ array<uint16_t,20> vars;
+ uint16_t active;
+
+ Instruction resolve(World &world);
+ int calcDuration(Instruction &ins);
+ void execute(Instruction &ins,World &world);
+
+public:
+ const Team *team;
+ vector<Script> banks;
+ int iset;
+ bool mobile;
+
+ int heading;
+
+ void load(int idx,const Script &scr);
+
+ void tick(World &world);
+};
+
+class Team{
+public:
+ string name;
+ vector<Script> banks;
+};
+
+class World{
+public:
+ Robot *board[SIZE][SIZE];
+
+ World();
+ ~World();
+
+ Robot& create(const Team *team,int iset,int nbanks,bool mobile);
+
+ void tick();
+ Robot* targetbot(const Robot *r);
+};
+
+
+ostream& operator<<(ostream &os,const Argument &arg);
+ostream& operator<<(ostream &os,const ins_t &type);
+ostream& operator<<(ostream &os,const Instruction &ins);
+ostream& operator<<(ostream &os,const Team &team);