hedgewars/uAI.pas
changeset 194 88652abdce9a
parent 193 56885ea29202
child 196 993cf173218b
equal deleted inserted replaced
193:56885ea29202 194:88652abdce9a
    58            Score:= AmmoTests[a](Me, Targets.ar[i].Point, BotLevel, Time, Angle, Power, ExplX, ExplY, ExplR);
    58            Score:= AmmoTests[a](Me, Targets.ar[i].Point, BotLevel, Time, Angle, Power, ExplX, ExplY, ExplR);
    59            if Actions.Score + Score > BestActions.Score then
    59            if Actions.Score + Score > BestActions.Score then
    60               begin
    60               begin
    61               BestActions:= Actions;
    61               BestActions:= Actions;
    62               inc(BestActions.Score, Score);
    62               inc(BestActions.Score, Score);
    63               
    63 
    64               AddAction(BestActions, aia_Weapon, Longword(a), 500);
    64               AddAction(BestActions, aia_Weapon, Longword(a), 500);
    65               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
    65               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
    66               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
    66               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
    67               else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
    67               else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
    68               if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
    68               if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
   103 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
   103 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
   104 
   104 
   105 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
   105 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
   106                                   else maxticks:= TurnTimeLeft;
   106                                   else maxticks:= TurnTimeLeft;
   107 
   107 
   108 
   108 BaseRate:= RatePlace(Me);
   109 BaseRate:= max(RatePlace(Me), 0);
       
   110 
   109 
   111 repeat
   110 repeat
   112     if not Pop(ticks, Actions, Me^) then
   111     if not Pop(ticks, Actions, Me^) then
   113        begin
   112        begin
   114        isThinking:= false;
   113        isThinking:= false;
   115        exit
   114        exit
   116        end;
   115        end;
   117     if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
   116 
   118 
   117     AddAction(Actions, Me.Message, aim_push, 10);
   119     AddAction(Actions, Me.Message, aim_push, 250);
       
   120     if (Me.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, round(Me.X), 0)
   118     if (Me.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, round(Me.X), 0)
   121                                      else AddAction(Actions, aia_WaitXR, round(Me.X), 0);
   119                                      else AddAction(Actions, aia_WaitXR, round(Me.X), 0);
   122     AddAction(Actions, Me.Message, aim_release, 0);
   120     AddAction(Actions, Me.Message, aim_release, 0);
   123     steps:= 0;
   121     steps:= 0;
       
   122     if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
   124 
   123 
   125     while not PosInThinkStack(Me) do
   124     while not PosInThinkStack(Me) do
   126        begin
   125        begin
   127        if SDL_GetTicks - AIThinkStart > 3 then
       
   128           begin
       
   129           dec(Actions.Count, 3);
       
   130           Push(ticks, Actions, Me^, Me^.Message);
       
   131           exit
       
   132           end;
       
   133 
       
   134        CanGo:= HHGo(Me, @AltMe, GoInfo);
   126        CanGo:= HHGo(Me, @AltMe, GoInfo);
   135        inc(ticks, GoInfo.Ticks);
   127        inc(ticks, GoInfo.Ticks);
   136        if ticks > maxticks then break;
   128        if ticks > maxticks then break;
   137        
   129 
   138        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   130        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   139           if Push(ticks, Actions, AltMe, Me^.Message) then
   131           if Push(ticks, Actions, AltMe, Me^.Message) then
   140              with ThinkStack.States[Pred(ThinkStack.Count)] do
   132              with ThinkStack.States[Pred(ThinkStack.Count)] do
   141                   begin
   133                   begin
   142                   AddAction(MadeActions, aia_HJump, 0, 305);
   134                   AddAction(MadeActions, aia_HJump, 0, 305);
   161        else if Rate < BaseRate then break;
   153        else if Rate < BaseRate then break;
   162        if GoInfo.FallPix >= FallPixForBranching then
   154        if GoInfo.FallPix >= FallPixForBranching then
   163           Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
   155           Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
   164 
   156 
   165        if ((Me.State and gstAttacked) = 0)
   157        if ((Me.State and gstAttacked) = 0)
   166            and ((steps mod 4) = 0) then TestAmmos(Actions, Me);
   158            and ((steps mod 4) = 0) then
       
   159            begin
       
   160            if SDL_GetTicks - AIThinkStart > 3 then
       
   161               begin
       
   162               dec(Actions.Count, 3);
       
   163               Push(ticks, Actions, Me^, Me^.Message);
       
   164               exit
       
   165               end;
       
   166            TestAmmos(Actions, Me)
       
   167            end
   167        end;
   168        end;
   168 until false
   169 until false
   169 end;
   170 end;
   170 
   171 
   171 procedure Think(Me: PGear);
   172 procedure Think(Me: PGear);
   183          if BestActions.Score < -1023 then
   184          if BestActions.Score < -1023 then
   184             begin
   185             begin
   185             BestActions.Count:= 0;
   186             BestActions.Count:= 0;
   186             AddAction(BestActions, aia_Skip, 0, 250);
   187             AddAction(BestActions, aia_Skip, 0, 250);
   187             end;
   188             end;
       
   189          Me.State:= Me.State and not gstHHThinking
   188          end
   190          end
   189       end else
   191       end else
   190 else begin
   192 else begin
   191       FillBonuses(true);
   193       FillBonuses(true);
   192       Walk(@WalkMe);
   194       Walk(@WalkMe);
   219     CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me.Hedgehog), a);
   221     CanUseAmmo[a]:= Assigned(AmmoTests[a]) and HHHasAmmo(PHedgehog(Me.Hedgehog), a);
   220 
   222 
   221 BestActions.Count:= 0;
   223 BestActions.Count:= 0;
   222 BestActions.Pos:= 0;
   224 BestActions.Pos:= 0;
   223 BestActions.Score:= 0;
   225 BestActions.Score:= 0;
   224 AddAction(BestActions, aia_Wait, GameTicks + 1500{ + Longword(random(1000))}, 1500);
       
   225 tmp:= random(2) + 1;
   226 tmp:= random(2) + 1;
   226 Push(0, BestActions, Me^, tmp);
   227 Push(0, BestActions, Me^, tmp);
   227 Push(0, BestActions, Me^, tmp xor 3);
   228 Push(0, BestActions, Me^, tmp xor 3);
   228 BestActions.Count:= 0;
       
   229 BestActions.Score:= Low(integer);
   229 BestActions.Score:= Low(integer);
   230 
   230 
   231 Think(Me)
   231 Think(Me)
   232 end;
   232 end;
   233 
   233