mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Maintain and broadcast current tick id
This commit is contained in:
parent
3d485518b0
commit
1ed67c81b6
5 changed files with 16 additions and 4 deletions
3
agent.cc
3
agent.cc
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "agent.h"
|
#include "agent.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
#include "main.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -36,5 +37,5 @@ agent::on_tick(void)
|
||||||
tile->tile_in_dir(0, 1).symbol(),
|
tile->tile_in_dir(0, 1).symbol(),
|
||||||
tile->tile_in_dir(-1, 0).symbol(),
|
tile->tile_in_dir(-1, 0).symbol(),
|
||||||
};
|
};
|
||||||
conn.senses(around);
|
conn.senses(tick_id, around);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
connection::senses(char around[4])
|
connection::senses(int tick_id, char around[4])
|
||||||
{
|
{
|
||||||
char buf[1024];
|
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));
|
write(fd, buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
|
|
||||||
connection(int fd_) : fd(fd_) {}
|
connection(int fd_) : fd(fd_) {}
|
||||||
|
|
||||||
void senses(char around[4]);
|
void senses(int tick_id, char around[4]);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
5
main.cc
5
main.cc
|
@ -10,8 +10,11 @@
|
||||||
|
|
||||||
#include "agent.h"
|
#include "agent.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
#include "main.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
int tick_id = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -37,12 +40,14 @@ main(int argc, char *argv[])
|
||||||
class agent agent(0, agentpos, conn);
|
class agent agent(0, agentpos, conn);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
std::cout << "tick " << tick_id << '\n';
|
||||||
map.print_map();
|
map.print_map();
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
|
|
||||||
agent.on_tick();
|
agent.on_tick();
|
||||||
|
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
|
tick_id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: destroy agent cleanly */
|
/* TODO: destroy agent cleanly */
|
||||||
|
|
6
main.h
Normal file
6
main.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef BRMLIFE__MAIN_H
|
||||||
|
#define BRMLIFE__MAIN_H
|
||||||
|
|
||||||
|
extern int tick_id;
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue