diff --git a/README b/README index 0b170ad..5b9d986 100644 --- a/README +++ b/README @@ -18,9 +18,11 @@ Each line starts with a single word (command name), plus some command-specific parameters. Note that newlines are CRLF ("\r\n"), not just LF ("\n")! -The following inputs are supported: +The following inputs (in no particular order) are supported: tick + BUMP + if received, the agent's move failed DEAD if received, the agent is dead! energy diff --git a/connection.cc b/connection.cc index 124df8d..80dba79 100644 --- a/connection.cc +++ b/connection.cc @@ -21,6 +21,14 @@ connection::senses(int tick_id, bool dead, int energy, char around[4]) pthread_mutex_unlock(&buf_lock); } +void +connection::bump(void) +{ + pthread_mutex_lock(&buf_lock); + out_buf.append("BUMP\n"); + pthread_mutex_unlock(&buf_lock); +} + void connection::actions(class agent *agent) { @@ -45,7 +53,8 @@ connection::actions(class agent *agent) sscanf(line.c_str(), "%d %d", &x, &y); if (x < -1) x = -1; if (x > 1) x = 1; if (y < -1) y = -1; if (y > 1) y = 1; - agent->move_dir(x, y); + if (!agent->move_dir(x, y)) + bump(); } else { std::cout << "unknown line " << cmd << " " << line << " ...\n"; } diff --git a/connection.h b/connection.h index ff98597..518ce90 100644 --- a/connection.h +++ b/connection.h @@ -32,6 +32,8 @@ public: void cancel(void); private: + void bump(void); + std::string out_buf, in_buf; pthread_mutex_t buf_lock;