hedgewars/uAI.pas
changeset 144 e6084b0c9316
parent 143 3dacbd83209b
child 146 458f4f58c1b6
equal deleted inserted replaced
143:3dacbd83209b 144:e6084b0c9316
   162           end
   162           end
   163     end;
   163     end;
   164 
   164 
   165 
   165 
   166 var Actions: TActions;
   166 var Actions: TActions;
   167     ticks, maxticks, steps, BotLevel: Longword;
   167     ticks, maxticks, steps, BotLevel, tmp: Longword;
   168     BaseRate, BestRate, Rate: integer;
   168     BaseRate, BestRate, Rate: integer;
   169     GoInfo: TGoInfo;
   169     GoInfo: TGoInfo;
   170     CanGo: boolean;
   170     CanGo: boolean;
   171     AltMe: TGear;
   171     AltMe: TGear;
   172 begin
   172 begin
   174 Actions.Pos:= 0;
   174 Actions.Pos:= 0;
   175 Actions.Score:= 0;
   175 Actions.Score:= 0;
   176 Stack.Count:= 0;
   176 Stack.Count:= 0;
   177 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
   177 BotLevel:= PHedgehog(Me.Hedgehog).BotLevel;
   178 
   178 
   179 Push(0, Actions, Me^, aia_Left);
   179 tmp:= random(2) + 1;
   180 Push(0, Actions, Me^, aia_Right);
   180 Push(0, Actions, Me^, tmp);
       
   181 Push(0, Actions, Me^, tmp xor 3);
   181 
   182 
   182 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
   183 if (Me.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - 4000 * BotLevel)
   183                                   else maxticks:= TurnTimeLeft;
   184                                   else maxticks:= TurnTimeLeft;
   184 
   185 
   185 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   186 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   187 BaseRate:= max(BestRate, 0);
   188 BaseRate:= max(BestRate, 0);
   188 
   189 
   189 while (Stack.Count > 0) and not StopThinking do
   190 while (Stack.Count > 0) and not StopThinking do
   190     begin
   191     begin
   191     Pop(ticks, Actions, Me^);
   192     Pop(ticks, Actions, Me^);
       
   193 
   192     AddAction(Actions, Me.Message, aim_push, 250);
   194     AddAction(Actions, Me.Message, aim_push, 250);
   193     AddAction(Actions, aia_WaitX, round(Me.X), 0);
   195     AddAction(Actions, aia_WaitX, round(Me.X), 0);
   194     AddAction(Actions, Me.Message, aim_release, 0);
   196     AddAction(Actions, Me.Message, aim_release, 0);
   195     steps:= 0;
   197     steps:= 0;
   196 
   198 
   197     while (not StopThinking) and (not PosInThinkStack(Me)) do
   199     while (not StopThinking) and (not PosInThinkStack(Me)) do
   198        begin
   200        begin
   199        CanGo:= HHGo(Me, @AltMe, GoInfo);
   201        CanGo:= HHGo(Me, @AltMe, GoInfo);
   200        inc(ticks, GoInfo.Ticks);
   202        inc(ticks, GoInfo.Ticks);
   201        if ticks > maxticks then break;
   203        if ticks > maxticks then break;
       
   204        
   202        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   205        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   203           if Push(ticks, Actions, AltMe, Me^.Message) then
   206           if Push(ticks, Actions, AltMe, Me^.Message) then
   204              with Stack.States[Pred(Stack.Count)] do
   207              with Stack.States[Pred(Stack.Count)] do
   205                   begin
   208                   begin
   206                   AddAction(MadeActions, aia_HJump, 0, 305);
   209                   AddAction(MadeActions, aia_HJump, 0, 305);
   208                   end;
   211                   end;
   209        if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
   212        if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
   210           if Push(ticks, Actions, AltMe, Me^.Message) then
   213           if Push(ticks, Actions, AltMe, Me^.Message) then
   211              with Stack.States[Pred(Stack.Count)] do
   214              with Stack.States[Pred(Stack.Count)] do
   212                   AddAction(MadeActions, aia_LJump, 0, 305);
   215                   AddAction(MadeActions, aia_LJump, 0, 305);
       
   216 
   213        if not CanGo then break;
   217        if not CanGo then break;
   214        inc(steps);
   218        inc(steps);
   215        Actions.actions[Actions.Count - 2].Param:= round(Me.X);
   219        Actions.actions[Actions.Count - 2].Param:= round(Me.X);
   216        Rate:= RatePlace(Me);
   220        Rate:= RatePlace(Me);
   217        if Rate > BestRate then
   221        if Rate > BestRate then
   265 procedure StartThink(Me: PGear);
   269 procedure StartThink(Me: PGear);
   266 var a: TAmmoType;
   270 var a: TAmmoType;
   267 begin
   271 begin
   268 if ((Me.State and gstAttacking) <> 0) or isInMultiShoot then exit;
   272 if ((Me.State and gstAttacking) <> 0) or isInMultiShoot then exit;
   269 Me.State:= Me.State or gstHHThinking;
   273 Me.State:= Me.State or gstHHThinking;
       
   274 Me.Message:= 0;
   270 StopThinking:= false;
   275 StopThinking:= false;
   271 ThinkingHH:= Me;
   276 ThinkingHH:= Me;
   272 FillTargets;
   277 FillTargets;
   273 if Targets.Count = 0 then
   278 if Targets.Count = 0 then
   274    begin
   279    begin
   286 const StartTicks: Longword = 0;
   291 const StartTicks: Longword = 0;
   287 begin
   292 begin
   288 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
   293 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
   289      if (Gear <> nil)
   294      if (Gear <> nil)
   290         and ((Gear.State and gstHHDriven) <> 0)
   295         and ((Gear.State and gstHHDriven) <> 0)
   291         and (TurnTimeLeft < cHedgehogTurnTime - 5) then
   296         and (TurnTimeLeft < cHedgehogTurnTime - 50) then
   292         if ((Gear.State and gstHHThinking) = 0) then
   297         if ((Gear.State and gstHHThinking) = 0) then
   293            if (BestActions.Pos >= BestActions.Count) then
   298            if (BestActions.Pos >= BestActions.Count) then
   294               begin
   299               begin
   295               StartThink(Gear);
   300               StartThink(Gear);
   296               StartTicks:= GameTicks
   301               StartTicks:= GameTicks