hedgewars/uAI.pas
changeset 136 89970b70b076
parent 111 30ca06092a64
child 139 340ded7cc336
equal deleted inserted replaced
135:53faa20669de 136:89970b70b076
    56 BestActions.Count:= 0;
    56 BestActions.Count:= 0;
    57 BestActions.Pos:= 0
    57 BestActions.Pos:= 0
    58 end;
    58 end;
    59 
    59 
    60 procedure TestAmmos(var Actions: TActions; Me: PGear);
    60 procedure TestAmmos(var Actions: TActions; Me: PGear);
    61 var Time: Longword;
    61 var Time, BotLevel: Longword;
    62     Angle, Power, Score, ExplX, ExplY, ExplR: integer;
    62     Angle, Power, Score, ExplX, ExplY, ExplR: integer;
    63     i: integer;
    63     i: integer;
    64     a, aa: TAmmoType;
    64     a, aa: TAmmoType;
    65 begin
    65 begin
       
    66 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
       
    67 
    66 for i:= 0 to Pred(Targets.Count) do
    68 for i:= 0 to Pred(Targets.Count) do
    67     if (Targets.ar[i].Score >= 0) then
    69     if (Targets.ar[i].Score >= 0) then
    68        begin
    70        begin
    69        with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
    71        with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
    70             a:= Ammo[CurSlot, CurAmmo].AmmoType;
    72             a:= Ammo[CurSlot, CurAmmo].AmmoType;
    71        aa:= a;
    73        aa:= a;
    72        repeat
    74        repeat
    73         if CanUseAmmo[a] then
    75         if CanUseAmmo[a] then
    74            begin
    76            begin
    75            Score:= AmmoTests[a](Me, Targets.ar[i].Point, Time, Angle, Power, ExplX, ExplY, ExplR);
    77            Score:= AmmoTests[a](Me, Targets.ar[i].Point, BotLevel, Time, Angle, Power, ExplX, ExplY, ExplR);
    76            if Actions.Score + Score + Targets.ar[i].Score > BestActions.Score then
    78            if Actions.Score + Score + Targets.ar[i].Score > BestActions.Score then
    77               begin
    79               begin
    78               BestActions:= Actions;
    80               BestActions:= Actions;
    79               inc(BestActions.Score, Score + Targets.ar[i].Score);
    81               inc(BestActions.Score, Score);
    80               AddAction(BestActions, aia_Weapon, Longword(a), 500);
    82               AddAction(BestActions, aia_Weapon, Longword(a), 500);
    81               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
    83               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
    82               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
    84               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
    83               else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
    85               else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
    84               if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
    86               if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
   160           end
   162           end
   161     end;
   163     end;
   162 
   164 
   163 
   165 
   164 var Actions: TActions;
   166 var Actions: TActions;
   165     ticks, maxticks, steps: Longword;
   167     ticks, maxticks, steps, BotLevel: Longword;
   166     BaseRate, BestRate, Rate: integer;
   168     BaseRate, BestRate, Rate: integer;
   167     GoInfo: TGoInfo;
   169     GoInfo: TGoInfo;
   168     CanGo: boolean;
   170     CanGo: boolean;
   169     AltMe: TGear;
   171     AltMe: TGear;
   170 begin
   172 begin
   171 Actions.Count:= 0;
   173 Actions.Count:= 0;
   172 Actions.Pos:= 0;
   174 Actions.Pos:= 0;
   173 Actions.Score:= 0;
   175 Actions.Score:= 0;
   174 Stack.Count:= 0;
   176 Stack.Count:= 0;
       
   177 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
   175 
   178 
   176 Push(0, Actions, Me^, aia_Left);
   179 Push(0, Actions, Me^, aia_Left);
   177 Push(0, Actions, Me^, aia_Right);
   180 Push(0, Actions, Me^, aia_Right);
   178 
   181 
   179 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, integer(TurnTimeLeft) - 10000)
   182 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
   180                                   else maxticks:= TurnTimeLeft;
   183                                   else maxticks:= TurnTimeLeft;
   181 
   184 
   182 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   185 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   183 BestRate:= RatePlace(Me);
   186 BestRate:= RatePlace(Me);
   184 BaseRate:= max(BestRate, 0);
   187 BaseRate:= max(BestRate, 0);
   194     while (not StopThinking) and (not PosInThinkStack(Me)) do
   197     while (not StopThinking) and (not PosInThinkStack(Me)) do
   195        begin
   198        begin
   196        CanGo:= HHGo(Me, @AltMe, GoInfo);
   199        CanGo:= HHGo(Me, @AltMe, GoInfo);
   197        inc(ticks, GoInfo.Ticks);
   200        inc(ticks, GoInfo.Ticks);
   198        if ticks > maxticks then break;
   201        if ticks > maxticks then break;
   199        if GoInfo.JumpType = jmpHJump then // hjump support
   202        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   200           if Push(ticks, Actions, AltMe, Me^.Message) then
   203           if Push(ticks, Actions, AltMe, Me^.Message) then
   201              with Stack.States[Pred(Stack.Count)] do
   204              with Stack.States[Pred(Stack.Count)] do
   202                   begin
   205                   begin
   203                   AddAction(MadeActions, aia_HJump, 0, 305);
   206                   AddAction(MadeActions, aia_HJump, 0, 305);
   204                   AddAction(MadeActions, aia_HJump, 0, 350);
   207                   AddAction(MadeActions, aia_HJump, 0, 350);
   205                   end;
   208                   end;
   206        if GoInfo.JumpType = jmpLJump then // ljump support
   209        if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
   207           if Push(ticks, Actions, AltMe, Me^.Message) then
   210           if Push(ticks, Actions, AltMe, Me^.Message) then
   208              with Stack.States[Pred(Stack.Count)] do
   211              with Stack.States[Pred(Stack.Count)] do
   209                   AddAction(MadeActions, aia_LJump, 0, 305);
   212                   AddAction(MadeActions, aia_LJump, 0, 305);
   210        if not CanGo then break;
   213        if not CanGo then break;
   211        inc(steps);
   214        inc(steps);