equal
deleted
inserted
replaced
1 unit uAIAmmoTests; |
1 unit uAIAmmoTests; |
2 interface |
2 interface |
3 uses SDLh; |
3 uses SDLh, uGears, uConsts; |
4 |
4 |
5 function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
5 function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
|
6 function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
|
7 |
|
8 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
|
9 const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
|
10 ( |
|
11 {amGrenade} TestGrenade, |
|
12 {amBazooka} TestBazooka, |
|
13 {amUFO} nil, |
|
14 {amShotgun} nil, |
|
15 {amPickHammer} nil, |
|
16 {amSkip} nil, |
|
17 {amRope} nil, |
|
18 {amMine} nil, |
|
19 {amDEagle} nil, |
|
20 {amDynamite} nil |
|
21 ); |
6 |
22 |
7 implementation |
23 implementation |
8 uses uMisc, uAIMisc; |
24 uses uMisc, uAIMisc; |
9 const cMyHHDamageScore = -3000; |
|
10 |
25 |
11 function Metric(x1, y1, x2, y2: integer): integer; |
26 function Metric(x1, y1, x2, y2: integer): integer; |
12 begin |
27 begin |
13 Result:= abs(x1 - x2) + abs(y1 - y2) |
28 Result:= abs(x1 - x2) + abs(y1 - y2) |
14 end; |
29 end; |
15 |
30 |
16 function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
31 function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
17 var Vx, Vy, r: real; |
32 var Vx, Vy, r: real; |
18 rTime: real; |
33 rTime: real; |
19 Score: integer; |
34 Score: integer; |
20 |
35 |
21 function CheckTrace: integer; |
36 function CheckTrace: integer; |
32 y:= y + dY; |
47 y:= y + dY; |
33 dX:= dX + cWindSpeed; |
48 dX:= dX + cWindSpeed; |
34 dY:= dY + cGravity; |
49 dY:= dY + cGravity; |
35 dec(t) |
50 dec(t) |
36 until TestColl(round(x), round(y), 5) or (t <= 0); |
51 until TestColl(round(x), round(y), 5) or (t <= 0); |
37 if NoMyHHNear(round(x), round(y), 110) then |
52 Result:= RateExplosion(Me, round(x), round(y), 101) - Metric(Targ.X, Targ.Y, round(x), round(y)) div 16 |
38 Result:= - Metric(round(x), round(y), Targ.x, Targ.y) div 16 |
|
39 else Result:= cMyHHDamageScore; |
|
40 end; |
53 end; |
41 |
54 |
42 begin |
55 begin |
43 Time:= 0; |
56 Time:= 0; |
44 rTime:= 10; |
57 rTime:= 10; |
45 Result:= Low(integer); |
58 Result:= Low(integer); |
46 repeat |
59 repeat |
47 rTime:= rTime + 70 + random*200; |
60 rTime:= rTime + 100 + random*250; |
48 Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; |
61 Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; |
49 Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; |
62 Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; |
50 r:= sqr(Vx) + sqr(Vy); |
63 r:= sqr(Vx) + sqr(Vy); |
51 if r <= 1 then |
64 if r <= 1 then |
52 begin |
65 begin |
60 end; |
73 end; |
61 end |
74 end |
62 until (rTime >= 5000) |
75 until (rTime >= 5000) |
63 end; |
76 end; |
64 |
77 |
|
78 function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
|
79 const tDelta = 10; |
|
80 var Vx, Vy, r: real; |
|
81 Score: integer; |
|
82 TestTime: Longword; |
|
83 |
|
84 function CheckTrace: integer; |
|
85 var x, y, dY: real; |
|
86 t: integer; |
|
87 begin |
|
88 x:= Me.X; |
|
89 y:= Me.Y; |
|
90 dY:= -Vy; |
|
91 t:= TestTime; |
|
92 repeat |
|
93 x:= x + Vx; |
|
94 y:= y + dY; |
|
95 dY:= dY + cGravity; |
|
96 dec(t) |
|
97 until TestColl(round(x), round(y), 5) or (t = 0); |
|
98 if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101) |
|
99 else Result:= Low(integer) |
|
100 end; |
|
101 |
|
102 begin |
|
103 Result:= Low(integer); |
|
104 TestTime:= 0; |
|
105 repeat |
|
106 inc(TestTime, 1000); |
|
107 Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
|
108 Vy:= cGravity*((TestTime + tDelta) div 2) - (Targ.Y - Me.Y) / (TestTime + tDelta); |
|
109 r:= sqr(Vx) + sqr(Vy); |
|
110 if r <= 1 then |
|
111 begin |
|
112 Score:= CheckTrace; |
|
113 if Result <= Score then |
|
114 begin |
|
115 r:= sqrt(r); |
|
116 Angle:= DxDy2AttackAngle(Vx, Vy); |
|
117 Power:= round(r * cMaxPower); |
|
118 Time:= TestTime; |
|
119 Result:= Score |
|
120 end; |
|
121 end |
|
122 until (TestTime = 5000) |
|
123 end; |
|
124 |
65 end. |
125 end. |