author | displacer |
Wed, 24 Jan 2007 21:58:43 +0000 | |
changeset 363 | c0d788307314 |
parent 351 | 29bc9c36ad5f |
child 369 | 2aed85310727 |
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 |
|
351 | 21 |
uses SDLh, uGears, uConsts, uFloat; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
22 |
|
351 | 23 |
(*function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
136 | 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, |
302 | 48 |
{amMineStrike} nil, |
49 |
{amBlowTorch} nil |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
50 |
); |
4 | 51 |
|
143 | 52 |
const BadTurn = Low(integer); |
351 | 53 |
*) |
143 | 54 |
|
4 | 55 |
implementation |
75 | 56 |
uses uMisc, uAIMisc, uLand; |
351 | 57 |
{ |
64 | 58 |
function Metric(x1, y1, x2, y2: integer): integer; |
4 | 59 |
begin |
64 | 60 |
Result:= abs(x1 - x2) + abs(y1 - y2) |
4 | 61 |
end; |
62 |
||
136 | 63 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
351 | 64 |
var Vx, Vy, r: hwFloat; |
65 |
rTime: hwFloat; |
|
71 | 66 |
Score, EX, EY: integer; |
4 | 67 |
|
64 | 68 |
function CheckTrace: integer; |
351 | 69 |
var x, y, dX, dY: hwFloat; |
4 | 70 |
t: integer; |
71 |
begin |
|
53 | 72 |
x:= Me.X; |
73 |
y:= Me.Y; |
|
4 | 74 |
dX:= Vx; |
75 |
dY:= -Vy; |
|
64 | 76 |
t:= trunc(rTime); |
4 | 77 |
repeat |
78 |
x:= x + dX; |
|
79 |
y:= y + dY; |
|
80 |
dX:= dX + cWindSpeed; |
|
81 |
dY:= dY + cGravity; |
|
82 |
dec(t) |
|
64 | 83 |
until TestColl(round(x), round(y), 5) or (t <= 0); |
71 | 84 |
EX:= round(x); |
85 |
EY:= round(y); |
|
70 | 86 |
Result:= RateExplosion(Me, round(x), round(y), 101); |
87 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
4 | 88 |
end; |
89 |
||
90 |
begin |
|
91 |
Time:= 0; |
|
82 | 92 |
rTime:= 50; |
71 | 93 |
ExplR:= 0; |
70 | 94 |
Result:= BadTurn; |
4 | 95 |
repeat |
198 | 96 |
rTime:= rTime + 300 + Level * 50 + random * 200; |
4 | 97 |
Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; |
98 |
Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; |
|
99 |
r:= sqr(Vx) + sqr(Vy); |
|
64 | 100 |
if r <= 1 then |
4 | 101 |
begin |
64 | 102 |
Score:= CheckTrace; |
103 |
if Result <= Score then |
|
104 |
begin |
|
105 |
r:= sqrt(r); |
|
141 | 106 |
Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8)); |
136 | 107 |
Power:= round(r * cMaxPower) - random((Level - 1) * 15 + 1); |
74 | 108 |
ExplR:= 100; |
71 | 109 |
ExplX:= EX; |
110 |
ExplY:= EY; |
|
143 | 111 |
Result:= Score |
64 | 112 |
end; |
4 | 113 |
end |
82 | 114 |
until (rTime >= 4500) |
39 | 115 |
end; |
4 | 116 |
|
136 | 117 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
70 | 118 |
const tDelta = 24; |
351 | 119 |
var Vx, Vy, r: hwFloat; |
71 | 120 |
Score, EX, EY: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
TestTime: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
function CheckTrace: integer; |
351 | 124 |
var x, y, dY: hwFloat; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
t: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
x:= Me.X; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
y:= Me.Y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
dY:= -Vy; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
t:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
131 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
132 |
x:= x + Vx; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
133 |
y:= y + dY; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
134 |
dY:= dY + cGravity; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
135 |
dec(t) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
136 |
until TestColl(round(x), round(y), 5) or (t = 0); |
71 | 137 |
EX:= round(x); |
138 |
EY:= round(y); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
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
|
140 |
else Result:= Low(integer) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
141 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
142 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
143 |
begin |
70 | 144 |
Result:= BadTurn; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
TestTime:= 0; |
71 | 146 |
ExplR:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
147 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
148 |
inc(TestTime, 1000); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
149 |
Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
150 |
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
|
151 |
r:= sqr(Vx) + sqr(Vy); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
152 |
if r <= 1 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
153 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
154 |
Score:= CheckTrace; |
70 | 155 |
if Result < Score then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
156 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
157 |
r:= sqrt(r); |
136 | 158 |
Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random(Level)); |
159 |
Power:= round(r * cMaxPower) + rndSign(random(Level) * 12); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
Time:= TestTime; |
74 | 161 |
ExplR:= 100; |
71 | 162 |
ExplX:= EX; |
163 |
ExplY:= EY; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
164 |
Result:= Score |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
165 |
end; |
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 |
until (TestTime = 5000) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
169 |
|
136 | 170 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
351 | 171 |
var Vx, Vy, x, y: hwFloat; |
136 | 172 |
begin |
79 | 173 |
ExplR:= 0; |
70 | 174 |
if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |
175 |
begin |
|
176 |
Result:= BadTurn; |
|
177 |
exit |
|
178 |
end; |
|
179 |
Time:= 0; |
|
180 |
Power:= 1; |
|
181 |
Vx:= (Targ.X - Me.X)/1024; |
|
182 |
Vy:= (Targ.Y - Me.Y)/1024; |
|
183 |
x:= Me.X; |
|
184 |
y:= Me.Y; |
|
185 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
186 |
repeat |
|
187 |
x:= x + vX; |
|
188 |
y:= y + vY; |
|
189 |
if TestColl(round(x), round(y), 2) then |
|
190 |
begin |
|
143 | 191 |
Result:= RateShove(Me, round(x), round(y), 25, 25) * 2; |
192 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
193 |
else dec(Result, Level * 4000); |
|
70 | 194 |
exit |
195 |
end |
|
196 |
until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024); |
|
197 |
Result:= BadTurn |
|
198 |
end; |
|
199 |
||
136 | 200 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
351 | 201 |
var Vx, Vy, x, y, t: hwFloat; |
75 | 202 |
d: Longword; |
203 |
begin |
|
79 | 204 |
ExplR:= 0; |
75 | 205 |
if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then |
206 |
begin |
|
207 |
Result:= BadTurn; |
|
208 |
exit |
|
209 |
end; |
|
210 |
Time:= 0; |
|
211 |
Power:= 1; |
|
212 |
t:= sqrt(sqr(Targ.X - Me.X) + sqr(Targ.Y - Me.Y)) * 2; |
|
213 |
Vx:= (Targ.X - Me.X) / t; |
|
214 |
Vy:= (Targ.Y - Me.Y) / t; |
|
215 |
x:= Me.X; |
|
216 |
y:= Me.Y; |
|
217 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
218 |
d:= 0; |
|
219 |
repeat |
|
220 |
x:= x + vX; |
|
221 |
y:= y + vY; |
|
222 |
if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0) |
|
223 |
and (Land[round(y), round(x)] <> 0) then inc(d); |
|
224 |
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); |
|
225 |
if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024) |
|
226 |
else Result:= Low(integer) |
|
227 |
end; |
|
228 |
||
136 | 229 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
79 | 230 |
begin |
231 |
ExplR:= 0; |
|
143 | 232 |
if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then |
79 | 233 |
begin |
234 |
Result:= BadTurn; |
|
235 |
exit |
|
236 |
end; |
|
237 |
Time:= 0; |
|
238 |
Power:= 1; |
|
108 | 239 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
143 | 240 |
Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30); |
241 |
if Result <= 0 then Result:= BadTurn |
|
79 | 242 |
end; |
243 |
||
136 | 244 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer; |
82 | 245 |
var i: integer; |
246 |
begin |
|
247 |
ExplR:= 0; |
|
248 |
if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then |
|
249 |
begin |
|
250 |
Result:= BadTurn; |
|
251 |
exit |
|
252 |
end; |
|
253 |
Time:= 0; |
|
254 |
Power:= 1; |
|
108 | 255 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
82 | 256 |
Result:= 0; |
257 |
for i:= 0 to 4 do |
|
143 | 258 |
Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30); |
259 |
if Result <= 0 then Result:= BadTurn |
|
82 | 260 |
end; |
351 | 261 |
} |
4 | 262 |
end. |