hedgewars/uAIAmmoTests.pas
changeset 8950 3bf81ed1f984
parent 8924 13ac59499066
child 8952 a6ee1e7310fb
equal deleted inserted replaced
8949:fac5a075f021 8950:3bf81ed1f984
   306         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
   306         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
   307                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t <= 0);
   307                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t <= 0);
   308         EX:= trunc(x);
   308         EX:= trunc(x);
   309         EY:= trunc(y);
   309         EY:= trunc(y);
   310 
   310 
   311         value:= RateShove(trunc(x), trunc(y), 5, 1, trunc((abs(dX)+abs(dY))*20), -dX, -dY, afTrackFall);
   311         value:= RateShove(Me, trunc(x), trunc(y), 5, 1, trunc((abs(dX)+abs(dY))*20), -dX, -dY, afTrackFall);
   312         // LOL copypasta: this is score for digging with... snowball
   312         // LOL copypasta: this is score for digging with... snowball
   313         //if value = 0 then
   313         //if value = 0 then
   314         //    value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   314         //    value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   315 
   315 
   316         if valueResult <= value then
   316         if valueResult <= value then
   800     while a >= 0 do
   800     while a >= 0 do
   801         begin
   801         begin
   802         dx:= sin(a / cMaxAngle * pi) * 0.5;
   802         dx:= sin(a / cMaxAngle * pi) * 0.5;
   803         dy:= cos(a / cMaxAngle * pi) * 0.5;
   803         dy:= cos(a / cMaxAngle * pi) * 0.5;
   804 
   804 
   805         v1:= RateShove(x - 10, y + 2
   805         v1:= RateShove(Me, x - 10, y + 2
   806                 , 32, 30, 115
   806                 , 32, 30, 115
   807                 , -dx, -dy, trackFall);
   807                 , -dx, -dy, trackFall);
   808         v2:= RateShove(x + 10, y + 2
   808         v2:= RateShove(Me, x + 10, y + 2
   809                 , 32, 30, 115
   809                 , 32, 30, 115
   810                 , dx, -dy, trackFall);
   810                 , dx, -dy, trackFall);
   811         if (v1 > valueResult) or (v2 > valueResult) then
   811         if (v1 > valueResult) or (v2 > valueResult) then
   812             if (v2 > v1)
   812             if (v2 > v1)
   813                 or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   813                 or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   846     y:= hwRound(Me^.Y) + 4;
   846     y:= hwRound(Me^.Y) + 4;
   847 
   847 
   848     v1:= 0;
   848     v1:= 0;
   849     for i:= 0 to 8 do
   849     for i:= 0 to 8 do
   850         begin
   850         begin
   851         v1:= v1 + RateShove(x - 5, y - 10 * i
   851         v1:= v1 + RateShove(Me, x - 5, y - 10 * i
   852                 , 19, 30, 40
   852                 , 19, 30, 40
   853                 , -0.45, -0.9, trackFall or afSetSkip);
   853                 , -0.45, -0.9, trackFall or afSetSkip);
   854         end;
   854         end;
   855     v1:= v1 + RateShove(x - 5, y - 90
   855     v1:= v1 + RateShove(Me, x - 5, y - 90
   856             , 19, 30, 40
   856             , 19, 30, 40
   857             , -0.45, -0.9, trackFall);
   857             , -0.45, -0.9, trackFall);
   858 
   858 
   859 
   859 
   860     // now try opposite direction
   860     // now try opposite direction
   861     v2:= 0;
   861     v2:= 0;
   862     for i:= 0 to 8 do
   862     for i:= 0 to 8 do
   863         begin
   863         begin
   864         v2:= v2 + RateShove(x + 5, y - 10 * i
   864         v2:= v2 + RateShove(Me, x + 5, y - 10 * i
   865                 , 19, 30, 40
   865                 , 19, 30, 40
   866                 , 0.45, -0.9, trackFall or afSetSkip);
   866                 , 0.45, -0.9, trackFall or afSetSkip);
   867         end;
   867         end;
   868     v2:= v2 + RateShove(x + 5, y - 90
   868     v2:= v2 + RateShove(Me, x + 5, y - 90
   869             , 19, 30, 40
   869             , 19, 30, 40
   870             , 0.45, -0.9, trackFall);
   870             , 0.45, -0.9, trackFall);
   871 
   871 
   872     if (v2 > v1)
   872     if (v2 > v1)
   873         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   873         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   905 
   905 
   906     // check left direction
   906     // check left direction
   907     {first RateShove checks farthermost of two whip's AmmoShove attacks
   907     {first RateShove checks farthermost of two whip's AmmoShove attacks
   908     to encourage distant attacks (damaged hog is excluded from view of second
   908     to encourage distant attacks (damaged hog is excluded from view of second
   909     RateShove call)}
   909     RateShove call)}
   910     v1:= RateShove(x - 13, y
   910     v1:= RateShove(Me, x - 13, y
   911             , 30, 30, 25
   911             , 30, 30, 25
   912             , -1, -0.8, trackFall or afSetSkip);
   912             , -1, -0.8, trackFall or afSetSkip);
   913     v1:= v1 +
   913     v1:= v1 +
   914         RateShove(x - 2, y
   914         RateShove(Me, x - 2, y
   915             , 30, 30, 25
   915             , 30, 30, 25
   916             , -1, -0.8, trackFall);
   916             , -1, -0.8, trackFall);
   917     // now try opposite direction
   917     // now try opposite direction
   918     v2:= RateShove(x + 13, y
   918     v2:= RateShove(Me, x + 13, y
   919             , 30, 30, 25
   919             , 30, 30, 25
   920             , 1, -0.8, trackFall or afSetSkip);
   920             , 1, -0.8, trackFall or afSetSkip);
   921     v2:= v2 +
   921     v2:= v2 +
   922         RateShove(x + 2, y
   922         RateShove(Me, x + 2, y
   923             , 30, 30, 25
   923             , 30, 30, 25
   924             , 1, -0.8, trackFall);
   924             , 1, -0.8, trackFall);
   925 
   925 
   926     if (v2 > v1)
   926     if (v2 > v1)
   927         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   927         or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   984     if dx >= 0 then cx:= 0.45 else cx:= -0.45;
   984     if dx >= 0 then cx:= 0.45 else cx:= -0.45;
   985 
   985 
   986     for i:= 0 to 512 div step - 2 do
   986     for i:= 0 to 512 div step - 2 do
   987         begin
   987         begin
   988         valueResult:= valueResult +
   988         valueResult:= valueResult +
   989             RateShove(trunc(x), trunc(y)
   989             RateShove(Me, trunc(x), trunc(y)
   990                 , 30, 30, 25
   990                 , 30, 30, 25
   991                 , cx, -0.9, trackFall or afSetSkip);
   991                 , cx, -0.9, trackFall or afSetSkip);
   992 
   992 
   993         x:= x + dx;
   993         x:= x + dx;
   994         y:= y + dy;
   994         y:= y + dy;
   996     if dx = 0 then
   996     if dx = 0 then
   997         begin
   997         begin
   998         x:= hwFloat2Float(Me^.X);
   998         x:= hwFloat2Float(Me^.X);
   999         y:= hwFloat2Float(Me^.Y);
   999         y:= hwFloat2Float(Me^.Y);
  1000         tx:= trunc(x);
  1000         tx:= trunc(x);
  1001         v:= RateShove(tx, trunc(y)
  1001         v:= RateShove(Me, tx, trunc(y)
  1002                 , 30, 30, 25
  1002                 , 30, 30, 25
  1003                 , -cx, -0.9, trackFall);
  1003                 , -cx, -0.9, trackFall);
  1004         for i:= 1 to 512 div step - 2 do
  1004         for i:= 1 to 512 div step - 2 do
  1005             begin
  1005             begin
  1006             y:= y + dy;
  1006             y:= y + dy;
  1007             v:= v +
  1007             v:= v +
  1008                 RateShove(tx, trunc(y)
  1008                 RateShove(Me, tx, trunc(y)
  1009                     , 30, 30, 25
  1009                     , 30, 30, 25
  1010                     , -cx, -0.9, trackFall or afSetSkip);
  1010                     , -cx, -0.9, trackFall or afSetSkip);
  1011             end
  1011             end
  1012         end;
  1012         end;
  1013     if v > valueResult then
  1013     if v > valueResult then
  1014         begin
  1014         begin
  1015         ap.Angle:= -2048;
  1015         ap.Angle:= -2048;
  1016         valueResult:= v
  1016         valueResult:= v
  1017         end;
  1017         end;
  1018 
  1018 
  1019     v:= RateShove(trunc(x), trunc(y)
  1019     v:= RateShove(Me, trunc(x), trunc(y)
  1020             , 30, 30, 25
  1020             , 30, 30, 25
  1021             , cx, -0.9, trackFall);
  1021             , cx, -0.9, trackFall);
  1022     valueResult:= valueResult + v - KillScore * friendlyfactor div 100 * 1024;
  1022     valueResult:= valueResult + v - KillScore * friendlyfactor div 100 * 1024;
  1023 
  1023 
  1024     if v < 65536 then
  1024     if v < 65536 then