mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +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
|
||||
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>
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
void cancel(void);
|
||||
|
||||
private:
|
||||
void bump(void);
|
||||
|
||||
std::string out_buf, in_buf;
|
||||
pthread_mutex_t buf_lock;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue