#include #include #include "world.h" using namespace std; Argument::~Argument(){} Instruction Instruction::make(ins_t op,vector args){ return {op,args}; } void Robot::load(int idx,const Script &scr){ banks[idx]=scr; } void Robot::tick(World &world){ waited++; Instruction ins=resolve(world); int dur=calcDuration(ins); if(duractive; else arg.num=0; } break; case arg_t::constant: assert(false); default: assert(false); } } return ins; } int Robot::calcDuration(Instruction &ins){ int d=0; for(const Argument &arg : ins.args){ if(arg.remote)d+=C::pen_remote; } int base=C::baseDuration[(int)ins.op]; switch(ins.op){ case ins_t::set: d+=base; case ins_t::add: d+=base; case ins_t::sub: d+=base; case ins_t::comp: d+=base; case ins_t::trans: d+=base+C::pen_transinstr*banks.at(ins.args[0].num).size(); case ins_t::jump: d+=base; case ins_t::bjump: d+=base; case ins_t::die: d+=base; case ins_t::move: d+=base; case ins_t::turn: d+=base; case ins_t::scan: d+=base; case ins_t::create: d+=(base+C::pen_createbank*ins.args[1].num)*C::pen_createmobilemult+C::pen_createmobile*ins.args[2].num+C::pen_createiset1*(ins.args[0].num==1)+C::pen_createiset2*(ins.args[0].num==2); default: assert(false); } return d; } World::World(){ memset(&board[0][0],0,SIZE*SIZE*sizeof(Robot*)); } World::~World(){ for(int y=0;yteam=team; board[y][x]->banks.resize(nbanks); board[y][x]->iset=iset; board[y][x]->mobile=mobile; board[y][x]->heading=rand()%4; return *board[y][x]; } void World::tick(){ for(int y=0;ytick(*this); } } } Robot* World::targetbot(const Robot *r){ for(int y=0;yheading){ case 0: return board[y][(x+1)%SIZE]; case 1: return board[(y+SIZE-1)%SIZE][x]; case 2: return board[y][(x+SIZE-1)%SIZE]; case 3: return board[(y+1)%SIZE][x]; } } } } assert(false); } ostream& operator<<(ostream &os,const Argument &arg){ if(arg.remote){ switch(arg.type){ case arg_t::number: return os<