mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +02:00
Sense around: Extended format describing agents explicitly
This commit is contained in:
parent
e22c57c97f
commit
f0a603352f
4 changed files with 31 additions and 11 deletions
9
README
9
README
|
@ -28,9 +28,14 @@ The following inputs (in no particular order) are supported:
|
|||
energy <points>
|
||||
number of agent's energy points; disregard
|
||||
in case of dead agents
|
||||
around <chars>
|
||||
<chars> describe tiles, clockwise from top,
|
||||
around <desc> <desc>...
|
||||
<desc> describe tiles, clockwise from top,
|
||||
in the immediate vicinity of the agent
|
||||
<desc> format is two-character, <type><agent>
|
||||
<type>: . for ground
|
||||
<agent>: - no agent
|
||||
a dead agent
|
||||
A alive agent
|
||||
|
||||
The following outputs are supported:
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
11
map.cc
11
map.cc
|
@ -1,5 +1,6 @@
|
|||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
4
map.h
4
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue