author | displacer |
Thu, 06 Dec 2007 20:25:32 +0000 | |
changeset 630 | 38338573e09a |
parent 602 | f7628ebfccde |
child 676 | 2aa3082937ac |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 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 |
|
4 | 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. |
|
4 | 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 |
|
4 | 17 |
*) |
18 |
||
19 |
unit uAI; |
|
20 |
interface |
|
351 | 21 |
uses uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
433 | 23 |
procedure ProcessBot; |
64 | 24 |
procedure FreeActionsList; |
4 | 25 |
|
26 |
implementation |
|
369 | 27 |
uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc, |
509 | 28 |
uAmmos, uConsole, uCollisions, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}; |
4 | 29 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
30 |
var BestActions: TActions; |
509 | 31 |
CanUseAmmo: array [TAmmoType] of boolean; |
433 | 32 |
StopThinking: boolean; |
599 | 33 |
ThinkThread: TThreadID; |
509 | 34 |
hasThread: LongInt = 0; |
599 | 35 |
|
369 | 36 |
procedure FreeActionsList; |
64 | 37 |
begin |
433 | 38 |
{$IFDEF DEBUGFILE}AddFileLog('FreeActionsList called');{$ENDIF} |
509 | 39 |
if hasThread <> 0 then |
433 | 40 |
begin |
41 |
{$IFDEF DEBUGFILE}AddFileLog('Waiting AI thread to finish');{$ENDIF} |
|
42 |
StopThinking:= true; |
|
509 | 43 |
repeat |
44 |
SDL_Delay(10) |
|
45 |
until hasThread = 0 |
|
433 | 46 |
end; |
434 | 47 |
|
602 | 48 |
with CurrentHedgehog^ do |
445 | 49 |
if Gear <> nil then |
50 |
if BotLevel <> 0 then |
|
51 |
begin |
|
52 |
if (Gear^.Message and gm_Left) <> 0 then ParseCommand('-left', true); |
|
53 |
if (Gear^.Message and gm_Right) <> 0 then ParseCommand('-right', true); |
|
54 |
end; |
|
442 | 55 |
|
64 | 56 |
BestActions.Count:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
57 |
BestActions.Pos:= 0 |
369 | 58 |
end; |
59 |
||
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
60 |
procedure TestAmmos(var Actions: TActions; Me: PGear; isMoved: boolean); |
545 | 61 |
var BotLevel: Longword; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
62 |
ap: TAttackParams; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
63 |
Score, i: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
a, aa: TAmmoType; |
4 | 65 |
begin |
369 | 66 |
BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel; |
433 | 67 |
|
64 | 68 |
for i:= 0 to Pred(Targets.Count) do |
509 | 69 |
if (Targets.ar[i].Score >= 0) and (not StopThinking) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
70 |
begin |
602 | 71 |
with CurrentHedgehog^ do |
369 | 72 |
a:= Ammo^[CurSlot, CurAmmo].AmmoType; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
73 |
aa:= a; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
74 |
repeat |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
75 |
if (CanUseAmmo[a]) and |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
76 |
((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
77 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
78 |
Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap); |
139 | 79 |
if Actions.Score + Score > BestActions.Score then |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
80 |
if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + LongInt(BotLevel) * 2048) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
81 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
82 |
BestActions:= Actions; |
136 | 83 |
inc(BestActions.Score, Score); |
194 | 84 |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
85 |
AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
86 |
if (ap.Time <> 0) then AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
87 |
if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0) |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
88 |
else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0); |
83 | 89 |
if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
90 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
91 |
ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
92 |
if ap.Angle > 0 then |
83 | 93 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
94 |
AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
95 |
AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
96 |
end else if ap.Angle < 0 then |
83 | 97 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
98 |
AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
99 |
AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) |
83 | 100 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
101 |
end; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
102 |
if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
103 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
104 |
AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
105 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
106 |
if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
107 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
108 |
AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
109 |
AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
110 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
111 |
if ap.ExplR > 0 then |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
112 |
AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
if a = High(TAmmoType) then a:= Low(TAmmoType) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
116 |
else inc(a) |
509 | 117 |
until (a = aa) or |
602 | 118 |
(CurrentHedgehog^.AttacksNum > 0) or |
509 | 119 |
StopThinking |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
end |
64 | 121 |
end; |
4 | 122 |
|
64 | 123 |
procedure Walk(Me: PGear); |
80 | 124 |
const FallPixForBranching = cHHRadius * 2 + 8; |
433 | 125 |
cBranchStackSize = 12; |
126 |
||
127 |
type TStackEntry = record |
|
128 |
WastedTicks: Longword; |
|
129 |
MadeActions: TActions; |
|
130 |
Hedgehog: TGear; |
|
131 |
end; |
|
132 |
||
133 |
var Stack: record |
|
134 |
Count: Longword; |
|
135 |
States: array[0..Pred(cBranchStackSize)] of TStackEntry; |
|
136 |
end; |
|
137 |
||
138 |
function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean; |
|
139 |
var Result: boolean; |
|
140 |
begin |
|
141 |
Result:= (Stack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5); |
|
142 |
if Result then |
|
143 |
with Stack.States[Stack.Count] do |
|
144 |
begin |
|
145 |
WastedTicks:= Ticks; |
|
146 |
MadeActions:= Actions; |
|
147 |
Hedgehog:= Me; |
|
148 |
Hedgehog.Message:= Dir; |
|
149 |
inc(Stack.Count) |
|
150 |
end; |
|
151 |
Push:= Result |
|
152 |
end; |
|
153 |
||
154 |
procedure Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear); |
|
155 |
begin |
|
156 |
dec(Stack.Count); |
|
157 |
with Stack.States[Stack.Count] do |
|
158 |
begin |
|
159 |
Ticks:= WastedTicks; |
|
160 |
Actions:= MadeActions; |
|
161 |
Me:= Hedgehog |
|
162 |
end |
|
163 |
end; |
|
164 |
||
165 |
function PosInThinkStack(Me: PGear): boolean; |
|
166 |
var i: Longword; |
|
167 |
begin |
|
168 |
i:= 0; |
|
169 |
while (i < Stack.Count) do |
|
170 |
begin |
|
171 |
if(not(hwAbs(Stack.States[i].Hedgehog.X - Me^.X) + |
|
498 | 172 |
hwAbs(Stack.States[i].Hedgehog.Y - Me^.Y) > _2)) and |
433 | 173 |
(Stack.States[i].Hedgehog.Message = Me^.Message) then exit(true); |
174 |
inc(i) |
|
175 |
end; |
|
176 |
PosInThinkStack:= false |
|
177 |
end; |
|
178 |
||
179 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
180 |
var Actions: TActions; |
433 | 181 |
ticks, maxticks, steps, BotLevel, tmp: Longword; |
182 |
BaseRate, BestRate, Rate: integer; |
|
75 | 183 |
GoInfo: TGoInfo; |
80 | 184 |
CanGo: boolean; |
185 |
AltMe: TGear; |
|
64 | 186 |
begin |
433 | 187 |
Actions.Count:= 0; |
188 |
Actions.Pos:= 0; |
|
189 |
Actions.Score:= 0; |
|
190 |
Stack.Count:= 0; |
|
369 | 191 |
BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel; |
75 | 192 |
|
433 | 193 |
tmp:= random(2) + 1; |
194 |
Push(0, Actions, Me^, tmp); |
|
195 |
Push(0, Actions, Me^, tmp xor 3); |
|
196 |
||
369 | 197 |
if (Me^.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel) |
433 | 198 |
else maxticks:= TurnTimeLeft; |
75 | 199 |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
200 |
if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false); |
433 | 201 |
BestRate:= RatePlace(Me); |
202 |
BaseRate:= max(BestRate, 0); |
|
75 | 203 |
|
433 | 204 |
while (Stack.Count > 0) and not StopThinking do |
205 |
begin |
|
206 |
Pop(ticks, Actions, Me^); |
|
193 | 207 |
|
433 | 208 |
AddAction(Actions, Me^.Message, aim_push, 250, 0, 0); |
369 | 209 |
if (Me^.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0) |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
210 |
else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
211 |
steps:= 0; |
82 | 212 |
|
433 | 213 |
while (not StopThinking) and (not PosInThinkStack(Me)) do |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
214 |
begin |
80 | 215 |
CanGo:= HHGo(Me, @AltMe, GoInfo); |
75 | 216 |
inc(ticks, GoInfo.Ticks); |
217 |
if ticks > maxticks then break; |
|
194 | 218 |
|
136 | 219 |
if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support |
80 | 220 |
if Push(ticks, Actions, AltMe, Me^.Message) then |
433 | 221 |
with Stack.States[Pred(Stack.Count)] do |
80 | 222 |
begin |
369 | 223 |
AddAction(MadeActions, aia_HJump, 0, 305, 0, 0); |
224 |
AddAction(MadeActions, aia_HJump, 0, 350, 0, 0); |
|
80 | 225 |
end; |
136 | 226 |
if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support |
80 | 227 |
if Push(ticks, Actions, AltMe, Me^.Message) then |
433 | 228 |
with Stack.States[Pred(Stack.Count)] do |
369 | 229 |
AddAction(MadeActions, aia_LJump, 0, 305, 0, 0); |
433 | 230 |
|
80 | 231 |
if not CanGo then break; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
232 |
inc(steps); |
544 | 233 |
Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X); |
70 | 234 |
Rate:= RatePlace(Me); |
433 | 235 |
if Rate > BestRate then |
70 | 236 |
begin |
237 |
BestActions:= Actions; |
|
433 | 238 |
BestRate:= Rate; |
239 |
Me^.State:= Me^.State or gstAttacked // we have better place, go there and don't use ammo |
|
70 | 240 |
end |
433 | 241 |
else if Rate < BestRate then break; |
242 |
if ((Me^.State and gstAttacked) = 0) |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
243 |
and ((steps mod 4) = 0) then TestAmmos(Actions, Me, true); |
193 | 244 |
if GoInfo.FallPix >= FallPixForBranching then |
245 |
Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right |
|
433 | 246 |
end; |
193 | 247 |
|
433 | 248 |
if BestRate > BaseRate then exit |
249 |
end |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
250 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
251 |
|
508 | 252 |
function Think(Me: Pointer): ptrint; |
74 | 253 |
var BackMe, WalkMe: TGear; |
433 | 254 |
StartTicks: Longword; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
255 |
begin |
509 | 256 |
InterlockedIncrement(hasThread); |
433 | 257 |
StartTicks:= GameTicks; |
500 | 258 |
BackMe:= PGear(Me)^; |
509 | 259 |
|
500 | 260 |
if (PGear(Me)^.State and gstAttacked) = 0 then |
74 | 261 |
if Targets.Count > 0 then |
262 |
begin |
|
509 | 263 |
WalkMe:= BackMe; |
74 | 264 |
Walk(@WalkMe); |
433 | 265 |
if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(2000); |
266 |
if BestActions.Score < -1023 then |
|
146 | 267 |
begin |
433 | 268 |
BestActions.Count:= 0; |
269 |
AddAction(BestActions, aia_Skip, 0, 250, 0, 0); |
|
270 |
end; |
|
80 | 271 |
end else |
74 | 272 |
else begin |
433 | 273 |
while (not StopThinking) and (BestActions.Count = 0) do |
274 |
begin |
|
275 |
FillBonuses(true); |
|
276 |
WalkMe:= BackMe; |
|
509 | 277 |
Walk(@WalkMe); |
278 |
if not StopThinking then SDL_Delay(100) |
|
433 | 279 |
end |
280 |
end; |
|
500 | 281 |
PGear(Me)^.State:= PGear(Me)^.State and not gstHHThinking; |
509 | 282 |
Think:= 0; |
283 |
InterlockedDecrement(hasThread) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
284 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
285 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
286 |
procedure StartThink(Me: PGear); |
75 | 287 |
var a: TAmmoType; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
288 |
begin |
542 | 289 |
if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0) |
439 | 290 |
or isInMultiShoot then exit; |
506 | 291 |
|
522 | 292 |
//DeleteCI(Me); // this might break demo |
369 | 293 |
Me^.State:= Me^.State or gstHHThinking; |
294 |
Me^.Message:= 0; |
|
509 | 295 |
|
296 |
BestActions.Count:= 0; |
|
297 |
BestActions.Pos:= 0; |
|
298 |
BestActions.Score:= Low(integer); |
|
299 |
||
433 | 300 |
StopThinking:= false; |
301 |
ThinkingHH:= Me; |
|
509 | 302 |
|
70 | 303 |
FillTargets; |
80 | 304 |
if Targets.Count = 0 then |
305 |
begin |
|
369 | 306 |
OutError('AI: no targets!?', false); |
80 | 307 |
exit |
308 |
end; |
|
369 | 309 |
FillBonuses((Me^.State and gstAttacked) <> 0); |
75 | 310 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
545
diff
changeset
|
311 |
CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(PHedgehog(Me^.Hedgehog)^, a); |
433 | 312 |
{$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF} |
500 | 313 |
BeginThread(@Think, Me, ThinkThread) |
433 | 314 |
end; |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
315 |
|
433 | 316 |
procedure ProcessBot; |
317 |
const StartTicks: Longword = 0; |
|
509 | 318 |
cStopThinkTime = 40; |
4 | 319 |
begin |
602 | 320 |
with CurrentHedgehog^ do |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
321 |
if (Gear <> nil) |
369 | 322 |
and ((Gear^.State and gstHHDriven) <> 0) |
144 | 323 |
and (TurnTimeLeft < cHedgehogTurnTime - 50) then |
433 | 324 |
if ((Gear^.State and gstHHThinking) = 0) then |
509 | 325 |
if (BestActions.Pos >= BestActions.Count) |
326 |
and (TurnTimeLeft > cStopThinkTime) then |
|
433 | 327 |
begin |
328 |
StartThink(Gear); |
|
329 |
StartTicks:= GameTicks |
|
330 |
end else ProcessAction(BestActions, Gear) |
|
509 | 331 |
else if ((GameTicks - StartTicks) > cMaxAIThinkTime) |
332 |
or (TurnTimeLeft <= cStopThinkTime) then StopThinking:= true |
|
369 | 333 |
end; |
4 | 334 |
|
335 |
end. |