Fixed weird bots behavior
authorunc0rr
Wed, 11 Oct 2006 19:07:38 +0000
changeset 194 88652abdce9a
parent 193 56885ea29202
child 195 edae828322a0
Fixed weird bots behavior
hedgewars/uAI.pas
hedgewars/uAIActions.pas
--- a/hedgewars/uAI.pas	Tue Oct 10 18:03:48 2006 +0000
+++ b/hedgewars/uAI.pas	Wed Oct 11 19:07:38 2006 +0000
@@ -60,7 +60,7 @@
               begin
               BestActions:= Actions;
               inc(BestActions.Score, Score);
-              
+
               AddAction(BestActions, aia_Weapon, Longword(a), 500);
               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
@@ -105,8 +105,7 @@
 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
                                   else maxticks:= TurnTimeLeft;
 
-
-BaseRate:= max(RatePlace(Me), 0);
+BaseRate:= RatePlace(Me);
 
 repeat
     if not Pop(ticks, Actions, Me^) then
@@ -114,27 +113,20 @@
        isThinking:= false;
        exit
        end;
-    if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
 
-    AddAction(Actions, Me.Message, aim_push, 250);
+    AddAction(Actions, Me.Message, aim_push, 10);
     if (Me.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, round(Me.X), 0)
                                      else AddAction(Actions, aia_WaitXR, round(Me.X), 0);
     AddAction(Actions, Me.Message, aim_release, 0);
     steps:= 0;
+    if ((Me.State and gstAttacked) = 0) then TestAmmos(Actions, Me);
 
     while not PosInThinkStack(Me) do
        begin
-       if SDL_GetTicks - AIThinkStart > 3 then
-          begin
-          dec(Actions.Count, 3);
-          Push(ticks, Actions, Me^, Me^.Message);
-          exit
-          end;
-
        CanGo:= HHGo(Me, @AltMe, GoInfo);
        inc(ticks, GoInfo.Ticks);
        if ticks > maxticks then break;
-       
+
        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
           if Push(ticks, Actions, AltMe, Me^.Message) then
              with ThinkStack.States[Pred(ThinkStack.Count)] do
@@ -163,7 +155,16 @@
           Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
 
        if ((Me.State and gstAttacked) = 0)
-           and ((steps mod 4) = 0) then TestAmmos(Actions, Me);
+           and ((steps mod 4) = 0) then
+           begin
+           if SDL_GetTicks - AIThinkStart > 3 then
+              begin
+              dec(Actions.Count, 3);
+              Push(ticks, Actions, Me^, Me^.Message);
+              exit
+              end;
+           TestAmmos(Actions, Me)
+           end
        end;
 until false
 end;
@@ -185,6 +186,7 @@
             BestActions.Count:= 0;
             AddAction(BestActions, aia_Skip, 0, 250);
             end;
+         Me.State:= Me.State and not gstHHThinking
          end
       end else
 else begin
@@ -221,11 +223,9 @@
 BestActions.Count:= 0;
 BestActions.Pos:= 0;
 BestActions.Score:= 0;
-AddAction(BestActions, aia_Wait, GameTicks + 1500{ + Longword(random(1000))}, 1500);
 tmp:= random(2) + 1;
 Push(0, BestActions, Me^, tmp);
 Push(0, BestActions, Me^, tmp xor 3);
-BestActions.Count:= 0;
 BestActions.Score:= Low(integer);
 
 Think(Me)
--- a/hedgewars/uAIActions.pas	Tue Oct 10 18:03:48 2006 +0000
+++ b/hedgewars/uAIActions.pas	Wed Oct 11 19:07:38 2006 +0000
@@ -115,6 +115,7 @@
 procedure ProcessAction(var Actions: TActions; Me: PGear);
 var s: shortstring;
 begin
+repeat
 if Actions.Pos >= Actions.Count then exit;
 with Actions.actions[Actions.Pos] do
      begin
@@ -153,9 +154,6 @@
             aia_HJump: ParseCommand('hjump');
             aia_LJump: ParseCommand('ljump');
              aia_Skip: ParseCommand('skip');
-             aia_Wait: if Param > GameTicks then exit
-                          else with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
-                                    Gear.State:= Gear.State and not gstHHThinking
              end else
         begin
         s:= ActionIdToStr[Action];
@@ -170,7 +168,8 @@
      end;
 inc(Actions.Pos);
 if Actions.Pos <= Actions.Count then
-   inc(Actions.actions[Actions.Pos].Time, GameTicks)
+   inc(Actions.actions[Actions.Pos].Time, GameTicks);
+until false
 end;
 
 end.