Various tweaks to recent AI change
authorunc0rr
Thu, 08 Nov 2012 17:18:49 +0400
changeset 8013 5cbf6e4361f4
parent 8011 ffd5eba8f7c2
child 8014 851f65004c33
Various tweaks to recent AI change
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIAmmoTests.pas	Wed Nov 07 23:04:29 2012 -0500
+++ b/hedgewars/uAIAmmoTests.pas	Thu Nov 08 17:18:49 2012 +0400
@@ -121,8 +121,6 @@
             (proc: nil;              flags: 0)  // amKnife
             );
 
-const BadTurn = Low(LongInt) div 4;
-
 implementation
 uses uAIMisc, uVariables, uUtils, uGearsHandlers;
 
@@ -149,7 +147,7 @@
 repeat
     rTime:= rTime + 300 + Level * 50 + random(300);
     Vx:= - windSpeed * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime;
+    Vy:= cGravityf * rTime * 0.5 - (Targ.Y + 1 - mY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
     if not (r > 1) then
         begin
@@ -173,7 +171,7 @@
             value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
         else value:= RateExplosion(Me, EX, EY, 101);
         if value = 0 then
-            value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
+            value:= 1024 - Metric(Targ.X, Targ.Y, EX, EY) div 64;
         if valueResult <= value then
             begin
             ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
@@ -229,8 +227,9 @@
         EY:= trunc(y);
 
         value:= RateShove(trunc(x), trunc(y), 5, 1, trunc((abs(dX)+abs(dY))*20), -dX, -dY, afTrackFall);
-        if value = 0 then
-            value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
+        // LOL copypasta: this is score for digging with... snowball
+        //if value = 0 then
+        //    value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
 
         if valueResult <= value then
             begin
@@ -337,7 +336,7 @@
     else 
         Score:= BadTurn;
 
-    if valueResult < Score then
+    if (valueResult < Score) and (Score > 0) then
         begin
         ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
         ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
@@ -582,7 +581,7 @@
         valueResult:= RateShotgun(Me, vX, vY, rx, ry);
      
         if valueResult = 0 then 
-            valueResult:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
+            valueResult:= 1024 - Metric(Targ.X, Targ.Y, rx, ry) div 64
         else 
             dec(valueResult, Level * 4000);
         // 27/20 is reuse bonus
--- a/hedgewars/uAIMisc.pas	Wed Nov 07 23:04:29 2012 -0500
+++ b/hedgewars/uAIMisc.pas	Thu Nov 08 17:18:49 2012 +0400
@@ -28,11 +28,12 @@
       afErasesLand = $00000002;
       afSetSkip    = $00000004;
 
+      BadTurn = Low(LongInt) div 4;
 
 type TTarget = record
     Point: TPoint;
     Score: LongInt;
-    skip: boolean;
+    skip, matters: boolean;
     end;
 TTargets = record
     Count: Longword;
@@ -117,19 +118,19 @@
                     with Targets.ar[Targets.Count], Hedgehogs[i] do
                         begin
                         skip:= false;
+                        matters:= (Hedgehogs[i].Gear^.AIHints and aihDoesntMatter) = 0;
+                        
                         Point.X:= hwRound(Gear^.X);
                         Point.Y:= hwRound(Gear^.Y);
-                        if (Hedgehogs[i].Gear^.AIHints and aihDoesntMatter) <> 0 then
-                            Score:= 0
-                            else if Clan <> CurrentTeam^.Clan then
-                                begin
-                                Score:= Gear^.Health - Gear^.Damage;
-                                inc(e)
-                                end else
-                                begin
-                                Score:= Gear^.Damage - Gear^.Health;
-                                inc(f)
-                                end
+                        if Clan <> CurrentTeam^.Clan then
+                            begin
+                            Score:= Gear^.Health - Gear^.Damage;
+                            inc(e)
+                            end else
+                            begin
+                            Score:= Gear^.Damage - Gear^.Health;
+                            inc(f)
+                            end
                         end;
                     inc(Targets.Count)
                     end;
@@ -409,6 +410,7 @@
 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
 var i, fallDmg, dmg, dmgBase, rate, erasure: LongInt;
     dX, dY, dmgMod: real;
+    hadSkips: boolean;
 begin
 fallDmg:= 0;
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
@@ -418,14 +420,22 @@
     begin
     Point.x:= hwRound(Me^.X);
     Point.y:= hwRound(Me^.Y);
+    skip:= false;
+    matters:= true;
     Score:= - ThinkingHH^.Health
     end;
 // rate explosion
 dmgBase:= r + cHHRadius div 2;
+
 if (Flags and afErasesLand <> 0) and (GameFlags and gfSolidLand = 0) then erasure:= r
 else erasure:= 0;
+
+hadSkips:= false;
+
 for i:= 0 to Targets.Count do
     with Targets.ar[i] do
+      if not matters then hadSkips:= true
+        else
         begin
         dmg:= 0;
         if abs(Point.x - x) + abs(Point.y - y) < dmgBase then
@@ -458,7 +468,11 @@
                 else dec(rate, (dmg + fallDmg) * friendlyfactor div 100 * 1024)
             end;
         end;
-RateExplosion:= rate;
+
+if hadSkips and (rate = 0) then
+    RateExplosion:= BadTurn
+    else
+    RateExplosion:= rate;
 end;
 
 function RateShove(x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
@@ -474,7 +488,7 @@
     with Targets.ar[i] do
       if skip then 
         if (Flags and afSetSkip = 0) then skip:= false else {still skip}
-      else  
+      else if matters then
         begin
         dmg:= 0;
         if abs(Point.x - x) + abs(Point.y - y) < r then
@@ -508,6 +522,7 @@
 function RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
 var i, dmg, fallDmg, baseDmg, rate, erasure: LongInt;
     dX, dY, dmgMod: real;
+    hadSkips: boolean;
 begin
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 rate:= 0;
@@ -518,14 +533,22 @@
     begin
     Point.x:= hwRound(Me^.X);
     Point.y:= hwRound(Me^.Y);
+    skip:= false;
+    matters:= true;
     Score:= - ThinkingHH^.Health
     end;
 // rate shot
 baseDmg:= cHHRadius + cShotgunRadius + 4;
+
 if GameFlags and gfSolidLand = 0 then erasure:= cShotgunRadius
 else erasure:= 0;
+
+hadSkips:= false;
+
 for i:= 0 to Targets.Count do
     with Targets.ar[i] do
+      if not matters then hadSkips:= true
+        else
         begin
         dmg:= 0;
         if abs(Point.x - x) + abs(Point.y - y) < baseDmg then
@@ -559,8 +582,12 @@
             else
                 dec(rate, (dmg+fallDmg) * friendlyfactor div 100)
             end;
-        end;        
-RateShotgun:= rate * 1024;
+        end;
+
+if hadSkips and (rate = 0) then
+    RateShotgun:= BadTurn
+    else
+    RateShotgun:= rate * 1024;
 end;
 
 function RateHammer(Me: PGear): LongInt;
@@ -573,6 +600,7 @@
 
 for i:= 0 to Pred(Targets.Count) do
     with Targets.ar[i] do
+      if matters then
          // hammer hit radius is 8, shift is 10
         if abs(Point.x - x) + abs(Point.y - y) < 18 then
             begin