hedgewars/uAIAmmoTests.pas
changeset 7441 5d64f59f2ca5
parent 7433 c7fff3e61d49
child 7471 ce5d3e39361e
equal deleted inserted replaced
7437:a46ce1812419 7441:5d64f59f2ca5
   359     TestTime: Longword;
   359     TestTime: Longword;
   360     x, y, dY, meX, meY: real;
   360     x, y, dY, meX, meY: real;
   361     t: LongInt;
   361     t: LongInt;
   362 begin
   362 begin
   363 valueResult:= BadTurn;
   363 valueResult:= BadTurn;
   364 TestTime:= 0;
   364 TestTime:= 500;
   365 ap.ExplR:= 0;
   365 ap.ExplR:= 0;
   366 meX:= hwFloat2Float(Me^.X);
   366 meX:= hwFloat2Float(Me^.X);
   367 meY:= hwFloat2Float(Me^.Y);
   367 meY:= hwFloat2Float(Me^.Y);
   368 repeat
   368 repeat
   369     inc(TestTime, 1000);
   369     inc(TestTime, 900);
   370     // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster
   370     // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster
   371     if meX<Targ.X then
   371     if meX<Targ.X then
   372         Vx:= ((Targ.X+10) - meX) / (TestTime + tDelta)
   372         Vx:= ((Targ.X+10) - meX) / (TestTime + tDelta)
   373     else
   373     else
   374         Vx:= ((Targ.X-10) - meX) / (TestTime + tDelta);
   374         Vx:= ((Targ.X-10) - meX) / (TestTime + tDelta);
   396 
   396 
   397      if valueResult < Score then
   397      if valueResult < Score then
   398         begin
   398         begin
   399         ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
   399         ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
   400         ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
   400         ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
   401         ap.Time:= TestTime;
   401         ap.Time:= TestTime div 1000 * 1000;
   402         ap.ExplR:= 90;
   402         ap.ExplR:= 90;
   403         ap.ExplX:= EX;
   403         ap.ExplX:= EX;
   404         ap.ExplY:= EY;
   404         ap.ExplY:= EY;
   405         valueResult:= Score
   405         valueResult:= Score
   406         end;
   406         end;
   407      end
   407      end
   408 until (TestTime = 4000);
   408 until (TestTime = 4100);
   409 TestClusterBomb:= valueResult
   409 TestClusterBomb:= valueResult
   410 end;
   410 end;
   411 
   411 
   412 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   412 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   413 const tDelta = 24;
   413 const tDelta = 24;
   416     TestTime: Longword;
   416     TestTime: Longword;
   417     x, y, dY, meX, meY: real;
   417     x, y, dY, meX, meY: real;
   418     t: LongInt;
   418     t: LongInt;
   419 begin
   419 begin
   420 valueResult:= BadTurn;
   420 valueResult:= BadTurn;
   421 TestTime:= 0;
   421 TestTime:= 500;
   422 ap.ExplR:= 0;
   422 ap.ExplR:= 0;
   423 meX:= hwFloat2Float(Me^.X);
   423 meX:= hwFloat2Float(Me^.X);
   424 meY:= hwFloat2Float(Me^.Y);
   424 meY:= hwFloat2Float(Me^.Y);
   425 repeat
   425 repeat
   426     inc(TestTime, 1000);
   426     inc(TestTime, 900);
   427     Vx:= (Targ.X - meX) / (TestTime + tDelta);
   427     Vx:= (Targ.X - meX) / (TestTime + tDelta);
   428     Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-50) - meY) / (TestTime + tDelta);
   428     Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Y-50) - meY) / (TestTime + tDelta);
   429     r:= sqr(Vx)+sqr(Vy);
   429     r:= sqr(Vx)+sqr(Vy);
   430     if not (r > 1) then
   430     if not (r > 1) then
   431         begin
   431         begin
   450             
   450             
   451         if valueResult < Score then
   451         if valueResult < Score then
   452             begin
   452             begin
   453             ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
   453             ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random(Level));
   454             ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
   454             ap.Power:= trunc(sqrt(r) * cMaxPower) + AIrndSign(random(Level) * 15);
   455             ap.Time:= TestTime;
   455             ap.Time:= TestTime div 1000 * 1000;
   456             ap.ExplR:= 300;
   456             ap.ExplR:= 300;
   457             ap.ExplX:= EX;
   457             ap.ExplX:= EX;
   458             ap.ExplY:= EY;
   458             ap.ExplY:= EY;
   459             valueResult:= Score
   459             valueResult:= Score
   460             end;
   460             end;
   461         end
   461         end
   462 until (TestTime = 4000);
   462 until (TestTime = 4100);
   463 TestWatermelon:= valueResult
   463 TestWatermelon:= valueResult
   464 end;
   464 end;
   465 
   465 
   466 
   466 
   467     function Solve(TX, TY, MX, MY: LongInt): LongWord;
   467     function Solve(TX, TY, MX, MY: LongInt): LongWord;
   820     RateShove call)}
   820     RateShove call)}
   821     v1:= RateShove(Me, x - 13, y
   821     v1:= RateShove(Me, x - 13, y
   822             , 30, 30, 25
   822             , 30, 30, 25
   823             , -1, -0.8, trackFall or afSetSkip);
   823             , -1, -0.8, trackFall or afSetSkip);
   824     v1:= v1 +
   824     v1:= v1 +
   825         RateShove(Me, x, y
   825         RateShove(Me, x - 2, y
   826             , 30, 30, 25
   826             , 30, 30, 25
   827             , -1, -0.8, trackFall);
   827             , -1, -0.8, trackFall);
   828     // now try opposite direction
   828     // now try opposite direction
   829     v2:= RateShove(Me, x + 13, y
   829     v2:= RateShove(Me, x + 13, y
   830             , 30, 30, 25
   830             , 30, 30, 25
   831             , 1, -0.8, trackFall or afSetSkip);
   831             , 1, -0.8, trackFall or afSetSkip);
   832     v2:= v2 +
   832     v2:= v2 +
   833         RateShove(Me, x, y
   833         RateShove(Me, x + 2, y
   834             , 30, 30, 25
   834             , 30, 30, 25
   835             , 1, -0.8, trackFall);
   835             , 1, -0.8, trackFall);
   836 
   836 
   837     if (v2 > v1) 
   837     if (v2 > v1) 
   838         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   838         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then