connnection::senses(): Sanitize interface, take just agent&

This commit is contained in:
Petr Baudis 2011-11-27 03:24:40 +01:00
parent 9dcb3c543a
commit 415475cd26
3 changed files with 21 additions and 14 deletions

View file

@ -83,17 +83,7 @@ agent::on_senses_update(void)
if (!conn)
return;
char around[8] = {
tile->tile_in_dir(0, -1).symbol(),
tile->tile_in_dir(1, -1).symbol(),
tile->tile_in_dir(1, 0).symbol(),
tile->tile_in_dir(1, 1).symbol(),
tile->tile_in_dir(0, 1).symbol(),
tile->tile_in_dir(-1, 1).symbol(),
tile->tile_in_dir(-1, 0).symbol(),
tile->tile_in_dir(-1, -1).symbol(),
};
conn->senses(tick_id, dead, energy, around);
conn->senses(tick_id, *this);
}
agent::~agent()

View file

@ -11,10 +11,27 @@
#include "connection.h"
void
connection::senses(int tick_id, bool dead, int energy, char around[4])
connection::senses(int tick_id, class agent &a)
{
char buf[1024];
snprintf(buf, sizeof(buf), "tick %d\r\n%senergy %d\r\naround %.8s\r\n\r\n", tick_id, dead ? "DEAD\r\n" : "", energy, around);
snprintf(buf, sizeof(buf),
"tick %d\r\n"
"%s"
"energy %d\r\n"
"around %c%c%c%c%c%c%c%c\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()
);
pthread_mutex_lock(&buf_lock);
out_buf.append(buf);

View file

@ -26,7 +26,7 @@ public:
close(fd);
}
void senses(int tick_id, bool dead, int energy, char around[8]);
void senses(int tick_id, class agent &);
void actions(class agent *);
void cancel(void);