author | displacer |
Sat, 27 Jan 2007 17:41:08 +0000 | |
changeset 372 | 4bac77f8cd38 |
parent 371 | 731ad6d27bd1 |
child 374 | 95169697cc38 |
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; |
24 |
(*function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
|
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; |
|
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 |
( |
369 | 33 |
{amGrenade} nil,//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, |
369 | 37 |
{amShotgun} nil,//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; |
|
82 | 95 |
rTime:= 50; |
71 | 96 |
ExplR:= 0; |
70 | 97 |
Result:= BadTurn; |
4 | 98 |
repeat |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
99 |
rTime:= rTime + 300 + Level * 50 + random(200); |
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 |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
116 |
until (rTime > 4500); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
117 |
TestBazooka:= Result |
39 | 118 |
end; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
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; |
371 | 123 |
Score, EX, EY: 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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
x:= Me.X; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
131 |
y:= Me.Y; |
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) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
until TestColl(round(x), round(y), 5) or (t = 0); |
71 | 140 |
EX:= round(x); |
141 |
EY:= round(y); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
142 |
if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101) |
371 | 143 |
else Result:= 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); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
152 |
Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
153 |
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
|
154 |
r:= sqr(Vx) + sqr(Vy); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
155 |
if r <= 1 then |
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
r:= sqrt(r); |
136 | 161 |
Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random(Level)); |
162 |
Power:= round(r * cMaxPower) + rndSign(random(Level) * 12); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
163 |
Time:= TestTime; |
74 | 164 |
ExplR:= 100; |
71 | 165 |
ExplX:= EX; |
166 |
ExplY:= EY; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
Result:= Score |
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 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
170 |
until (TestTime = 5000) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
171 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
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; |
136 | 175 |
begin |
79 | 176 |
ExplR:= 0; |
70 | 177 |
if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |
178 |
begin |
|
179 |
Result:= BadTurn; |
|
180 |
exit |
|
181 |
end; |
|
182 |
Time:= 0; |
|
183 |
Power:= 1; |
|
184 |
Vx:= (Targ.X - Me.X)/1024; |
|
185 |
Vy:= (Targ.Y - Me.Y)/1024; |
|
186 |
x:= Me.X; |
|
187 |
y:= Me.Y; |
|
188 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
189 |
repeat |
|
190 |
x:= x + vX; |
|
191 |
y:= y + vY; |
|
192 |
if TestColl(round(x), round(y), 2) then |
|
193 |
begin |
|
143 | 194 |
Result:= RateShove(Me, round(x), round(y), 25, 25) * 2; |
195 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64 |
|
196 |
else dec(Result, Level * 4000); |
|
70 | 197 |
exit |
198 |
end |
|
199 |
until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024); |
|
200 |
Result:= BadTurn |
|
201 |
end; |
|
202 |
||
371 | 203 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 204 |
var Vx, Vy, x, y, t: hwFloat; |
75 | 205 |
d: Longword; |
206 |
begin |
|
79 | 207 |
ExplR:= 0; |
75 | 208 |
if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then |
209 |
begin |
|
210 |
Result:= BadTurn; |
|
211 |
exit |
|
212 |
end; |
|
213 |
Time:= 0; |
|
214 |
Power:= 1; |
|
215 |
t:= sqrt(sqr(Targ.X - Me.X) + sqr(Targ.Y - Me.Y)) * 2; |
|
216 |
Vx:= (Targ.X - Me.X) / t; |
|
217 |
Vy:= (Targ.Y - Me.Y) / t; |
|
218 |
x:= Me.X; |
|
219 |
y:= Me.Y; |
|
220 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
|
221 |
d:= 0; |
|
222 |
repeat |
|
223 |
x:= x + vX; |
|
224 |
y:= y + vY; |
|
225 |
if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0) |
|
226 |
and (Land[round(y), round(x)] <> 0) then inc(d); |
|
227 |
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); |
|
228 |
if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024) |
|
371 | 229 |
else Result:= Low(LongInt) |
75 | 230 |
end; |
231 |
||
371 | 232 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
79 | 233 |
begin |
234 |
ExplR:= 0; |
|
143 | 235 |
if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then |
79 | 236 |
begin |
237 |
Result:= BadTurn; |
|
238 |
exit |
|
239 |
end; |
|
240 |
Time:= 0; |
|
241 |
Power:= 1; |
|
108 | 242 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
143 | 243 |
Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30); |
244 |
if Result <= 0 then Result:= BadTurn |
|
79 | 245 |
end; |
246 |
||
371 | 247 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
248 |
var i: LongInt; |
|
82 | 249 |
begin |
250 |
ExplR:= 0; |
|
251 |
if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then |
|
252 |
begin |
|
253 |
Result:= BadTurn; |
|
254 |
exit |
|
255 |
end; |
|
256 |
Time:= 0; |
|
257 |
Power:= 1; |
|
108 | 258 |
Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1); |
82 | 259 |
Result:= 0; |
260 |
for i:= 0 to 4 do |
|
143 | 261 |
Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30); |
262 |
if Result <= 0 then Result:= BadTurn |
|
82 | 263 |
end; |
351 | 264 |
} |
4 | 265 |
end. |