From 2907cb6791bba3392c2ddb4688b8c1cccc907d2f Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 27 Nov 2011 05:07:01 +0100 Subject: [PATCH] Connection: Add 'move' attribute to the negotiation phase --- README | 10 ++++++++++ agent.cc | 3 +++ agent.h | 5 +++++ connection.cc | 8 +++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README b/README index 314a6a6..d788e5d 100644 --- a/README +++ b/README @@ -46,3 +46,13 @@ The following outputs are supported: attack_dir and 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 + between 0 and 1, describing probability + of success of move command. Higher probability + means higher energy maintenance of move actuators. diff --git a/agent.cc b/agent.cc index e7446a6..cb06493 100644 --- a/agent.cc +++ b/agent.cc @@ -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); diff --git a/agent.h b/agent.h index 62d4b45..56a7b7e 100644 --- a/agent.h +++ b/agent.h @@ -14,6 +14,10 @@ public: class 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); diff --git a/connection.cc b/connection.cc index cd3da50..022eba7 100644 --- a/connection.cc +++ b/connection.cc @@ -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;