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

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