# HG changeset patch # User unc0rr # Date 1337945748 -14400 # Node ID baf3351646f4ea90ad463f46dc441c59c5ad7219 # Parent fcab1fd02bc63d5b15b424dbe1205095d1fe316f - Fix some AI stupidness factors - Slight optimizations and formatting diff -r fcab1fd02bc6 -r baf3351646f4 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Sun May 27 23:42:43 2012 +0400 +++ b/hedgewars/uAI.pas Fri May 25 15:35:48 2012 +0400 @@ -142,41 +142,41 @@ inc(BestActions.Score, Score); BestActions.isWalkingToABetterPlace:= false; - if (ap.Angle > 0) then - AddAction(BestActions, aia_LookRight, 0, 200, 0, 0) - else if (ap.Angle < 0) then - AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0); + AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); - AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); - - if (ap.Time <> 0) then - AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); - if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then - begin - ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); - if ap.Angle > 0 then + if (ap.Angle > 0) then + AddAction(BestActions, aia_LookRight, 0, 200, 0, 0) + else if (ap.Angle < 0) then + AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0); + + if (ap.Time <> 0) then + AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); + if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then begin - AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) - end - else if ap.Angle < 0 then + ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); + if ap.Angle > 0 then + begin + AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); + AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) + end + else if ap.Angle < 0 then + begin + AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); + AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) + end + end; + if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then begin - AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) - end - end; - if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then - begin - AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) - end; - if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then - begin - AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); - AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); - end; - if ap.ExplR > 0 then - AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); - end + AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) + end; + if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then + begin + AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); + AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); + end; + if ap.ExplR > 0 then + AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); + end end; if a = High(TAmmoType) then a:= Low(TAmmoType) @@ -205,10 +205,6 @@ BotLevel:= Me^.Hedgehog^.BotLevel; -tmp:= random(2) + 1; -Push(0, Actions, Me^, tmp); -Push(0, Actions, Me^, tmp xor 3); - if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel)) else @@ -221,8 +217,12 @@ BaseRate:= Max(BestRate, 0); if (Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0 then - AddAction(Actions, aia_Weapon, Longword(amNothing), 100 + random(200), 0, 0); + AddAction(Actions, aia_Weapon, Longword(amSkip), 100 + random(200), 0, 0); +tmp:= random(2) + 1; +Push(0, Actions, Me^, tmp); +Push(0, Actions, Me^, tmp xor 3); + while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do begin Pop(ticks, Actions, Me^); diff -r fcab1fd02bc6 -r baf3351646f4 hedgewars/uAIActions.pas --- a/hedgewars/uAIActions.pas Sun May 27 23:42:43 2012 +0400 +++ b/hedgewars/uAIActions.pas Fri May 25 15:35:48 2012 +0400 @@ -176,7 +176,8 @@ exit end else - begin CheckHang(Me); + begin + CheckHang(Me); exit end; @@ -194,7 +195,8 @@ exit end else - begin CheckHang(Me); + begin + CheckHang(Me); exit end; aia_LookLeft: diff -r fcab1fd02bc6 -r baf3351646f4 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Sun May 27 23:42:43 2012 +0400 +++ b/hedgewars/uAIAmmoTests.pas Fri May 25 15:35:48 2012 +0400 @@ -364,7 +364,7 @@ Vx:= ((Targ.X+10) - meX) / (TestTime + tDelta) else Vx:= ((Targ.X-10) - meX) / (TestTime + tDelta); - Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-150) - meY) / (TestTime + tDelta); + Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-50) - meY) / (TestTime + tDelta); r:= sqr(Vx)+sqr(Vy); if not (r > 1) then begin @@ -388,7 +388,7 @@ if valueResult < Score then begin ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level)); - ap.Power:= trunc(sqrt(r) * cMaxPower * 0.9) + AIrndSign(random(Level) * 15); + ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15); ap.Time:= TestTime; ap.ExplR:= 90; ap.ExplX:= EX; @@ -416,7 +416,7 @@ repeat inc(TestTime, 1000); Vx:= (Targ.X - meX) / (TestTime + tDelta); - Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-200) - meY) / (TestTime + tDelta); + Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-50) - meY) / (TestTime + tDelta); r:= sqr(Vx)+sqr(Vy); if not (r > 1) then begin @@ -424,30 +424,31 @@ y:= meY; dY:= -Vy; t:= TestTime; - repeat - x:= x + Vx; - y:= y + dY; - dY:= dY + cGravityf; - dec(t) - until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t = 0); - EX:= trunc(x); - EY:= trunc(y); - if t < 50 then - Score:= RateExplosion(Me, EX, EY, 381) - else - Score:= BadTurn; + repeat + x:= x + Vx; + y:= y + dY; + dY:= dY + cGravityf; + dec(t) + until TestCollExcludingMe(Me, trunc(x), trunc(y), 7) or (t = 0); - if valueResult < Score then - begin - ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level)); - ap.Power:= trunc(sqrt(r) * cMaxPower * 0.9) + AIrndSign(random(Level) * 15); - ap.Time:= TestTime; - ap.ExplR:= 300; - ap.ExplX:= EX; - ap.ExplY:= EY; - valueResult:= Score - end; - end + EX:= trunc(x); + EY:= trunc(y); + if t < 50 then + Score:= RateExplosion(Me, EX, EY, 200) + RateExplosion(Me, EX, EY + 120, 200) + else + Score:= BadTurn; + + if valueResult < Score then + begin + ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level)); + ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15); + ap.Time:= TestTime; + ap.ExplR:= 300; + ap.ExplX:= EX; + ap.ExplY:= EY; + valueResult:= Score + end; + end until (TestTime = 4000); TestWatermelon:= valueResult end; @@ -457,15 +458,15 @@ var A, B, D, T: real; C: LongInt; begin - A:= sqr(cGravityf) * 0.25; + A:= sqr(cGravityf); B:= - cGravityf * (TY - MY) - 1; C:= sqr(TY - MY) + sqr(TX - MX); - D:= sqr(B) - (A * C * 4); + D:= sqr(B) - A * C; if D >= 0 then begin - D:= ( - B + sqrt(D)) * 0.5 / A; + D:= sqrt(D) - B; if D >= 0 then - T:= sqrt(D) + T:= sqrt(D * 2 / A) else T:= 0; Solve:= trunc(T) @@ -772,6 +773,7 @@ if (Level > 3) then exit(BadTurn); +ap.Angle:= 0; ap.AttackPutX:= Targ.X; ap.AttackPutY:= Targ.Y;