4
|
1 |
unit uAIAmmoTests;
|
|
2 |
interface
|
64
|
3 |
uses SDLh;
|
4
|
4 |
|
64
|
5 |
function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
|
4
|
6 |
|
|
7 |
implementation
|
64
|
8 |
uses uMisc, uAIMisc;
|
|
9 |
const cMyHHDamageScore = -3000;
|
4
|
10 |
|
64
|
11 |
function Metric(x1, y1, x2, y2: integer): integer;
|
4
|
12 |
begin
|
64
|
13 |
Result:= abs(x1 - x2) + abs(y1 - y2)
|
4
|
14 |
end;
|
|
15 |
|
64
|
16 |
function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
|
4
|
17 |
var Vx, Vy, r: real;
|
|
18 |
rTime: real;
|
64
|
19 |
Score: integer;
|
4
|
20 |
|
64
|
21 |
function CheckTrace: integer;
|
4
|
22 |
var x, y, dX, dY: real;
|
|
23 |
t: integer;
|
|
24 |
begin
|
53
|
25 |
x:= Me.X;
|
|
26 |
y:= Me.Y;
|
4
|
27 |
dX:= Vx;
|
|
28 |
dY:= -Vy;
|
64
|
29 |
t:= trunc(rTime);
|
4
|
30 |
repeat
|
|
31 |
x:= x + dX;
|
|
32 |
y:= y + dY;
|
|
33 |
dX:= dX + cWindSpeed;
|
|
34 |
dY:= dY + cGravity;
|
|
35 |
dec(t)
|
64
|
36 |
until TestColl(round(x), round(y), 5) or (t <= 0);
|
|
37 |
if NoMyHHNear(round(x), round(y), 110) then
|
|
38 |
Result:= - Metric(round(x), round(y), Targ.x, Targ.y) div 16
|
|
39 |
else Result:= cMyHHDamageScore;
|
4
|
40 |
end;
|
|
41 |
|
|
42 |
begin
|
|
43 |
Time:= 0;
|
|
44 |
rTime:= 10;
|
64
|
45 |
Result:= Low(integer);
|
4
|
46 |
repeat
|
64
|
47 |
rTime:= rTime + 70 + random*200;
|
4
|
48 |
Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime;
|
|
49 |
Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime;
|
|
50 |
r:= sqr(Vx) + sqr(Vy);
|
64
|
51 |
if r <= 1 then
|
4
|
52 |
begin
|
64
|
53 |
Score:= CheckTrace;
|
|
54 |
if Result <= Score then
|
|
55 |
begin
|
|
56 |
r:= sqrt(r);
|
|
57 |
Angle:= DxDy2AttackAngle(Vx, Vy);
|
|
58 |
Power:= round(r * cMaxPower);
|
|
59 |
Result:= Score
|
|
60 |
end;
|
4
|
61 |
end
|
64
|
62 |
until (rTime >= 5000)
|
39
|
63 |
end;
|
4
|
64 |
|
|
65 |
end.
|