hedgewars/uAI.pas
changeset 6395 bb04d7a9f7e2
parent 6393 701eb3f3556a
child 6415 af2047bb4f70
equal deleted inserted replaced
6394:f0a9042e7387 6395:bb04d7a9f7e2
   130            if Actions.Score + Score > BestActions.Score then
   130            if Actions.Score + Score > BestActions.Score then
   131             if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then
   131             if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then
   132               begin
   132               begin
   133               BestActions:= Actions;
   133               BestActions:= Actions;
   134               inc(BestActions.Score, Score);
   134               inc(BestActions.Score, Score);
       
   135               BestActions.isWalkingToABetterPlace:= false;
   135 
   136 
   136               if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
   137               if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
   137               else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
   138               else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
   138 
   139 
   139               AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0);
   140               AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0);
   243        Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
   244        Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
   244        Rate:= RatePlace(Me);
   245        Rate:= RatePlace(Me);
   245        if Rate > BestRate then
   246        if Rate > BestRate then
   246           begin
   247           begin
   247           BestActions:= Actions;
   248           BestActions:= Actions;
       
   249           BestActions.isWalkingToABetterPlace:= true;
   248           BestRate:= Rate;
   250           BestRate:= Rate;
   249           Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
   251           Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
   250           end
   252           end
   251        else if Rate < BestRate then break;
   253        else if Rate < BestRate then break;
   252        if ((Me^.State and gstAttacked) = 0)
   254        if ((Me^.State and gstAttacked) = 0)
   305             until (itHedgehog = currHedgehogIndex) or (CurrentTeam^.Hedgehogs[itHedgehog].Gear <> nil);
   307             until (itHedgehog = currHedgehogIndex) or (CurrentTeam^.Hedgehogs[itHedgehog].Gear <> nil);
   306 
   308 
   307             inc(switchesNum);
   309             inc(switchesNum);
   308         until (not (switchImmediatelyAvailable or switchAvailable))
   310         until (not (switchImmediatelyAvailable or switchAvailable))
   309             or StopThinking 
   311             or StopThinking 
   310             or (itHedgehog = currHedgehogIndex);
   312             or (itHedgehog = currHedgehogIndex)
       
   313             or BestActions.isWalkingToABetterPlace;
   311 
   314 
   312         if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000);
   315         if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000);
   313 
   316 
   314         if BestActions.Score < -1023 then
   317         if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
   315             begin
   318             begin
   316             BestActions.Count:= 0;
   319             BestActions.Count:= 0;
   317             AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   320             AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   318             end;
   321             end;
   319 
   322 
   347 Me^.Message:= 0;
   350 Me^.Message:= 0;
   348 
   351 
   349 BestActions.Count:= 0;
   352 BestActions.Count:= 0;
   350 BestActions.Pos:= 0;
   353 BestActions.Pos:= 0;
   351 BestActions.Score:= Low(LongInt);
   354 BestActions.Score:= Low(LongInt);
       
   355 BestActions.isWalkingToABetterPlace:= false;
   352 
   356 
   353 StopThinking:= false;
   357 StopThinking:= false;
   354 ThinkingHH:= Me;
   358 ThinkingHH:= Me;
   355 
   359 
   356 FillTargets;
   360 FillTargets;