aboutsummaryrefslogtreecommitdiff
path: root/world.h
blob: ccbdbcf57341e10fbf2da58b3e08b9c5c17e5224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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);