diff --git a/agent.cc b/agent.cc index dedd512..f82065c 100644 --- a/agent.cc +++ b/agent.cc @@ -4,6 +4,7 @@ #include "agent.h" #include "connection.h" +#include "main.h" #include "map.h" void @@ -36,5 +37,5 @@ agent::on_tick(void) tile->tile_in_dir(0, 1).symbol(), tile->tile_in_dir(-1, 0).symbol(), }; - conn.senses(around); + conn.senses(tick_id, around); } diff --git a/connection.cc b/connection.cc index 3a6f0a4..0a467c7 100644 --- a/connection.cc +++ b/connection.cc @@ -7,9 +7,9 @@ #include "connection.h" void -connection::senses(char around[4]) +connection::senses(int tick_id, char around[4]) { char buf[1024]; - snprintf(buf, sizeof(buf), "around %c%c%c%c\n\n", around[0], around[1], around[2], around[3]); + snprintf(buf, sizeof(buf), "tick %d\naround %c%c%c%c\n\n", tick_id, around[0], around[1], around[2], around[3]); write(fd, buf, strlen(buf)); } diff --git a/connection.h b/connection.h index 7d8f9e9..3067188 100644 --- a/connection.h +++ b/connection.h @@ -11,7 +11,7 @@ public: connection(int fd_) : fd(fd_) {} - void senses(char around[4]); + void senses(int tick_id, char around[4]); }; #endif diff --git a/main.cc b/main.cc index 7f5ae88..83f600a 100644 --- a/main.cc +++ b/main.cc @@ -10,8 +10,11 @@ #include "agent.h" #include "connection.h" +#include "main.h" #include "map.h" +int tick_id = 0; + int main(int argc, char *argv[]) { @@ -37,12 +40,14 @@ main(int argc, char *argv[]) class agent agent(0, agentpos, conn); while (true) { + std::cout << "tick " << tick_id << '\n'; map.print_map(); std::cout << '\n'; agent.on_tick(); usleep(1000000); + tick_id++; } /* TODO: destroy agent cleanly */ diff --git a/main.h b/main.h new file mode 100644 index 0000000..487982c --- /dev/null +++ b/main.h @@ -0,0 +1,6 @@ +#ifndef BRMLIFE__MAIN_H +#define BRMLIFE__MAIN_H + +extern int tick_id; + +#endif