Maintain and broadcast current tick id

This commit is contained in:
Petr Baudis 2011-11-26 23:31:28 +01:00
parent 3d485518b0
commit 1ed67c81b6
5 changed files with 16 additions and 4 deletions

View file

@ -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);
}

View file

@ -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));
}

View file

@ -11,7 +11,7 @@ public:
connection(int fd_) : fd(fd_) {}
void senses(char around[4]);
void senses(int tick_id, char around[4]);
};
#endif

View file

@ -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 */

6
main.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef BRMLIFE__MAIN_H
#define BRMLIFE__MAIN_H
extern int tick_id;
#endif