author | unc0rr |
Sat, 09 Dec 2006 19:47:31 +0000 | |
changeset 293 | 00a532e8808e |
parent 285 | cdab49768c83 |
child 302 | 7aca131ecd7f |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
71 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
71 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
71 | 17 |
*) |
18 |
||
4 | 19 |
unit uAIAmmoTests; |
20 |
interface |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
21 |
uses SDLh, uGears, uConsts; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
22 |
|
136 | 23 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
24 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
|
25 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
|
26 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
|
27 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
|
28 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
|
4 | 29 |
|
136 | 30 |
type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
31 |
const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
32 |
( |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
33 |
{amGrenade} TestGrenade, |
78 | 34 |
{amClusterBomb} nil, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
35 |
{amBazooka} TestBazooka, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
36 |
{amUFO} nil, |
70 | 37 |
{amShotgun} TestShotgun, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
38 |
{amPickHammer} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
39 |
{amSkip} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
40 |
{amRope} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
41 |
{amMine} nil, |
75 | 42 |
{amDEagle} TestDesertEagle, |
79 | 43 |
{amDynamite} nil, |
143 | 44 |
{amFirePunch} TestFirePunch, |
211 | 45 |
{amBaseballBat} TestBaseballBat, |
263 | 46 |
{amParachute} nil, |
285 | 47 |
{amAirAttack} nil, |
48 |
{amMineStrike} nil |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
49 |
); |
4 | 50 |
|
143 | 51 |
const BadTurn = Low(integer); |
52 |
||
4 | 53 |
implementation |
75 | 54 |
uses uMisc, uAIMisc, uLand; |
4 | 55 |
|
64 | 56 |
function Metric(x1, y1, x2, y2: integer): integer; |
4 | 57 |
begin |
64 | 58 |
Result:= abs(x1 - x2) + abs(y1 - y2) |
4 | 59 |
end; |
60 |
||
136 | 61 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
107 | 62 |
var Vx, Vy, r: Double; |
63 |
rTime: Double; |
|
71 | 64 |
Score, EX, EY: integer; |
4 | 65 |
|
64 | 66 |
function CheckTrace: integer; |
107 | 67 |
var x, y, dX, dY: Double; |
4 | 68 |
t: integer; |
69 |
begin |
|
53 | 70 |
x:= Me.X; |
71 |
y:= Me.Y; |
|
4 | 72 |
dX:= Vx; |
73 |
dY:= -Vy; |
|
64 | 74 |
t:= trunc(rTime); |
4 | 75 |
repeat |
76 |
x:= x + dX; |
|
77 |
y:= y + dY; |
|
78 |
dX:= dX + cWindSpeed; |
|
79 |
dY:= dY + cGravity; |
|
80 |
dec(t) |
|
64 | 81 |
until TestColl(round(x), round(y), 5) or (t <= 0); |
71 | 82 |
EX:= round(x); |
83 |
EY:= round(y); |
|
70 | 84 |
Result:= RateExplosion(Me, round(x), round(y), 101); |
85 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
4 | 86 |
end; |
87 |
||
88 |
begin |
|
89 |
Time:= 0; |
|
82 | 90 |
rTime:= 50; |
71 | 91 |
ExplR:= 0; |
70 | 92 |
Result:= BadTurn; |
4 | 93 |
repeat |
198 | 94 |
rTime:= rTime + 300 + Level * 50 + random * 200; |
4 | 95 |
Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; |
96 |
Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; |
|
97 |
r:= sqr(Vx) + sqr(Vy); |
|
64 | 98 |
if r <= 1 then |
4 | 99 |
begin |
64 | 100 |
Score:= CheckTrace; |
101 |
if Result <= Score then |
|
102 |
begin |
|
103 |
r:= sqrt(r); |
|
141 | 104 |
Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8)); |
136 | 105 |
Power:= round(r * cMaxPower) - random((Level - 1) * 15 + 1); |
74 | 106 |
ExplR:= 100; |
71 | 107 |
ExplX:= EX; |
108 |
ExplY:= EY; |
|
143 | 109 |
Result:= Score |
64 | 110 |
end; |
4 | 111 |
end |
82 | 112 |
until (rTime >= 4500) |
39 | 113 |
end; |
4 | 114 |
|
136 | 115 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
70 | 116 |
const tDelta = 24; |
107 | 117 |
var Vx, Vy, r: Double; |
71 | 118 |
Score, EX, EY: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
TestTime: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
function CheckTrace: integer; |
107 | 122 |
var x, y, dY: Double; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
t: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
x:= Me.X; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
y:= Me.Y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
dY:= -Vy; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
t:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
x:= x + Vx; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
131 |
y:= y + dY; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
132 |
dY:= dY + cGravity; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
133 |
dec(t) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
134 |
until TestColl(round(x), round(y), 5) or (t = 0); |
71 | 135 |
EX:= round(x); |
136 |
EY:= round(y); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
137 |
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
|
138 |
else Result:= Low(integer) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
140 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
141 |
begin |
70 | 142 |
Result:= BadTurn; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
143 |
TestTime:= 0; |
71 | 144 |
ExplR:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
inc(TestTime, 1000); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
147 |
Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
148 |
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
|
149 |
r:= sqr(Vx) + sqr(Vy); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
150 |
if r <= 1 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
151 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
152 |
Score:= CheckTrace; |
70 | 153 |
if Result < Score then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
154 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
155 |
r:= sqrt(r); |
136 | 156 |
Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random(Level)); |
157 |
Power:= round(r * cMaxPower) + rndSign(random(Level) * 12); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
158 |
Time:= TestTime; |
74 | 159 |
ExplR:= 100; |
71 | 160 |
ExplX:= EX; |
161 |
ExplY:= EY; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
Result:= Score |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
163 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
164 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
165 |
until (TestTime = 5000) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
166 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
|
136 | 168 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
107 | 169 |
var Vx, Vy, x, y: Double; |
136 | 170 |
begin |
79 | 171 |
ExplR:= 0; |
70 | 172 |
if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |
173 |
begin |
|
174 |
Result:= BadTurn; |
|
175 |
exit |
|
176 |
end; |
|
177 |
Time:= 0; |
|
178 |
Power:= 1; |
|
179 |
Vx:= (Targ.X - Me.X)/1024; |
|
180 |
Vy:= (Targ.Y - Me.Y)/1024; |
|
181 |
x:= Me.X; |
|
182 |
y:= Me.Y; |
|
183 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
184 |
repeat |
|
185 |
x:= x + vX; |
|
186 |
y:= y + vY; |
|
187 |
if TestColl(round(x), round(y), 2) then |
|
188 |
begin |
|
143 | 189 |
Result:= RateShove(Me, round(x), round(y), 25, 25) * 2; |
190 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
191 |
else dec(Result, Level * 4000); |
|
70 | 192 |
exit |
193 |
end |
|
194 |
until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024); |
|
195 |
Result:= BadTurn |
|
196 |
end; |
|
197 |
||
136 | 198 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
107 | 199 |
var Vx, Vy, x, y, t: Double; |
75 | 200 |
d: Longword; |
201 |
begin |
|
79 | 202 |
ExplR:= 0; |
75 | 203 |
if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then |
204 |
begin |
|
205 |
Result:= BadTurn; |
|
206 |
exit |
|
207 |
end; |
|
208 |
Time:= 0; |
|
209 |
Power:= 1; |
|
210 |
t:= sqrt(sqr(Targ.X - Me.X) + sqr(Targ.Y - Me.Y)) * 2; |
|
211 |
Vx:= (Targ.X - Me.X) / t; |
|
212 |
Vy:= (Targ.Y - Me.Y) / t; |
|
213 |
x:= Me.X; |
|
214 |
y:= Me.Y; |
|
215 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
216 |
d:= 0; |
|
217 |
repeat |
|
218 |
x:= x + vX; |
|
219 |
y:= y + vY; |
|
220 |
if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0) |
|
221 |
and (Land[round(y), round(x)] <> 0) then inc(d); |
|
222 |
until (abs(Targ.X - x) + abs(Targ.Y - y) < 2) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024) or (d > 200); |
|
223 |
if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024) |
|
224 |
else Result:= Low(integer) |
|
225 |
end; |
|
226 |
||
136 | 227 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
79 | 228 |
begin |
229 |
ExplR:= 0; |
|
143 | 230 |
if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then |
79 | 231 |
begin |
232 |
Result:= BadTurn; |
|
233 |
exit |
|
234 |
end; |
|
235 |
Time:= 0; |
|
236 |
Power:= 1; |
|
108 | 237 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
143 | 238 |
Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30); |
239 |
if Result <= 0 then Result:= BadTurn |
|
79 | 240 |
end; |
241 |
||
136 | 242 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
82 | 243 |
var i: integer; |
244 |
begin |
|
245 |
ExplR:= 0; |
|
246 |
if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then |
|
247 |
begin |
|
248 |
Result:= BadTurn; |
|
249 |
exit |
|
250 |
end; |
|
251 |
Time:= 0; |
|
252 |
Power:= 1; |
|
108 | 253 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
82 | 254 |
Result:= 0; |
255 |
for i:= 0 to 4 do |
|
143 | 256 |
Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30); |
257 |
if Result <= 0 then Result:= BadTurn |
|
82 | 258 |
end; |
259 |
||
4 | 260 |
end. |