hedgewars/uAI.pas
branch0.9.19
changeset 9081 7f04ad2cda54
parent 9003 896c6b21c87f
child 9080 9b42757d7e71
equal deleted inserted replaced
8932:e095e3023682 9081:7f04ad2cda54
   124             and ((not rareChecks) or ((AmmoTests[a].flags and amtest_Rare) = 0))
   124             and ((not rareChecks) or ((AmmoTests[a].flags and amtest_Rare) = 0))
   125             and ((i = 0) or ((AmmoTests[a].flags and amtest_NoTarget) = 0))
   125             and ((i = 0) or ((AmmoTests[a].flags and amtest_NoTarget) = 0))
   126             then
   126             then
   127             begin
   127             begin
   128 {$HINTS OFF}
   128 {$HINTS OFF}
   129             Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap);
   129             Score:= AmmoTests[a].proc(Me, Targets.ar[i], BotLevel, ap);
   130 {$HINTS ON}
   130 {$HINTS ON}
   131             if Actions.Score + Score > BestActions.Score then
   131             if Actions.Score + Score > BestActions.Score then
   132                 if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then
   132                 if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel - 1) * 2048) then
   133                     begin
   133                     begin
   134                     BestActions:= Actions;
   134                     BestActions:= Actions;
   135                     inc(BestActions.Score, Score);
   135                     inc(BestActions.Score, Score);
   136                     BestActions.isWalkingToABetterPlace:= false;
   136                     BestActions.isWalkingToABetterPlace:= false;
   137 
   137 
   364     switchCount: LongInt;
   364     switchCount: LongInt;
   365     StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
   365     StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
   366     switchImmediatelyAvailable: boolean;
   366     switchImmediatelyAvailable: boolean;
   367     Actions: TActions;
   367     Actions: TActions;
   368 begin
   368 begin
   369 AddFileLog('Think thread started');
       
   370 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   369 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   371 StartTicks:= GameTicks;
   370 StartTicks:= GameTicks;
   372 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   371 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   373 itHedgehog:= currHedgehogIndex;
   372 itHedgehog:= currHedgehogIndex;
   374 switchesNum:= 0;
   373 switchesNum:= 0;
   376 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   375 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   377 if Me^.Hedgehog^.BotLevel <> 5 then
   376 if Me^.Hedgehog^.BotLevel <> 5 then
   378     switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch)
   377     switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch)
   379 else switchCount:= 0;
   378 else switchCount:= 0;
   380 
   379 
   381 if (Me^.State and gstAttacked) = 0 then
   380 if ((Me^.State and gstAttacked) = 0) or isInMultiShoot then
   382     if Targets.Count > 0 then
   381     if Targets.Count > 0 then
   383         begin
   382         begin
   384         // iterate over current team hedgehogs
   383         // iterate over current team hedgehogs
   385         repeat
   384         repeat
   386             WalkMe:= CurrentTeam^.Hedgehogs[itHedgehog].Gear^;
   385             WalkMe:= CurrentTeam^.Hedgehogs[itHedgehog].Gear^;
   425 
   424 
   426         end else SDL_Delay(100)
   425         end else SDL_Delay(100)
   427 else
   426 else
   428     begin
   427     begin
   429     BackMe:= Me^;
   428     BackMe:= Me^;
   430     while (not StopThinking) and (BestActions.Count = 0) do
   429     i:= 12;
       
   430     while (not StopThinking) and (BestActions.Count = 0) and (i > 0) do
   431         begin
   431         begin
   432 (*
   432 (*
   433         // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
   433         // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
   434         if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
   434         if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
   435             AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
   435             AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
   438         WalkMe:= BackMe;
   438         WalkMe:= BackMe;
   439         Actions.Count:= 0;
   439         Actions.Count:= 0;
   440         Actions.Pos:= 0;
   440         Actions.Pos:= 0;
   441         Actions.Score:= 0;
   441         Actions.Score:= 0;
   442         Walk(@WalkMe, Actions);
   442         Walk(@WalkMe, Actions);
       
   443         dec(i);
   443         if not StopThinking then
   444         if not StopThinking then
   444             SDL_Delay(100)
   445             SDL_Delay(100)
   445         end
   446         end
   446     end;
   447     end;
   447 
   448 
   476     begin
   477     begin
   477     OutError('AI: no targets!?', false);
   478     OutError('AI: no targets!?', false);
   478     exit
   479     exit
   479     end;
   480     end;
   480 
   481 
   481 FillBonuses((Me^.State and gstAttacked) <> 0);
   482 FillBonuses(((Me^.State and gstAttacked) <> 0) and (not isInMultiShoot));
   482 
   483 
   483 SDL_LockMutex(ThreadLock);
   484 SDL_LockMutex(ThreadLock);
   484 ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL13}, 'think'{$ENDIF}, Me);
   485 ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL13}, 'think'{$ENDIF}, Me);
   485 SDL_UnlockMutex(ThreadLock);
   486 SDL_UnlockMutex(ThreadLock);
   486 end;
   487 end;
   487 
   488 
   488 //var scoreShown: boolean = false;
   489 {$IFDEF DEBUGAI}
       
   490 var scoreShown: boolean = false;
       
   491 {$ENDIF}
   489 
   492 
   490 procedure ProcessBot;
   493 procedure ProcessBot;
   491 const cStopThinkTime = 40;
   494 const cStopThinkTime = 40;
   492 begin
   495 begin
   493 with CurrentHedgehog^ do
   496 with CurrentHedgehog^ do
   505                     end;
   508                     end;
   506 
   509 
   507                 if Gear^.Message <> 0 then
   510                 if Gear^.Message <> 0 then
   508                     exit;
   511                     exit;
   509 
   512 
   510                 //scoreShown:= false;
   513 {$IFDEF DEBUGAI}
       
   514                 scoreShown:= false;
       
   515 {$ENDIF}
   511                 StartThink(Gear);
   516                 StartThink(Gear);
   512                 StartTicks:= GameTicks
   517                 StartTicks:= GameTicks
   513 
   518 
   514             end else
   519             end else
   515                 begin
   520                 begin
   516                 {if not scoreShown then
   521 {$IFDEF DEBUGAI}
       
   522                 if not scoreShown then
   517                     begin
   523                     begin
   518                     if BestActions.Score > 0 then ParseCommand('/say Expected score = ' + inttostr(BestActions.Score div 1024), true);
   524                     if BestActions.Score > 0 then ParseCommand('/say Expected score = ' + inttostr(BestActions.Score div 1024), true);
   519                     scoreShown:= true
   525                     scoreShown:= true
   520                     end;}
   526                     end;
       
   527 {$ENDIF}
   521                 ProcessAction(BestActions, Gear)
   528                 ProcessAction(BestActions, Gear)
   522                 end
   529                 end
   523         else if ((GameTicks - StartTicks) > cMaxAIThinkTime)
   530         else if ((GameTicks - StartTicks) > cMaxAIThinkTime)
   524             or (TurnTimeLeft <= cStopThinkTime) then
   531             or (TurnTimeLeft <= cStopThinkTime) then
   525                 StopThinking:= true
   532                 StopThinking:= true