Connection: Add 'move' attribute to the negotiation phase

This commit is contained in:
Petr Baudis 2011-11-27 05:07:01 +01:00
parent 9cf99e0bcd
commit 2907cb6791
4 changed files with 25 additions and 1 deletions

10
README
View file

@ -46,3 +46,13 @@ The following outputs are supported:
attack_dir <x> <y>
<x> and <y> are integer offsets relative
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.

View file

@ -29,6 +29,9 @@ agent::move_dir(int dir_x, int dir_y)
if (dead || !tile)
return false;
if ((double) random() / (double) RAND_MAX > attr.move)
return false;
chenergy(world::move_cost);
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);

View file

@ -14,6 +14,10 @@ public:
class map &map;
class tile *tile;
struct {
double move;
} attr;
int energy;
bool dead;
@ -22,6 +26,7 @@ public:
{
energy = world::newborn_energy;
dead = false;
attr.move = 1.0;
};
void spawn(void);
void spawn_at(class tile &tile);

View file

@ -69,7 +69,13 @@ connection::actions(class agent &agent)
std::string cmd = line.substr(0, spofs);
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;
sscanf(line.c_str(), "%d %d", &x, &y);
if (x < -1) x = -1; if (x > 1) x = 1;