mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +02:00
Create an agent
This commit is contained in:
parent
a131964cc0
commit
32dc354e60
4 changed files with 29 additions and 2 deletions
4
Makefile
4
Makefile
|
@ -1,8 +1,8 @@
|
||||||
CFLAGS=-Wall -O3 -g
|
CFLAGS=-Wall -O3 -g
|
||||||
|
|
||||||
OBJS=main.o map.o
|
OBJS=main.o map.o agent.o
|
||||||
|
|
||||||
brmlife: main.o map.o
|
brmlife: main.o map.o agent.o
|
||||||
$(CXX) -o $@ $^
|
$(CXX) -o $@ $^
|
||||||
|
|
||||||
|
|
||||||
|
|
16
agent.cc
Normal file
16
agent.cc
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "agent.h"
|
||||||
|
#include "map.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
agent::put_at(struct position *pos)
|
||||||
|
{
|
||||||
|
class tile *t = &pos->map->tile_at(*pos);
|
||||||
|
if (!t->on_agent_enter(this)) {
|
||||||
|
std::cerr << "Collision.";
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
7
agent.h
7
agent.h
|
@ -7,6 +7,13 @@ class agent {
|
||||||
public:
|
public:
|
||||||
int id;
|
int id;
|
||||||
class position *pos;
|
class position *pos;
|
||||||
|
|
||||||
|
agent(int id_, class position &pos_) : id (id_), pos (&pos_)
|
||||||
|
{
|
||||||
|
put_at(pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
void put_at(struct position *pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
4
main.cc
4
main.cc
|
@ -7,6 +7,10 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
class map map(10, 10);
|
class map map(10, 10);
|
||||||
|
|
||||||
|
class position agentpos(4, 4, map);
|
||||||
|
class agent agent(0, agentpos);
|
||||||
|
|
||||||
map.print_map();
|
map.print_map();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue