hedgewars/uAIAmmoTests.pas
changeset 143 3dacbd83209b
parent 141 ac3680be1f4b
child 183 57c2ef19f719
equal deleted inserted replaced
142:1ff0b02fe367 143:3dacbd83209b
    54 {amSkip}          nil,
    54 {amSkip}          nil,
    55 {amRope}          nil,
    55 {amRope}          nil,
    56 {amMine}          nil,
    56 {amMine}          nil,
    57 {amDEagle}        TestDesertEagle,
    57 {amDEagle}        TestDesertEagle,
    58 {amDynamite}      nil,
    58 {amDynamite}      nil,
    59 {amBaseballBat}   TestBaseballBat,
    59 {amFirePunch}     TestFirePunch,
    60 {amFirePunch}     TestFirePunch
    60 {amBaseballBat}   TestBaseballBat
    61                   );
    61                   );
       
    62 
       
    63 const BadTurn = Low(integer);
    62 
    64 
    63 implementation
    65 implementation
    64 uses uMisc, uAIMisc, uLand;
    66 uses uMisc, uAIMisc, uLand;
    65 const BadTurn = Low(integer);
       
    66 
    67 
    67 function Metric(x1, y1, x2, y2: integer): integer;
    68 function Metric(x1, y1, x2, y2: integer): integer;
    68 begin
    69 begin
    69 Result:= abs(x1 - x2) + abs(y1 - y2)
    70 Result:= abs(x1 - x2) + abs(y1 - y2)
    70 end;
    71 end;
   115         Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8));
   116         Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random((Level - 1) * 8));
   116         Power:= round(r * cMaxPower) - random((Level - 1) * 15 + 1);
   117         Power:= round(r * cMaxPower) - random((Level - 1) * 15 + 1);
   117         ExplR:= 100;
   118         ExplR:= 100;
   118         ExplX:= EX;
   119         ExplX:= EX;
   119         ExplY:= EY;
   120         ExplY:= EY;
   120         Result:= Score - random((Level - 1) * 2500)
   121         Result:= Score
   121         end;
   122         end;
   122      end
   123      end
   123 until (rTime >= 4500)
   124 until (rTime >= 4500)
   124 end;
   125 end;
   125 
   126 
   195 repeat
   196 repeat
   196   x:= x + vX;
   197   x:= x + vX;
   197   y:= y + vY;
   198   y:= y + vY;
   198   if TestColl(round(x), round(y), 2) then
   199   if TestColl(round(x), round(y), 2) then
   199      begin
   200      begin
   200      Result:= RateShove(Me, round(x), round(y), 25, 25) * 2 - Level * 4000;
   201      Result:= RateShove(Me, round(x), round(y), 25, 25) * 2;
   201      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64;
   202      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64
       
   203                    else dec(Result, Level * 4000);
   202      exit
   204      exit
   203      end
   205      end
   204 until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   206 until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   205 Result:= BadTurn
   207 Result:= BadTurn
   206 end;
   208 end;
   235 end;
   237 end;
   236 
   238 
   237 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
   239 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
   238 begin
   240 begin
   239 ExplR:= 0;
   241 ExplR:= 0;
   240 if (Level < 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then
   242 if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then
   241    begin
   243    begin
   242    Result:= BadTurn;
   244    Result:= BadTurn;
   243    exit
   245    exit
   244    end;
   246    end;
   245 Time:= 0;
   247 Time:= 0;
   246 Power:= 1;
   248 Power:= 1;
   247 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   249 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   248 Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30)
   250 Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30);
       
   251 if Result <= 0 then Result:= BadTurn
   249 end;
   252 end;
   250 
   253 
   251 function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
   254 function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; out Time: Longword; out Angle, Power: integer; out ExplX, ExplY, ExplR: integer): integer;
   252 var i: integer;
   255 var i: integer;
   253 begin
   256 begin
   260 Time:= 0;
   263 Time:= 0;
   261 Power:= 1;
   264 Power:= 1;
   262 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   265 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   263 Result:= 0;
   266 Result:= 0;
   264 for i:= 0 to 4 do
   267 for i:= 0 to 4 do
   265     Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30)
   268     Result:= Result + RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y) - 20 * i - 5, 10, 30);
       
   269 if Result <= 0 then Result:= BadTurn
   266 end;
   270 end;
   267 
   271 
   268 end.
   272 end.