hedgewars/uAIAmmoTests.pas
changeset 433 9f8f22094c0e
parent 409 4f1841929ccc
child 434 2c6ccce17f39
equal deleted inserted replaced
432:b0f693024b50 433:9f8f22094c0e
    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 *)
    27 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    28 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;
    29 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    29 *)
    30 
    30 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    31 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 =
    32 const AmmoTests: array[TAmmoType] of TAmmoTestProc =
    32                  (
    33                  (
    33 {amGrenade}       @TestGrenade,
    34 {amGrenade}       @TestGrenade,
    34 {amClusterBomb}   nil,
    35 {amClusterBomb}   nil,
    35 {amBazooka}       @TestBazooka,
    36 {amBazooka}       @TestBazooka,
    36 {amUFO}           nil,
    37 {amUFO}           nil,
    37 {amShotgun}       @TestShotgun,
    38 {amShotgun}       nil,//@TestShotgun,
    38 {amPickHammer}    nil,
    39 {amPickHammer}    nil,
    39 {amSkip}          nil,
    40 {amSkip}          nil,
    40 {amRope}          nil,
    41 {amRope}          nil,
    41 {amMine}          nil,
    42 {amMine}          nil,
    42 {amDEagle}        nil,//TestDesertEagle,
    43 {amDEagle}        nil,//TestDesertEagle,
    43 {amDynamite}      nil,
    44 {amDynamite}      nil,
    44 {amFirePunch}     nil,//TestFirePunch,
    45 {amFirePunch}     @TestFirePunch,
    45 {amBaseballBat}   nil,//TestBaseballBat,
    46 {amBaseballBat}   @TestBaseballBat,
    46 {amParachute}     nil,
    47 {amParachute}     nil,
    47 {amAirAttack}     nil,
    48 {amAirAttack}     nil,
    48 {amMineStrike}    nil,
    49 {amMineStrike}    nil,
    49 {amBlowTorch}     nil,
    50 {amBlowTorch}     nil,
    50 {amGirder}        nil
    51 {amGirder}        nil
   104   if not (r > 1) then
   105   if not (r > 1) then
   105      begin
   106      begin
   106      Score:= CheckTrace;
   107      Score:= CheckTrace;
   107      if Result <= Score then
   108      if Result <= Score then
   108         begin
   109         begin
   109         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 8));
   110         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 11));
   110         Power:= hwRound(r * cMaxPower) - random((Level - 1) * 15 + 1);
   111         Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1);
   111         ExplR:= 100;
   112         ExplR:= 100;
   112         ExplX:= EX;
   113         ExplX:= EX;
   113         ExplY:= EY;
   114         ExplY:= EY;
   114         Result:= Score
   115         Result:= Score
   115         end;
   116         end;
   157      begin
   158      begin
   158      Score:= CheckTrace;
   159      Score:= CheckTrace;
   159      if Result < Score then
   160      if Result < Score then
   160         begin
   161         begin
   161         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
   162         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
   162         Power:= hwRound(r * cMaxPower) + AIrndSign(random(Level) * 12);
   163         Power:= hwRound(r * cMaxPower) + AIrndSign(random(Level) * 15);
   163         Time:= TestTime;
   164         Time:= TestTime;
   164         ExplR:= 100;
   165         ExplR:= 100;
   165         ExplX:= EX;
   166         ExplX:= EX;
   166         ExplY:= EY;
   167         ExplY:= EY;
   167         Result:= Score
   168         Result:= Score
   230      and (Land[round(y), round(x)] <> 0) then inc(d);
   231      and (Land[round(y), round(x)] <> 0) then inc(d);
   231 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);
   232 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);
   232 if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   233 if abs(Targ.X - x) + abs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   233                                          else Result:= Low(LongInt)
   234                                          else Result:= Low(LongInt)
   234 end;
   235 end;
   235 
   236 }
   236 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   237 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   237 begin
   238 var Result: LongInt;
   238 ExplR:= 0;
   239 begin
   239 if (Level > 2) and (abs(Me.X - Targ.X) + abs(Me.Y - Targ.Y) >= 25) then
   240 ExplR:= 0;
   240    begin
   241 if (Level > 2) and not (hwAbs(Me^.X - Targ.X) + hwAbs(Me^.Y - Targ.Y) < 25) then
   241    Result:= BadTurn;
   242    exit(BadTurn);
   242    exit
   243 
   243    end;
   244 Time:= 0;
   244 Time:= 0;
   245 Power:= 1;
   245 Power:= 1;
   246 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me^.X), 1);
   246 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
   247 Result:= RateShove(Me, hwRound(Me^.X) + 10 * hwSign(Targ.X - Me^.X), hwRound(Me^.Y), 15, 30);
   247 Result:= RateShove(Me, round(Me.X) + 10 * hwSign(Targ.X - Me.X), round(Me.Y), 15, 30);
   248 if Result <= 0 then Result:= BadTurn else inc(Result);
   248 if Result <= 0 then Result:= BadTurn
   249 TestBaseballBat:= Result
   249 end;
   250 end;
   250 
   251 
   251 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   252 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   252 var i: LongInt;
   253 var i, Result: LongInt;
   253 begin
   254 begin
   254 ExplR:= 0;
   255 ExplR:= 0;
   255 if (abs(Me.X - Targ.X) > 25) or (abs(Me.Y - 50 - Targ.Y) > 50) then
   256 Time:= 0;
   256    begin
   257 Power:= 1;
   257    Result:= BadTurn;
   258 Angle:= 0;
   258    exit
   259 if (hwAbs(Me^.X - Targ.X) > 25) or (hwAbs(Me^.Y - 50 - Targ.Y) > 50) then
   259    end;
   260    exit(BadTurn);
   260 Time:= 0;
   261 
   261 Power:= 1;
       
   262 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me.X), 1);
       
   263 Result:= 0;
   262 Result:= 0;
   264 for i:= 0 to 4 do
   263 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);
   264     Result:= Result + RateShove(Me, hwRound(Me^.X) + 10 * hwSign(Targ.X - Me^.X), hwRound(Me^.Y) - 20 * i - 5, 10, 30);
   266 if Result <= 0 then Result:= BadTurn
   265 if Result <= 0 then Result:= BadTurn;
   267 end;
   266 TestFirePunch:= Result
   268 }
   267 end;
       
   268 
   269 end.
   269 end.