author | displacer |
Sat, 03 Feb 2007 00:19:16 +0000 | |
changeset 380 | 86f3d818da1c |
parent 375 | 18012da67681 |
child 393 | db01cc79f278 |
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 |
|
371 | 23 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
374 | 24 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
375 | 25 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
26 |
(*function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
|
371 | 27 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
28 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
|
369 | 29 |
*) |
371 | 30 |
type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
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 |
( |
374 | 33 |
{amGrenade} @TestGrenade, |
78 | 34 |
{amClusterBomb} nil, |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
35 |
{amBazooka} @TestBazooka, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
36 |
{amUFO} nil, |
375 | 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, |
369 | 42 |
{amDEagle} nil,//TestDesertEagle, |
79 | 43 |
{amDynamite} nil, |
369 | 44 |
{amFirePunch} nil,//TestFirePunch, |
45 |
{amBaseballBat} nil,//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 |
|
371 | 52 |
const BadTurn = Low(LongInt); |
369 | 53 |
|
143 | 54 |
|
4 | 55 |
implementation |
75 | 56 |
uses uMisc, uAIMisc, uLand; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
57 |
|
371 | 58 |
function Metric(x1, y1, x2, y2: LongInt): LongInt; |
4 | 59 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
60 |
Metric:= abs(x1 - x2) + abs(y1 - y2) |
4 | 61 |
end; |
62 |
||
371 | 63 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 64 |
var Vx, Vy, r: hwFloat; |
65 |
rTime: hwFloat; |
|
371 | 66 |
Score, EX, EY: LongInt; |
67 |
Result: LongInt; |
|
4 | 68 |
|
371 | 69 |
function CheckTrace: LongInt; |
351 | 70 |
var x, y, dX, dY: hwFloat; |
371 | 71 |
t: LongInt; |
72 |
Result: LongInt; |
|
4 | 73 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
74 |
x:= Me^.X; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
75 |
y:= Me^.Y; |
4 | 76 |
dX:= Vx; |
77 |
dY:= -Vy; |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
78 |
t:= hwRound(rTime); |
4 | 79 |
repeat |
80 |
x:= x + dX; |
|
81 |
y:= y + dY; |
|
82 |
dX:= dX + cWindSpeed; |
|
83 |
dY:= dY + cGravity; |
|
84 |
dec(t) |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
85 |
until TestColl(hwRound(x), hwRound(y), 5) or (t <= 0); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
86 |
EX:= hwRound(x); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
87 |
EY:= hwRound(y); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
88 |
Result:= RateExplosion(Me, EX, EY, 101); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
89 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
90 |
CheckTrace:= Result |
4 | 91 |
end; |
92 |
||
93 |
begin |
|
94 |
Time:= 0; |
|
375 | 95 |
rTime:= 350; |
71 | 96 |
ExplR:= 0; |
70 | 97 |
Result:= BadTurn; |
4 | 98 |
repeat |
375 | 99 |
rTime:= rTime + 300 + Level * 50 + random(300); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
100 |
Vx:= - cWindSpeed * rTime * _0_5 + (Targ.X - hwRound(Me^.X)) / rTime; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
101 |
Vy:= cGravity * rTime * _0_5 - (Targ.Y - hwRound(Me^.Y)) / rTime; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
102 |
r:= Distance(Vx, Vy); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
103 |
if not (r > 1) then |
4 | 104 |
begin |
64 | 105 |
Score:= CheckTrace; |
106 |
if Result <= Score then |
|
107 |
begin |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
108 |
Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 8)); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
109 |
Power:= hwRound(r * cMaxPower) - random((Level - 1) * 15 + 1); |
74 | 110 |
ExplR:= 100; |
71 | 111 |
ExplX:= EX; |
112 |
ExplY:= EY; |
|
143 | 113 |
Result:= Score |
64 | 114 |
end; |
4 | 115 |
end |
375 | 116 |
until (rTime > 4250); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
117 |
TestBazooka:= Result |
39 | 118 |
end; |
374 | 119 |
|
371 | 120 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
70 | 121 |
const tDelta = 24; |
351 | 122 |
var Vx, Vy, r: hwFloat; |
374 | 123 |
Score, EX, EY, Result: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
TestTime: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
|
371 | 126 |
function CheckTrace: LongInt; |
351 | 127 |
var x, y, dY: hwFloat; |
371 | 128 |
t: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
begin |
374 | 130 |
x:= Me^.X; |
131 |
y:= Me^.Y; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
132 |
dY:= -Vy; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
133 |
t:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
134 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
135 |
x:= x + Vx; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
136 |
y:= y + dY; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
137 |
dY:= dY + cGravity; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
138 |
dec(t) |
374 | 139 |
until TestColl(hwRound(x), hwRound(y), 5) or (t = 0); |
140 |
EX:= hwRound(x); |
|
141 |
EY:= hwRound(y); |
|
142 |
if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101) |
|
143 |
else CheckTrace:= Low(LongInt) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
144 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
begin |
70 | 147 |
Result:= BadTurn; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
148 |
TestTime:= 0; |
71 | 149 |
ExplR:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
150 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
151 |
inc(TestTime, 1000); |
374 | 152 |
Vx:= (Targ.X - Me^.X) / (TestTime + tDelta); |
153 |
Vy:= cGravity * ((TestTime + tDelta) div 2) - (Targ.Y - Me^.Y) / (TestTime + tDelta); |
|
154 |
r:= Distance(Vx, Vy); |
|
155 |
if not (r > 1) 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 |
Score:= CheckTrace; |
70 | 158 |
if Result < Score then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
159 |
begin |
374 | 160 |
Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level)); |
161 |
Power:= hwRound(r * cMaxPower) + AIrndSign(random(Level) * 12); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
Time:= TestTime; |
74 | 163 |
ExplR:= 100; |
71 | 164 |
ExplX:= EX; |
165 |
ExplY:= EY; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
166 |
Result:= Score |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
end |
374 | 169 |
until (TestTime = 5000); |
170 |
TestGrenade:= Result |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
171 |
end; |
375 | 172 |
|
371 | 173 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 174 |
var Vx, Vy, x, y: hwFloat; |
375 | 175 |
rx, ry, Result: LongInt; |
176 |
begin |
|
79 | 177 |
ExplR:= 0; |
375 | 178 |
if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then |
70 | 179 |
begin |
180 |
Result:= BadTurn; |
|
181 |
exit |
|
182 |
end; |
|
183 |
Time:= 0; |
|
184 |
Power:= 1; |
|
375 | 185 |
Vx:= (Targ.X - Me^.X) * _1div1024; |
186 |
Vy:= (Targ.Y - Me^.Y) * _1div1024; |
|
187 |
x:= Me^.X; |
|
188 |
y:= Me^.Y; |
|
70 | 189 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
190 |
repeat |
|
191 |
x:= x + vX; |
|
192 |
y:= y + vY; |
|
375 | 193 |
rx:= hwRound(x); |
194 |
ry:= hwRound(y); |
|
195 |
if TestColl(rx, ry, 2) then |
|
70 | 196 |
begin |
375 | 197 |
Result:= RateShove(Me, rx, ry, 25, 25) * 2; |
198 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64 |
|
143 | 199 |
else dec(Result, Level * 4000); |
375 | 200 |
exit(Result) |
70 | 201 |
end |
375 | 202 |
until (hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024); |
203 |
TestShotgun:= BadTurn |
|
70 | 204 |
end; |
375 | 205 |
{ |
371 | 206 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 207 |
var Vx, Vy, x, y, t: hwFloat; |
75 | 208 |
d: Longword; |
209 |
begin |
|
79 | 210 |
ExplR:= 0; |
75 | 211 |
if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then |
212 |
begin |
|
213 |
Result:= BadTurn; |
|
214 |
exit |
|
215 |
end; |
|
216 |
Time:= 0; |
|
217 |
Power:= 1; |
|
218 |
t:= sqrt(sqr(Targ.X - Me.X) + sqr(Targ.Y - Me.Y)) * 2; |
|
219 |
Vx:= (Targ.X - Me.X) / t; |
|
220 |
Vy:= (Targ.Y - Me.Y) / t; |
|
221 |
x:= Me.X; |
|
222 |
y:= Me.Y; |
|
223 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
224 |
d:= 0; |
|
225 |
repeat |
|
226 |
x:= x + vX; |
|
227 |
y:= y + vY; |
|
228 |
if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0) |
|
229 |
and (Land[round(y), round(x)] <> 0) then inc(d); |
|
230 |
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); |
|
231 |
if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024) |
|
371 | 232 |
else Result:= Low(LongInt) |
75 | 233 |
end; |
234 |
||
371 | 235 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
79 | 236 |
begin |
237 |
ExplR:= 0; |
|
143 | 238 |
if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then |
79 | 239 |
begin |
240 |
Result:= BadTurn; |
|
241 |
exit |
|
242 |
end; |
|
243 |
Time:= 0; |
|
244 |
Power:= 1; |
|
108 | 245 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
143 | 246 |
Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30); |
247 |
if Result <= 0 then Result:= BadTurn |
|
79 | 248 |
end; |
249 |
||
371 | 250 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
251 |
var i: LongInt; |
|
82 | 252 |
begin |
253 |
ExplR:= 0; |
|
254 |
if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then |
|
255 |
begin |
|
256 |
Result:= BadTurn; |
|
257 |
exit |
|
258 |
end; |
|
259 |
Time:= 0; |
|
260 |
Power:= 1; |
|
108 | 261 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
82 | 262 |
Result:= 0; |
263 |
for i:= 0 to 4 do |
|
143 | 264 |
Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30); |
265 |
if Result <= 0 then Result:= BadTurn |
|
82 | 266 |
end; |
351 | 267 |
} |
4 | 268 |
end. |