author | unc0rr |
Fri, 23 Jun 2006 20:02:41 +0000 | |
changeset 70 | 82d93eeecebe |
parent 66 | 9643d75baf1e |
child 71 | 5f56c6979496 |
permissions | -rw-r--r-- |
4 | 1 |
unit uAIAmmoTests; |
2 |
interface |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
3 |
uses SDLh, uGears, uConsts; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
4 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
5 |
function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
6 |
function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
70 | 7 |
function TestShotgun(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
4 | 8 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
9 |
type TAmmoTestProc = function (Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
10 |
const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
11 |
( |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
12 |
{amGrenade} TestGrenade, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
13 |
{amBazooka} TestBazooka, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
14 |
{amUFO} nil, |
70 | 15 |
{amShotgun} TestShotgun, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
16 |
{amPickHammer} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
17 |
{amSkip} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
18 |
{amRope} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
19 |
{amMine} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
20 |
{amDEagle} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
21 |
{amDynamite} nil |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
22 |
); |
4 | 23 |
|
24 |
implementation |
|
64 | 25 |
uses uMisc, uAIMisc; |
70 | 26 |
const BadTurn = Low(integer); |
4 | 27 |
|
64 | 28 |
function Metric(x1, y1, x2, y2: integer): integer; |
4 | 29 |
begin |
64 | 30 |
Result:= abs(x1 - x2) + abs(y1 - y2) |
4 | 31 |
end; |
32 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
33 |
function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
4 | 34 |
var Vx, Vy, r: real; |
35 |
rTime: real; |
|
64 | 36 |
Score: integer; |
4 | 37 |
|
64 | 38 |
function CheckTrace: integer; |
4 | 39 |
var x, y, dX, dY: real; |
40 |
t: integer; |
|
41 |
begin |
|
53 | 42 |
x:= Me.X; |
43 |
y:= Me.Y; |
|
4 | 44 |
dX:= Vx; |
45 |
dY:= -Vy; |
|
64 | 46 |
t:= trunc(rTime); |
4 | 47 |
repeat |
48 |
x:= x + dX; |
|
49 |
y:= y + dY; |
|
50 |
dX:= dX + cWindSpeed; |
|
51 |
dY:= dY + cGravity; |
|
52 |
dec(t) |
|
64 | 53 |
until TestColl(round(x), round(y), 5) or (t <= 0); |
70 | 54 |
Result:= RateExplosion(Me, round(x), round(y), 101); |
55 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
4 | 56 |
end; |
57 |
||
58 |
begin |
|
59 |
Time:= 0; |
|
60 |
rTime:= 10; |
|
70 | 61 |
Result:= BadTurn; |
4 | 62 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
rTime:= rTime + 100 + random*250; |
4 | 64 |
Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; |
65 |
Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; |
|
66 |
r:= sqr(Vx) + sqr(Vy); |
|
64 | 67 |
if r <= 1 then |
4 | 68 |
begin |
64 | 69 |
Score:= CheckTrace; |
70 |
if Result <= Score then |
|
71 |
begin |
|
72 |
r:= sqrt(r); |
|
73 |
Angle:= DxDy2AttackAngle(Vx, Vy); |
|
74 |
Power:= round(r * cMaxPower); |
|
75 |
Result:= Score |
|
76 |
end; |
|
4 | 77 |
end |
64 | 78 |
until (rTime >= 5000) |
39 | 79 |
end; |
4 | 80 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
81 |
function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
70 | 82 |
const tDelta = 24; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
83 |
var Vx, Vy, r: real; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
84 |
Score: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
85 |
TestTime: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
86 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
87 |
function CheckTrace: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
88 |
var x, y, dY: real; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
89 |
t: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
90 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
91 |
x:= Me.X; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
92 |
y:= Me.Y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
93 |
dY:= -Vy; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
94 |
t:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
95 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
96 |
x:= x + Vx; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
97 |
y:= y + dY; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
98 |
dY:= dY + cGravity; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
99 |
dec(t) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
100 |
until TestColl(round(x), round(y), 5) or (t = 0); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
101 |
if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
102 |
else Result:= Low(integer) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
103 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
104 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
105 |
begin |
70 | 106 |
Result:= BadTurn; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
107 |
TestTime:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
108 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
109 |
inc(TestTime, 1000); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
110 |
Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
111 |
Vy:= cGravity*((TestTime + tDelta) div 2) - (Targ.Y - Me.Y) / (TestTime + tDelta); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
r:= sqr(Vx) + sqr(Vy); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
if r <= 1 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
Score:= CheckTrace; |
70 | 116 |
if Result < Score then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
r:= sqrt(r); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
Angle:= DxDy2AttackAngle(Vx, Vy); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
Power:= round(r * cMaxPower); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
Time:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
Result:= Score |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
until (TestTime = 5000) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
|
70 | 128 |
function TestShotgun(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer; |
129 |
var Vx, Vy, x, y: real; |
|
130 |
begin |
|
131 |
if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |
|
132 |
begin |
|
133 |
Result:= BadTurn; |
|
134 |
exit |
|
135 |
end; |
|
136 |
Time:= 0; |
|
137 |
Power:= 1; |
|
138 |
Vx:= (Targ.X - Me.X)/1024; |
|
139 |
Vy:= (Targ.Y - Me.Y)/1024; |
|
140 |
x:= Me.X; |
|
141 |
y:= Me.Y; |
|
142 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
143 |
repeat |
|
144 |
x:= x + vX; |
|
145 |
y:= y + vY; |
|
146 |
if TestColl(round(x), round(y), 2) then |
|
147 |
begin |
|
148 |
Result:= RateExplosion(Me, round(x), round(y), 25) * 2; |
|
149 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64; |
|
150 |
exit |
|
151 |
end |
|
152 |
until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024); |
|
153 |
Result:= BadTurn |
|
154 |
end; |
|
155 |
||
4 | 156 |
end. |