hedgewars/uAI.pas
branchhedgeroid
changeset 5516 8710987d3484
parent 5504 96d735b83d43
child 5611 099868c5bba5
equal deleted inserted replaced
5514:294c92eea729 5516:8710987d3484
    64 var BotLevel: Byte;
    64 var BotLevel: Byte;
    65     ap: TAttackParams;
    65     ap: TAttackParams;
    66     Score, i: LongInt;
    66     Score, i: LongInt;
    67     a, aa: TAmmoType;
    67     a, aa: TAmmoType;
    68 begin
    68 begin
    69 WriteToConsole('testing ammo');
       
    70 BotLevel:= Me^.Hedgehog^.BotLevel;
    69 BotLevel:= Me^.Hedgehog^.BotLevel;
    71 
    70 
    72 for i:= 0 to Pred(Targets.Count) do
    71 for i:= 0 to Pred(Targets.Count) do
    73     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
    72     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
    74        begin
    73        begin
    75        with CurrentHedgehog^ do
    74        with CurrentHedgehog^ do
    76             a:= CurAmmoType;
    75             a:= CurAmmoType;
    77        aa:= a;
    76        aa:= a;
    78 WriteToConsole('start walking');
       
    79 SDL_delay(0);
    77 SDL_delay(0);
    80 //       ThreadSwitch();
    78 //       ThreadSwitch();
    81 WriteToConsole('start walking');
       
    82        
    79        
    83        repeat
    80        repeat
    84         if (CanUseAmmo[a]) and
    81         if (CanUseAmmo[a]) and
    85            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
    82            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
    86            begin
    83            begin
   205 BotLevel:= Me^.Hedgehog^.BotLevel;
   202 BotLevel:= Me^.Hedgehog^.BotLevel;
   206 
   203 
   207 tmp:= random(2) + 1;
   204 tmp:= random(2) + 1;
   208 Push(0, Actions, Me^, tmp);
   205 Push(0, Actions, Me^, tmp);
   209 Push(0, Actions, Me^, tmp xor 3);
   206 Push(0, Actions, Me^, tmp xor 3);
   210 WriteToConsole('start walking');
       
   211 
   207 
   212 if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
   208 if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
   213                                    else maxticks:= TurnTimeLeft;
   209                                    else maxticks:= TurnTimeLeft;
   214 WriteToConsole('start walking');
       
   215 
   210 
   216 if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
   211 if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
   217 WriteToConsole('start walking');
       
   218 BestRate:= RatePlace(Me);
   212 BestRate:= RatePlace(Me);
   219 BaseRate:= Max(BestRate, 0);
   213 BaseRate:= Max(BestRate, 0);
   220 WriteToConsole('start walking');
       
   221 
   214 
   222 if (Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
   215 if (Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
   223     AddAction(Actions, aia_Weapon, Longword(amNothing), 100 + random(200), 0, 0);
   216     AddAction(Actions, aia_Weapon, Longword(amNothing), 100 + random(200), 0, 0);
   224 WriteToConsole('start walking');
       
   225 
   217 
   226 while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do
   218 while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do
   227     begin
   219     begin
   228 WriteToConsole('start walking');
       
   229     Pop(ticks, Actions, Me^);
   220     Pop(ticks, Actions, Me^);
   230 
   221 
   231     AddAction(Actions, Me^.Message, aim_push, 250, 0, 0);
   222     AddAction(Actions, Me^.Message, aim_push, 250, 0, 0);
   232     if (Me^.Message and gmLeft) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
   223     if (Me^.Message and gmLeft) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
   233                                       else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
   224                                       else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
   238 {$HINTS OFF}
   229 {$HINTS OFF}
   239        CanGo:= HHGo(Me, @AltMe, GoInfo);
   230        CanGo:= HHGo(Me, @AltMe, GoInfo);
   240 {$HINTS ON}
   231 {$HINTS ON}
   241        inc(ticks, GoInfo.Ticks);
   232        inc(ticks, GoInfo.Ticks);
   242        if ticks > maxticks then break;
   233        if ticks > maxticks then break;
   243 WriteToConsole('start walking');
       
   244 
   234 
   245        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   235        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
   246           if Push(ticks, Actions, AltMe, Me^.Message) then
   236           if Push(ticks, Actions, AltMe, Me^.Message) then
   247              with Stack.States[Pred(Stack.Count)] do
   237              with Stack.States[Pred(Stack.Count)] do
   248                   begin
   238                   begin
   260 
   250 
   261        if not CanGo then break;
   251        if not CanGo then break;
   262        inc(steps);
   252        inc(steps);
   263        Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
   253        Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
   264        Rate:= RatePlace(Me);
   254        Rate:= RatePlace(Me);
   265 WriteToConsole('start walking');
       
   266        if Rate > BestRate then
   255        if Rate > BestRate then
   267           begin
   256           begin
   268           BestActions:= Actions;
   257           BestActions:= Actions;
   269           BestRate:= Rate;
   258           BestRate:= Rate;
   270           Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
   259           Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
   271           end
   260           end
   272        else if Rate < BestRate then break;
   261        else if Rate < BestRate then break;
   273 WriteToConsole('start walking');
       
   274        if ((Me^.State and gstAttacked) = 0)
   262        if ((Me^.State and gstAttacked) = 0)
   275            and ((steps mod 4) = 0) then TestAmmos(Actions, Me, true);
   263            and ((steps mod 4) = 0) then TestAmmos(Actions, Me, true);
   276 WriteToConsole('start walking');
       
   277        if GoInfo.FallPix >= FallPixForBranching then
   264        if GoInfo.FallPix >= FallPixForBranching then
   278           Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
   265           Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
   279        end;
   266        end;
   280 
   267 
   281     if BestRate > BaseRate then exit
   268     if BestRate > BaseRate then exit
   284 
   271 
   285 function Think(Me: Pointer): ptrint;
   272 function Think(Me: Pointer): ptrint;
   286 var BackMe, WalkMe: TGear;
   273 var BackMe, WalkMe: TGear;
   287     StartTicks: Longword;
   274     StartTicks: Longword;
   288 begin
   275 begin
   289 WriteToConsole('starting to think');
       
   290 InterlockedIncrement(hasThread);
   276 InterlockedIncrement(hasThread);
   291 WriteToConsole('bla');
       
   292 StartTicks:= GameTicks;
   277 StartTicks:= GameTicks;
   293 WriteToConsole('bla');
       
   294 BackMe:= PGear(Me)^;
   278 BackMe:= PGear(Me)^;
   295 WriteToConsole('bla');
       
   296 
   279 
   297 if (PGear(Me)^.State and gstAttacked) = 0 then
   280 if (PGear(Me)^.State and gstAttacked) = 0 then
   298    if Targets.Count > 0 then
   281    if Targets.Count > 0 then
   299       begin
   282       begin
   300 WriteToConsole('blaaa');
       
   301 
   283 
   302       WalkMe:= BackMe;
   284       WalkMe:= BackMe;
   303 WriteToConsole('blaa');
       
   304       Walk(@WalkMe);
   285       Walk(@WalkMe);
   305 WriteToConsole('blaa');
       
   306       if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(1000);
   286       if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(1000);
   307 	 WriteToConsole('bla');
       
   308 
   287 
   309       if BestActions.Score < -1023 then
   288       if BestActions.Score < -1023 then
   310          begin
   289          begin
   311 	 WriteToConsole('bla');
       
   312          BestActions.Count:= 0;
   290          BestActions.Count:= 0;
   313          AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   291          AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   314 	 WriteToConsole('bla');
       
   315          end;
   292          end;
   316       end else
   293       end else
   317 else begin
   294 else begin
   318       while (not StopThinking) and (BestActions.Count = 0) do
   295       while (not StopThinking) and (BestActions.Count = 0) do
   319             begin
   296             begin
   320 WriteToConsole('bla loop');
       
   321             FillBonuses(true);
   297             FillBonuses(true);
   322             WalkMe:= BackMe;
   298             WalkMe:= BackMe;
   323             Walk(@WalkMe);
   299             Walk(@WalkMe);
   324             if not StopThinking then SDL_Delay(100)
   300             if not StopThinking then SDL_Delay(100)
   325             end
   301             end
   326       end;
   302       end;
   327 PGear(Me)^.State:= PGear(Me)^.State and not gstHHThinking;
   303 PGear(Me)^.State:= PGear(Me)^.State and not gstHHThinking;
   328 Think:= 0;
   304 Think:= 0;
   329 WriteToConsole('bla');
       
   330 
   305 
   331 InterlockedDecrement(hasThread);
   306 InterlockedDecrement(hasThread);
   332 WriteToConsole('bla end');
       
   333 
   307 
   334 end;
   308 end;
   335 
   309 
   336 procedure StartThink(Me: PGear);
   310 procedure StartThink(Me: PGear);
   337 var a: TAmmoType;
   311 var a: TAmmoType;