hedgewars/uAI.pas
changeset 4436 94c948a92759
parent 4403 0dfe26f48ec1
child 4900 8ad0e23e6d63
equal deleted inserted replaced
4366:d19adc635c99 4436:94c948a92759
    27 
    27 
    28 procedure ProcessBot;
    28 procedure ProcessBot;
    29 procedure FreeActionsList;
    29 procedure FreeActionsList;
    30 
    30 
    31 implementation
    31 implementation
    32 uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc,
    32 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
    33      uAmmos, uConsole, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF};
    33      uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes,
       
    34      uVariables, uCommands, uUtils, uDebug;
    34 
    35 
    35 var BestActions: TActions;
    36 var BestActions: TActions;
    36     CanUseAmmo: array [TAmmoType] of boolean;
    37     CanUseAmmo: array [TAmmoType] of boolean;
    37     StopThinking: boolean;
    38     StopThinking: boolean;
    38     ThinkThread: TThreadID;
    39     ThinkThread: TThreadID;
    63 var BotLevel: Byte;
    64 var BotLevel: Byte;
    64     ap: TAttackParams;
    65     ap: TAttackParams;
    65     Score, i: LongInt;
    66     Score, i: LongInt;
    66     a, aa: TAmmoType;
    67     a, aa: TAmmoType;
    67 begin
    68 begin
    68 BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel;
    69 BotLevel:= Me^.Hedgehog^.BotLevel;
    69 
    70 
    70 for i:= 0 to Pred(Targets.Count) do
    71 for i:= 0 to Pred(Targets.Count) do
    71     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
    72     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
    72        begin
    73        begin
    73        with CurrentHedgehog^ do
    74        with CurrentHedgehog^ do
   192 ticks:= 0; // avoid compiler hint
   193 ticks:= 0; // avoid compiler hint
   193 Actions.Count:= 0;
   194 Actions.Count:= 0;
   194 Actions.Pos:= 0;
   195 Actions.Pos:= 0;
   195 Actions.Score:= 0;
   196 Actions.Score:= 0;
   196 Stack.Count:= 0;
   197 Stack.Count:= 0;
   197 BotLevel:= PHedgehog(Me^.Hedgehog)^.BotLevel;
   198 BotLevel:= Me^.Hedgehog^.BotLevel;
   198 
   199 
   199 tmp:= random(2) + 1;
   200 tmp:= random(2) + 1;
   200 Push(0, Actions, Me^, tmp);
   201 Push(0, Actions, Me^, tmp);
   201 Push(0, Actions, Me^, tmp xor 3);
   202 Push(0, Actions, Me^, tmp xor 3);
   202 
   203 
   203 if (Me^.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
   204 if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
   204                                    else maxticks:= TurnTimeLeft;
   205                                    else maxticks:= TurnTimeLeft;
   205 
   206 
   206 if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
   207 if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
   207 BestRate:= RatePlace(Me);
   208 BestRate:= RatePlace(Me);
   208 BaseRate:= max(BestRate, 0);
   209 BaseRate:= Max(BestRate, 0);
   209 
   210 
   210 while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do
   211 while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do
   211     begin
   212     begin
   212     Pop(ticks, Actions, Me^);
   213     Pop(ticks, Actions, Me^);
   213 
   214 
   319    exit
   320    exit
   320    end;
   321    end;
   321 
   322 
   322 FillBonuses((Me^.State and gstAttacked) <> 0);
   323 FillBonuses((Me^.State and gstAttacked) <> 0);
   323 for a:= Low(TAmmoType) to High(TAmmoType) do
   324 for a:= Low(TAmmoType) to High(TAmmoType) do
   324     CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(PHedgehog(Me^.Hedgehog)^, a);
   325     CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a);
   325 {$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF}
   326 {$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF}
   326 BeginThread(@Think, Me, ThinkThread)
   327 BeginThread(@Think, Me, ThinkThread)
   327 end;
   328 end;
   328 
   329 
   329 procedure ProcessBot;
   330 procedure ProcessBot;