mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 18:33:39 +02:00
Connection: Add 'move' attribute to the negotiation phase
This commit is contained in:
parent
9cf99e0bcd
commit
2907cb6791
4 changed files with 25 additions and 1 deletions
10
README
10
README
|
@ -46,3 +46,13 @@ The following outputs are supported:
|
||||||
attack_dir <x> <y>
|
attack_dir <x> <y>
|
||||||
<x> and <y> are integer offsets relative
|
<x> and <y> are integer offsets relative
|
||||||
to the current position; may be just {-1,0,1}
|
to the current position; may be just {-1,0,1}
|
||||||
|
|
||||||
|
|
||||||
|
After connecting, the client specifies its desired attributes,
|
||||||
|
in the same format as in normal output (line-based, terminated
|
||||||
|
by empty line), but with these commands instead:
|
||||||
|
|
||||||
|
move <rate>
|
||||||
|
<rate> between 0 and 1, describing probability
|
||||||
|
of success of move command. Higher probability
|
||||||
|
means higher energy maintenance of move actuators.
|
||||||
|
|
3
agent.cc
3
agent.cc
|
@ -29,6 +29,9 @@ agent::move_dir(int dir_x, int dir_y)
|
||||||
if (dead || !tile)
|
if (dead || !tile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if ((double) random() / (double) RAND_MAX > attr.move)
|
||||||
|
return false;
|
||||||
|
|
||||||
chenergy(world::move_cost);
|
chenergy(world::move_cost);
|
||||||
|
|
||||||
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
||||||
|
|
5
agent.h
5
agent.h
|
@ -14,6 +14,10 @@ public:
|
||||||
class map ↦
|
class map ↦
|
||||||
class tile *tile;
|
class tile *tile;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
double move;
|
||||||
|
} attr;
|
||||||
|
|
||||||
int energy;
|
int energy;
|
||||||
bool dead;
|
bool dead;
|
||||||
|
|
||||||
|
@ -22,6 +26,7 @@ public:
|
||||||
{
|
{
|
||||||
energy = world::newborn_energy;
|
energy = world::newborn_energy;
|
||||||
dead = false;
|
dead = false;
|
||||||
|
attr.move = 1.0;
|
||||||
};
|
};
|
||||||
void spawn(void);
|
void spawn(void);
|
||||||
void spawn_at(class tile &tile);
|
void spawn_at(class tile &tile);
|
||||||
|
|
|
@ -69,7 +69,13 @@ connection::actions(class agent &agent)
|
||||||
std::string cmd = line.substr(0, spofs);
|
std::string cmd = line.substr(0, spofs);
|
||||||
line.erase(0, spofs + 1);
|
line.erase(0, spofs + 1);
|
||||||
|
|
||||||
if (!cmd.compare("move_dir")) {
|
if (negotiation && !cmd.compare("move")) {
|
||||||
|
double mprob = 1.0;
|
||||||
|
sscanf(line.c_str(), "%lf", &mprob);
|
||||||
|
if (mprob >= 0 && mprob <= 1)
|
||||||
|
agent.attr.move = mprob;
|
||||||
|
|
||||||
|
} else if (!negotiation && !cmd.compare("move_dir")) {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
sscanf(line.c_str(), "%d %d", &x, &y);
|
sscanf(line.c_str(), "%d %d", &x, &y);
|
||||||
if (x < -1) x = -1; if (x > 1) x = 1;
|
if (x < -1) x = -1; if (x > 1) x = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue