mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Track agent energy
Base energy, move energy
This commit is contained in:
parent
4fe552a79e
commit
93882f79b9
5 changed files with 22 additions and 6 deletions
4
agent.cc
4
agent.cc
|
@ -19,6 +19,8 @@ agent::put_at(class tile &t)
|
|||
bool
|
||||
agent::move_dir(int dir_x, int dir_y)
|
||||
{
|
||||
energy -= world::move_cost;
|
||||
|
||||
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
||||
if (!t2->on_agent_enter(*this))
|
||||
return false;
|
||||
|
@ -54,7 +56,7 @@ agent::on_senses_update(void)
|
|||
tile->tile_in_dir(0, 1).symbol(),
|
||||
tile->tile_in_dir(-1, 0).symbol(),
|
||||
};
|
||||
conn->senses(tick_id, around);
|
||||
conn->senses(tick_id, energy, around);
|
||||
}
|
||||
|
||||
agent::~agent()
|
||||
|
|
9
agent.h
9
agent.h
|
@ -2,19 +2,24 @@
|
|||
#define BRMLIFE__AGENT_H
|
||||
|
||||
#include "map.h"
|
||||
#include "world.h"
|
||||
|
||||
class connection;
|
||||
|
||||
class agent {
|
||||
public:
|
||||
int id;
|
||||
class tile *tile;
|
||||
class connection *conn;
|
||||
|
||||
class tile *tile;
|
||||
|
||||
int energy;
|
||||
|
||||
agent(int id_, class tile &tile_, class connection *conn_)
|
||||
: id (id_), tile (&tile_), conn (conn_)
|
||||
: id (id_), conn (conn_), tile (&tile_)
|
||||
{
|
||||
put_at(tile_);
|
||||
energy = world::newborn_energy;
|
||||
};
|
||||
|
||||
bool move_dir(int dir_x, int dir_y);
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
#include "connection.h"
|
||||
|
||||
void
|
||||
connection::senses(int tick_id, char around[4])
|
||||
connection::senses(int tick_id, int energy, char around[4])
|
||||
{
|
||||
char buf[1024];
|
||||
snprintf(buf, sizeof(buf), "tick %d\naround %c%c%c%c\n\n", tick_id, around[0], around[1], around[2], around[3]);
|
||||
snprintf(buf, sizeof(buf), "tick %d\nenergy %d\naround %c%c%c%c\n\n", tick_id, energy, around[0], around[1], around[2], around[3]);
|
||||
|
||||
pthread_mutex_lock(&buf_lock);
|
||||
out_buf.append(buf);
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
close(fd);
|
||||
}
|
||||
|
||||
void senses(int tick_id, char around[4]);
|
||||
void senses(int tick_id, int energy, char around[4]);
|
||||
void actions(class agent *);
|
||||
|
||||
void cancel(void);
|
||||
|
|
9
world.h
Normal file
9
world.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef BRMLIFE__WORLD_H
|
||||
#define BRMLIFE__WORLD_H
|
||||
|
||||
struct world {
|
||||
const static int newborn_energy = 500;
|
||||
const static int move_cost = 10;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue