mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
agent::move_dir(): Implement
This commit is contained in:
parent
56726a6c05
commit
b305a41cfc
3 changed files with 24 additions and 0 deletions
12
agent.cc
12
agent.cc
|
@ -13,3 +13,15 @@ agent::put_at(class tile &t)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
agent::move_dir(int dir_x, int dir_y)
|
||||||
|
{
|
||||||
|
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
|
||||||
|
if (!t2->on_agent_enter(*this))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tile->on_agent_leave(*this);
|
||||||
|
tile = t2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
2
agent.h
2
agent.h
|
@ -13,6 +13,8 @@ public:
|
||||||
put_at(tile_);
|
put_at(tile_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool move_dir(int dir_x, int dir_y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Just for initial placement. */
|
/* Just for initial placement. */
|
||||||
void put_at(class tile &tile);
|
void put_at(class tile &tile);
|
||||||
|
|
10
main.cc
10
main.cc
|
@ -12,5 +12,15 @@ main(int argc, char *argv[])
|
||||||
class agent agent(0, agentpos);
|
class agent agent(0, agentpos);
|
||||||
|
|
||||||
map.print_map();
|
map.print_map();
|
||||||
|
std::cout << '\n';
|
||||||
|
|
||||||
|
agent.move_dir(1, 0);
|
||||||
|
map.print_map();
|
||||||
|
std::cout << '\n';
|
||||||
|
|
||||||
|
agent.move_dir(0, -1);
|
||||||
|
map.print_map();
|
||||||
|
std::cout << '\n';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue