diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-03-01 15:53:02 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-03-01 15:53:02 +0100 |
commit | fd56574a4d60e553c610615660198f0a84bcb7a1 (patch) | |
tree | bd9e1dd576fa4494187a5176099772f22aeb360c /world.h |
Initial
Diffstat (limited to 'world.h')
-rw-r--r-- | world.h | 94 |
1 files changed, 94 insertions, 0 deletions
@@ -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); |