diff --git a/README b/README index 5b9d986..17d80a1 100644 --- a/README +++ b/README @@ -28,9 +28,14 @@ The following inputs (in no particular order) are supported: energy number of agent's energy points; disregard in case of dead agents - around - describe tiles, clockwise from top, + around ... + describe tiles, clockwise from top, in the immediate vicinity of the agent + format is two-character, + : . for ground + : - no agent + a dead agent + A alive agent The following outputs are supported: diff --git a/connection.cc b/connection.cc index 6a5176a..c266e16 100644 --- a/connection.cc +++ b/connection.cc @@ -18,19 +18,19 @@ connection::senses(int tick_id, class agent &a) "tick %d\r\n" "%s" "energy %d\r\n" - "around %c%c%c%c%c%c%c%c\r\n" + "around %s %s %s %s %s %s %s %s\r\n" "\r\n", tick_id, a.dead ? "DEAD\r\n" : "", a.energy, - a.tile->tile_in_dir(0, -1).symbol(), - a.tile->tile_in_dir(1, -1).symbol(), - a.tile->tile_in_dir(1, 0).symbol(), - a.tile->tile_in_dir(1, 1).symbol(), - a.tile->tile_in_dir(0, 1).symbol(), - a.tile->tile_in_dir(-1, 1).symbol(), - a.tile->tile_in_dir(-1, 0).symbol(), - a.tile->tile_in_dir(-1, -1).symbol() + a.tile->tile_in_dir(0, -1).str(), + a.tile->tile_in_dir(1, -1).str(), + a.tile->tile_in_dir(1, 0).str(), + a.tile->tile_in_dir(1, 1).str(), + a.tile->tile_in_dir(0, 1).str(), + a.tile->tile_in_dir(-1, 1).str(), + a.tile->tile_in_dir(-1, 0).str(), + a.tile->tile_in_dir(-1, -1).str() ); pthread_mutex_lock(&buf_lock); diff --git a/map.cc b/map.cc index 631551b..2444ec6 100644 --- a/map.cc +++ b/map.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include "agent.h" @@ -39,6 +40,16 @@ tile_ground::type_symbol(void) return '.'; } +char * +tile::str(void) +{ + snprintf(str_buf, sizeof(str_buf), + "%c%c", + type_symbol(), + agent ? (!agent->dead ? 'A' : 'a') : '-'); + return str_buf; +} + class tile & tile::tile_in_dir(int dir_x, int dir_y) { diff --git a/map.h b/map.h index 286e65b..e80e27a 100644 --- a/map.h +++ b/map.h @@ -16,6 +16,7 @@ public: char symbol(void); virtual char type_symbol(void) = 0; + char *str(void); class tile &tile_in_dir(int dir_x, int dir_y); @@ -23,6 +24,9 @@ public: virtual void on_agent_leave(class agent &); virtual void on_tick(void); + +private: + char str_buf[3]; }; class tile_ground : public tile {