Created
March 24, 2020 19:35
-
-
Save Sohaib03/b194f1606f1d21ff760daa0dcd286dda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <map> | |
using namespace std; | |
template<typename T> | |
void debug(T args) { | |
cerr << args << endl; | |
} | |
int width, height; | |
const int NONE = -1; | |
const int ROBOT_ALLY = 0; | |
const int ROBOT_ENEMY = 1; | |
const int HOLE = 1; | |
const int RADAR = 2; | |
const int TRAP = 3; | |
const int AMADEUSIUM = 4; | |
class Pos { | |
public: | |
int x, y; | |
Pos(int a, int b) { | |
this->x = a; | |
this->y = b; | |
} | |
int distance(Pos other) { | |
return abs(x - other.x) + abs(y - other.y); | |
} | |
}; | |
class Entity:public Pos { | |
public: | |
int type, id; | |
Entity(int x,int y,int type,int id) : Pos(x, y) | |
{ | |
this->type = type; | |
this->id = id; | |
} | |
}; | |
class Robot:public Entity { | |
public: | |
string command; | |
int item; | |
Robot () : Entity(0,0,0,0){} | |
Robot(int x, int y, int type, int id, int item) : Entity (x, y, type, id) { | |
this->item = item; | |
} | |
bool is_dead() { | |
return x==-1 and y==-1; | |
} | |
void move(int x, int y, string message = "") { | |
command = "MOVE " + to_string(x) + " " + to_string(y) + " " + message; | |
} | |
void wait(string message = "") { | |
command = "WAIT " + message; | |
} | |
void dig(int x, int y, string message = "") { | |
command = "DIG " + to_string(x) + " " + to_string(y) + " " + message; | |
} | |
void request(string item, string message = "") { | |
command = "REQUEST " + item + " " + message; | |
} | |
pair<int, int> get_pos() { | |
return {x, y}; | |
} | |
void update(int x, int y, int item, int type) { | |
this->x = x; | |
this->y = y; | |
this->item = item; | |
this->type = type; | |
} | |
void execute() { | |
if (command.empty()) cout << "WAIT (by default)" << endl; | |
else cout << command << endl; | |
} | |
}; | |
class Cell: public Pos { | |
public: | |
int amadeusium, hole; | |
Cell() : Pos(-1, -1) | |
{ | |
this->amadeusium = 0; | |
this->hole = 0; | |
} | |
Cell(int x, int y, int amadeusium, int hole) : Pos(x,y) | |
{ | |
this->amadeusium = amadeusium; | |
this->hole = hole; | |
} | |
bool has_hole() { | |
return this->hole == HOLE; | |
} | |
void update(int amadeusium, int hole) { | |
this->amadeusium = amadeusium; | |
this->hole = hole; | |
} | |
}; | |
class Grid { | |
public: | |
Cell *cells; | |
Grid() { | |
cells = new Cell[height * width]; | |
for (int j=0; j<height; j++) | |
for (int i=0; i<width; i++) | |
cells[i + width*j] = Cell(i, j, 0, 0); | |
} | |
Cell get_cell(int x, int y) { | |
if (width > x and x>=0 and height > y and y>=0) | |
return cells[x+y*width]; | |
else | |
return Cell(-1, -1, -1, -1); | |
} | |
~Grid() { | |
delete[] cells; | |
} | |
}; | |
class Game { | |
public: | |
Grid grid; | |
int my_score; | |
int enemy_score; | |
int radar_cooldown; | |
int trap_cooldown; | |
vector <Entity> radars; | |
vector <Entity> traps; | |
map<int, Robot> my_robots; | |
map<int, Robot> enemy_robots; | |
Game() : | |
my_score(0), enemy_score(0), radar_cooldown(0), trap_cooldown(0) {} | |
void reset() { | |
radars.clear(); | |
traps.clear(); | |
} | |
}; | |
int main() { | |
cin >> width >> height; cin.ignore(); | |
Game game; | |
while (1) | |
{ | |
cin >> game.my_score >> game.enemy_score; cin.ignore(); | |
for (int i=0; i<height; i++) { | |
for (int j=0; j<width; j++) { | |
char ore; int ore_count; | |
int hole; | |
cin >> ore >> hole; cin.ignore(); | |
if (ore == '?') ore_count = -1; | |
else ore_count = ore - '0'; | |
} | |
} | |
int entity_count; | |
int radar_cooldown; | |
int trap_cooldown; | |
cin >> entity_count >> radar_cooldown >> trap_cooldown; cin.ignore(); | |
game.reset(); | |
for (int i = 0; i < entity_count; i++) { | |
int id, type, x, y, item; | |
cin >> id >> type >> x >> y >> item; cin.ignore(); | |
if (type == ROBOT_ALLY) game.my_robots[id].update(x, y, item, type); | |
else if (type == ROBOT_ENEMY) game.enemy_robots[id].update(x, y, item, type); | |
else if (type == TRAP) game.traps.push_back(Entity(x, y, type, id)); | |
else if (type == RADAR) game.radars.push_back(Entity(x,y, type, id)); | |
} | |
for (int i = 0; i < 5; i++) { | |
game.my_robots[i].execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment