Send BUMP if move failed

This commit is contained in:
Petr Baudis 2011-11-27 02:59:28 +01:00
parent de7a604e52
commit 77e555706b
3 changed files with 15 additions and 2 deletions

4
README
View file

@ -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 <ticknum>
BUMP
if received, the agent's move failed
DEAD
if received, the agent is dead!
energy <points>

View file

@ -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";
}

View file

@ -32,6 +32,8 @@ public:
void cancel(void);
private:
void bump(void);
std::string out_buf, in_buf;
pthread_mutex_t buf_lock;