hedgewars/uAIAmmoTests.pas
changeset 375 18012da67681
parent 374 95169697cc38
child 393 db01cc79f278
equal deleted inserted replaced
374:95169697cc38 375:18012da67681
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    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}       @TestGrenade,
    33 {amGrenade}       @TestGrenade,
    34 {amClusterBomb}   nil,
    34 {amClusterBomb}   nil,
    35 {amBazooka}       @TestBazooka,
    35 {amBazooka}       @TestBazooka,
    36 {amUFO}           nil,
    36 {amUFO}           nil,
    37 {amShotgun}       nil,//TestShotgun,
    37 {amShotgun}       @TestShotgun,
    38 {amPickHammer}    nil,
    38 {amPickHammer}    nil,
    39 {amSkip}          nil,
    39 {amSkip}          nil,
    40 {amRope}          nil,
    40 {amRope}          nil,
    41 {amMine}          nil,
    41 {amMine}          nil,
    42 {amDEagle}        nil,//TestDesertEagle,
    42 {amDEagle}        nil,//TestDesertEagle,
    90     CheckTrace:= Result
    90     CheckTrace:= Result
    91     end;
    91     end;
    92 
    92 
    93 begin
    93 begin
    94 Time:= 0;
    94 Time:= 0;
    95 rTime:= 50;
    95 rTime:= 350;
    96 ExplR:= 0;
    96 ExplR:= 0;
    97 Result:= BadTurn;
    97 Result:= BadTurn;
    98 repeat
    98 repeat
    99   rTime:= rTime + 300 + Level * 50 + random(200);
    99   rTime:= rTime + 300 + Level * 50 + random(300);
   100   Vx:= - cWindSpeed * rTime * _0_5 + (Targ.X - hwRound(Me^.X)) / rTime;
   100   Vx:= - cWindSpeed * rTime * _0_5 + (Targ.X - hwRound(Me^.X)) / rTime;
   101   Vy:= cGravity * rTime * _0_5 - (Targ.Y - hwRound(Me^.Y)) / rTime;
   101   Vy:= cGravity * rTime * _0_5 - (Targ.Y - hwRound(Me^.Y)) / rTime;
   102   r:= Distance(Vx, Vy);
   102   r:= Distance(Vx, Vy);
   103   if not (r > 1) then
   103   if not (r > 1) then
   104      begin
   104      begin
   111         ExplX:= EX;
   111         ExplX:= EX;
   112         ExplY:= EY;
   112         ExplY:= EY;
   113         Result:= Score
   113         Result:= Score
   114         end;
   114         end;
   115      end
   115      end
   116 until (rTime > 4500);
   116 until (rTime > 4250);
   117 TestBazooka:= Result
   117 TestBazooka:= Result
   118 end;
   118 end;
   119 
   119 
   120 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   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;
   167         end;
   167         end;
   168      end
   168      end
   169 until (TestTime = 5000);
   169 until (TestTime = 5000);
   170 TestGrenade:= Result
   170 TestGrenade:= Result
   171 end;
   171 end;
   172 {
   172 
   173 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   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     rx, ry, Result: LongInt;
   176 ExplR:= 0;
   176 begin
   177 if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then
   177 ExplR:= 0;
   178    begin
   178 if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
   179    Result:= BadTurn;
   179    begin
   180    exit
   180    Result:= BadTurn;
   181    end;
   181    exit
   182 Time:= 0;
   182    end;
   183 Power:= 1;
   183 Time:= 0;
   184 Vx:= (Targ.X - Me.X)/1024;
   184 Power:= 1;
   185 Vy:= (Targ.Y - Me.Y)/1024;
   185 Vx:= (Targ.X - Me^.X) * _1div1024;
   186 x:= Me.X;
   186 Vy:= (Targ.Y - Me^.Y) * _1div1024;
   187 y:= Me.Y;
   187 x:= Me^.X;
       
   188 y:= Me^.Y;
   188 Angle:= DxDy2AttackAngle(Vx, -Vy);
   189 Angle:= DxDy2AttackAngle(Vx, -Vy);
   189 repeat
   190 repeat
   190   x:= x + vX;
   191   x:= x + vX;
   191   y:= y + vY;
   192   y:= y + vY;
   192   if TestColl(round(x), round(y), 2) then
   193   rx:= hwRound(x);
       
   194   ry:= hwRound(y);
       
   195   if TestColl(rx, ry, 2) then
   193      begin
   196      begin
   194      Result:= RateShove(Me, round(x), round(y), 25, 25) * 2;
   197      Result:= RateShove(Me, rx, ry, 25, 25) * 2;
   195      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64
   198      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
   196                    else dec(Result, Level * 4000);
   199                    else dec(Result, Level * 4000);
   197      exit
   200      exit(Result)
   198      end
   201      end
   199 until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   202 until (hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   200 Result:= BadTurn
   203 TestShotgun:= BadTurn
   201 end;
   204 end;
   202 
   205 {
   203 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   206 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;
   207 var Vx, Vy, x, y, t: hwFloat;
   205     d: Longword;
   208     d: Longword;
   206 begin
   209 begin
   207 ExplR:= 0;
   210 ExplR:= 0;