-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAI.pde
109 lines (105 loc) · 2.75 KB
/
AI.pde
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class AI{
AI(){}
boolean[] command( Entity me, boolean andou ){ return null; }
}
class Schizo extends AI{
Schizo(){}
boolean[] command( Entity me, boolean andou ){
boolean[] out = new boolean[4];
int I = round( random( -0.499, 28.499 ) );
if( I <= 3 ) out[I] = true;
return out;
}
}
class Returner extends AI{
ArrayList<Index> path;
int c;
Returner( float i, float j ){
path = A_Star( new Index(i,j), new Index(startingX[1], startingY[1]), bounds );
if( path != null ) c = path.size()-1;
else println( "null path" );
}
boolean[] command( Entity me, boolean andou ){
boolean[] out = new boolean[4];
Index pos = new Index( me.x, me.y );
for( int q = c; q > 0; --q ){
if( pos.equals( path.get(q) ) ){
out[0] = path.get(q-1).j < pos.j;
out[1] = path.get(q-1).j > pos.j;
out[2] = path.get(q-1).i < pos.i;
out[3] = path.get(q-1).i > pos.i;
c = q;
break;
}
}
return out;
}
}
class Seguidor extends AI{
ArrayList<Index> path;
int crazy;
boolean is_crazy;
Seguidor(){
path = new ArrayList();
}
boolean[] command( Entity me, boolean andou ){
boolean[] out = new boolean[4];
Index pos = new Index( me.x, me.y );
if( andou ){
if( millis() > crazy ){
if( random( 50 ) < 1 ){
int R = round(random( -0.499, encruzilhada.length-0.501 ) );
path = A_Star( pos, encruzilhada[R], bounds );
crazy = millis() + 3000;
is_crazy = true;
}
else path = A_Star( pos, new Index(floor(pacman.x), floor(pacman.y)), bounds );
}
else if( is_crazy ){
path = A_Star( pos, new Index(floor(pacman.x), floor(pacman.y)), bounds );
is_crazy = false;
}
}
if( path != null ){
if( path.size() > 0 ){
for( int q = path.size()-1; q > 0; --q ){
if( pos.equals( path.get(q) ) ){
out[0] = path.get(q-1).j < pos.j;
out[1] = path.get(q-1).j > pos.j;
out[2] = path.get(q-1).i < pos.i;
out[3] = path.get(q-1).i > pos.i;
break;
}
path.remove(q);
}
}
else{
path = A_Star( pos, new Index(floor(pacman.x), floor(pacman.y)), bounds );
is_crazy = false;
}
}
return out;
}
}
/*
class Seguidor_rudimentar extends AI{
float px, py;
Seguidor(){
}
boolean[] command( Entity me ){
boolean[] out = new boolean[4];
if(
if( abs(pacman.y - me.y) > 0.5 ){
if( pacman.y < me.y ) out[0] = true;
if( pacman.y > me.y ) out[1] = true;
}
if( abs(pacman.x - me.x) > 0.5 ){
if( pacman.x < me.x ) out[2] = true;
if( pacman.x > me.x ) out[3] = true;
}
px = me.x;
py = me.y;
return out;
}
}
*/