1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "Character.hpp"
Character::Character(char nSymbol, int nColor, Location L)
{
symbol = nSymbol;
color = nColor;
l = L;
}
void Character::draw(WINDOW * w)
{
wattron(w,COLOR_PAIR(color));
mvwaddch(w,l.x,l.y,symbol);
}
void Character::action(vector <Character> men, vector <Location> impassable)
{
if(order == "wander")
wander(men, impassable);
else if(order == "move")
astar(men,impassable);
}
bool Character::check(Location L, vector <Character> men, vector <Location> impassable)
{
for(int i = 0; i < men.size(); i++)
if(L.x == men[i].getLocation().x && L.y == men[i].getLocation().y)
return false;
for(int i = 0; i < impassable.size(); i++)
if(L.x == impassable[i].x && L.y == impassable[i].y)
return false;
return true;
}
void Character::wander(vector <Character> men, vector <Location> impassable)
{
int r = rand()%15+1;
bool stay = false;
Location L;
if(r==1)
L = Location(l.x+1,l.y);
else if(r==2)
L = Location(l.x-1,l.y);
else if(r==3)
L = Location(l.x,l.y+1);
else if(r==4)
L = Location(l.x,l.y-1);
else if(r==5)
L = Location(l.x+1,l.x+1);
else if(r==6)
L = Location(l.x-1,l.y-1);
else if(r==7)
L = Location(l.x+1,l.y-1);
else if(r==8)
L = Location(l.x-1,l.y+1);
else
stay = true;
if (!stay)
if(check(L,men,impassable))
move(L);
}
void Character::astar(vector <Character> men, vector <Location> impassable)
{
vector <Location> closed;
vector <Location> open;
}
|