hedgewars/uAIAmmoTests.pas
changeset 371 731ad6d27bd1
parent 370 c75410fe3133
child 374 95169697cc38
equal deleted inserted replaced
370:c75410fe3133 371:731ad6d27bd1
    18 
    18 
    19 unit uAIAmmoTests;
    19 unit uAIAmmoTests;
    20 interface
    20 interface
    21 uses SDLh, uGears, uConsts, uFloat;
    21 uses SDLh, uGears, uConsts, uFloat;
    22 
    22 
    23 function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    23 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    24 (*function TestGrenade(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    24 (*function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    25 function TestShotgun(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    25 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    26 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    26 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    27 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    27 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    28 function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    28 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    29 *)
    29 *)
    30 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    30 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    31 const AmmoTests: array[TAmmoType] of TAmmoTestProc =
    31 const AmmoTests: array[TAmmoType] of TAmmoTestProc =
    32                  (
    32                  (
    33 {amGrenade}       nil,//TestGrenade,
    33 {amGrenade}       nil,//TestGrenade,
    34 {amClusterBomb}   nil,
    34 {amClusterBomb}   nil,
    35 {amBazooka}       @TestBazooka,
    35 {amBazooka}       @TestBazooka,
    47 {amAirAttack}     nil,
    47 {amAirAttack}     nil,
    48 {amMineStrike}    nil,
    48 {amMineStrike}    nil,
    49 {amBlowTorch}     nil
    49 {amBlowTorch}     nil
    50                   );
    50                   );
    51 
    51 
    52 const BadTurn = Low(integer);
    52 const BadTurn = Low(LongInt);
    53 
    53 
    54 
    54 
    55 implementation
    55 implementation
    56 uses uMisc, uAIMisc, uLand;
    56 uses uMisc, uAIMisc, uLand;
    57 
    57 
    58 function Metric(x1, y1, x2, y2: integer): integer;
    58 function Metric(x1, y1, x2, y2: LongInt): LongInt;
    59 begin
    59 begin
    60 Metric:= abs(x1 - x2) + abs(y1 - y2)
    60 Metric:= abs(x1 - x2) + abs(y1 - y2)
    61 end;
    61 end;
    62 
    62 
    63 function TestBazooka(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
    63 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    64 var Vx, Vy, r: hwFloat;
    64 var Vx, Vy, r: hwFloat;
    65     rTime: hwFloat;
    65     rTime: hwFloat;
    66     Score, EX, EY: integer;
    66     Score, EX, EY: LongInt;
    67     Result: integer;
    67     Result: LongInt;
    68 
    68 
    69     function CheckTrace: integer;
    69     function CheckTrace: LongInt;
    70     var x, y, dX, dY: hwFloat;
    70     var x, y, dX, dY: hwFloat;
    71         t: integer;
    71         t: LongInt;
    72         Result: integer;
    72         Result: LongInt;
    73     begin
    73     begin
    74     x:= Me^.X;
    74     x:= Me^.X;
    75     y:= Me^.Y;
    75     y:= Me^.Y;
    76     dX:= Vx;
    76     dX:= Vx;
    77     dY:= -Vy;
    77     dY:= -Vy;
   115      end
   115      end
   116 until (rTime > 4500);
   116 until (rTime > 4500);
   117 TestBazooka:= Result
   117 TestBazooka:= Result
   118 end;
   118 end;
   119 {
   119 {
   120 function TestGrenade(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
   120 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   121 const tDelta = 24;
   121 const tDelta = 24;
   122 var Vx, Vy, r: hwFloat;
   122 var Vx, Vy, r: hwFloat;
   123     Score, EX, EY: integer;
   123     Score, EX, EY: LongInt;
   124     TestTime: Longword;
   124     TestTime: Longword;
   125 
   125 
   126     function CheckTrace: integer;
   126     function CheckTrace: LongInt;
   127     var x, y, dY: hwFloat;
   127     var x, y, dY: hwFloat;
   128         t: integer;
   128         t: LongInt;
   129     begin
   129     begin
   130     x:= Me.X;
   130     x:= Me.X;
   131     y:= Me.Y;
   131     y:= Me.Y;
   132     dY:= -Vy;
   132     dY:= -Vy;
   133     t:= TestTime;
   133     t:= TestTime;
   138       dec(t)
   138       dec(t)
   139     until TestColl(round(x), round(y), 5) or (t = 0);
   139     until TestColl(round(x), round(y), 5) or (t = 0);
   140     EX:= round(x);
   140     EX:= round(x);
   141     EY:= round(y);
   141     EY:= round(y);
   142     if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101)
   142     if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101)
   143               else Result:= Low(integer)
   143               else Result:= Low(LongInt)
   144     end;
   144     end;
   145 
   145 
   146 begin
   146 begin
   147 Result:= BadTurn;
   147 Result:= BadTurn;
   148 TestTime:= 0;
   148 TestTime:= 0;
   168         end;
   168         end;
   169      end
   169      end
   170 until (TestTime = 5000)
   170 until (TestTime = 5000)
   171 end;
   171 end;
   172 
   172 
   173 function TestShotgun(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
   173 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   174 var Vx, Vy, x, y: hwFloat;
   174 var Vx, Vy, x, y: hwFloat;
   175 begin       
   175 begin       
   176 ExplR:= 0;
   176 ExplR:= 0;
   177 if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then
   177 if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then
   178    begin
   178    begin
   198      end
   198      end
   199 until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   199 until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   200 Result:= BadTurn
   200 Result:= BadTurn
   201 end;
   201 end;
   202 
   202 
   203 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
   203 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   204 var Vx, Vy, x, y, t: hwFloat;
   204 var Vx, Vy, x, y, t: hwFloat;
   205     d: Longword;
   205     d: Longword;
   206 begin
   206 begin
   207 ExplR:= 0;
   207 ExplR:= 0;
   208 if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then
   208 if abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) < 80 then
   224   y:= y + vY;
   224   y:= y + vY;
   225   if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0)
   225   if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0)
   226      and (Land[round(y), round(x)] <> 0) then inc(d);
   226      and (Land[round(y), round(x)] <> 0) then inc(d);
   227 until (abs(Targ.X - x) + abs(Targ.Y - y) < 2) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024) or (d > 200);
   227 until (abs(Targ.X - x) + abs(Targ.Y - y) < 2) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024) or (d > 200);
   228 if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   228 if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   229                                          else Result:= Low(integer)
   229                                          else Result:= Low(LongInt)
   230 end;
   230 end;
   231 
   231 
   232 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
   232 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   233 begin
   233 begin
   234 ExplR:= 0;
   234 ExplR:= 0;
   235 if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then
   235 if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then
   236    begin
   236    begin
   237    Result:= BadTurn;
   237    Result:= BadTurn;
   242 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   242 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   243 Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30);
   243 Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30);
   244 if Result <= 0 then Result:= BadTurn
   244 if Result <= 0 then Result:= BadTurn
   245 end;
   245 end;
   246 
   246 
   247 function TestFirePunch(Me: PGear; Targ: TPoint; Level: Integer; var Time: Longword; var Angle, Power: integer; var ExplX, ExplY, ExplR: integer): integer;
   247 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   248 var i: integer;
   248 var i: LongInt;
   249 begin
   249 begin
   250 ExplR:= 0;
   250 ExplR:= 0;
   251 if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then
   251 if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then
   252    begin
   252    begin
   253    Result:= BadTurn;
   253    Result:= BadTurn;