mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 10:23:38 +02:00
Send BUMP if move failed
This commit is contained in:
parent
de7a604e52
commit
77e555706b
3 changed files with 15 additions and 2 deletions
4
README
4
README
|
@ -18,9 +18,11 @@ Each line starts with a single word (command name), plus
|
||||||
some command-specific parameters. Note that newlines are
|
some command-specific parameters. Note that newlines are
|
||||||
CRLF ("\r\n"), not just LF ("\n")!
|
CRLF ("\r\n"), not just LF ("\n")!
|
||||||
|
|
||||||
The following inputs are supported:
|
The following inputs (in no particular order) are supported:
|
||||||
|
|
||||||
tick <ticknum>
|
tick <ticknum>
|
||||||
|
BUMP
|
||||||
|
if received, the agent's move failed
|
||||||
DEAD
|
DEAD
|
||||||
if received, the agent is dead!
|
if received, the agent is dead!
|
||||||
energy <points>
|
energy <points>
|
||||||
|
|
|
@ -21,6 +21,14 @@ connection::senses(int tick_id, bool dead, int energy, char around[4])
|
||||||
pthread_mutex_unlock(&buf_lock);
|
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
|
void
|
||||||
connection::actions(class agent *agent)
|
connection::actions(class agent *agent)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +53,8 @@ connection::actions(class agent *agent)
|
||||||
sscanf(line.c_str(), "%d %d", &x, &y);
|
sscanf(line.c_str(), "%d %d", &x, &y);
|
||||||
if (x < -1) x = -1; if (x > 1) x = 1;
|
if (x < -1) x = -1; if (x > 1) x = 1;
|
||||||
if (y < -1) y = -1; if (y > 1) y = 1;
|
if (y < -1) y = -1; if (y > 1) y = 1;
|
||||||
agent->move_dir(x, y);
|
if (!agent->move_dir(x, y))
|
||||||
|
bump();
|
||||||
} else {
|
} else {
|
||||||
std::cout << "unknown line " << cmd << " " << line << " ...\n";
|
std::cout << "unknown line " << cmd << " " << line << " ...\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
void cancel(void);
|
void cancel(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void bump(void);
|
||||||
|
|
||||||
std::string out_buf, in_buf;
|
std::string out_buf, in_buf;
|
||||||
pthread_mutex_t buf_lock;
|
pthread_mutex_t buf_lock;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue