hedgewars/uAIAmmoTests.pas
changeset 7161 21a9c70b2070
parent 7154 56e329edf4b8
child 7178 c61cfc9eb29d
equal deleted inserted replaced
7159:0cc7420c0b98 7161:21a9c70b2070
   161         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
   161         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
   162         
   162         
   163         EX:= trunc(x);
   163         EX:= trunc(x);
   164         EY:= trunc(y);
   164         EY:= trunc(y);
   165         if Me^.Hedgehog^.BotLevel = 1 then
   165         if Me^.Hedgehog^.BotLevel = 1 then
   166             value:= RateExplosion(Me, EX, EY, 101, 3)
   166             value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   167         else value:= RateExplosion(Me, EX, EY, 101);
   167         else value:= RateExplosion(Me, EX, EY, 101);
   168         if value = 0 then
   168         if value = 0 then
   169             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   169             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   170         if valueResult <= value then
   170         if valueResult <= value then
   171             begin
   171             begin
   218             dec(t)
   218             dec(t)
   219         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
   219         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
   220         EX:= trunc(x);
   220         EX:= trunc(x);
   221         EY:= trunc(y);
   221         EY:= trunc(y);
   222 
   222 
   223         value:= RateShove(Me, trunc(x), trunc(y), 5, 1, trunc((abs(dX)+abs(dY))*20), -dX, -dY, 1);
   223         value:= RateShove(Me, trunc(x), trunc(y), 5, 1, trunc((abs(dX)+abs(dY))*20), -dX, -dY, afTrackFall);
   224         if value = 0 then
   224         if value = 0 then
   225             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   225             value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   226 
   226 
   227         if valueResult <= value then
   227         if valueResult <= value then
   228             begin
   228             begin
   321         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t = 0);
   321         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t = 0);
   322     EX:= trunc(x);
   322     EX:= trunc(x);
   323     EY:= trunc(y);
   323     EY:= trunc(y);
   324     if t < 50 then 
   324     if t < 50 then 
   325         if Me^.Hedgehog^.BotLevel = 1 then
   325         if Me^.Hedgehog^.BotLevel = 1 then
   326             Score:= RateExplosion(Me, EX, EY, 101, 3)
   326             Score:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   327         else Score:= RateExplosion(Me, EX, EY, 101)
   327         else Score:= RateExplosion(Me, EX, EY, 101)
   328     else 
   328     else 
   329         Score:= BadTurn;
   329         Score:= BadTurn;
   330 
   330 
   331     if valueResult < Score then
   331     if valueResult < Score then
   648 if (Targ.X) - trunc(x) >= 0 then
   648 if (Targ.X) - trunc(x) >= 0 then
   649     ap.Angle:=   cMaxAngle div 4
   649     ap.Angle:=   cMaxAngle div 4
   650 else
   650 else
   651     ap.Angle:= - cMaxAngle div 4;
   651     ap.Angle:= - cMaxAngle div 4;
   652 
   652 
   653 valueResult:= RateShove(Me, trunc(x) + LongWord(10*hwSignf(Targ.X - x)), trunc(y), 15, 30, 115, hwSign(Me^.dX)*0.353, -0.353, 1);
   653 valueResult:= RateShove(Me, trunc(x) + LongWord(10*hwSignf(Targ.X - x)), trunc(y), 15, 30, 115, hwSign(Me^.dX)*0.353, -0.353, afTrackFall);
   654 if valueResult <= 0 then
   654 if valueResult <= 0 then
   655     valueResult:= BadTurn
   655     valueResult:= BadTurn
   656 else
   656 else
   657     inc(valueResult);
   657     inc(valueResult);
   658 TestBaseballBat:= valueResult;
   658 TestBaseballBat:= valueResult;
   686     }
   686     }
   687 // and this is actual try to attack
   687 // and this is actual try to attack
   688 val1:= 0;
   688 val1:= 0;
   689 for i:= 0 to 4 do
   689 for i:= 0 to 4 do
   690     begin
   690     begin
   691     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, hwSign(Me^.dX)*0.45, -0.9, 1);
   691     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, hwSign(Me^.dX)*0.45, -0.9, afTrackFall);
   692     if (val1 < 0) or (t < 0) then val1:= BadTurn
   692     if (val1 < 0) or (t < 0) then val1:= BadTurn
   693     else if t > 0 then val1:= t;
   693     else if t > 0 then val1:= t;
   694     end;
   694     end;
   695 
   695 
   696 val2:= 0;
   696 val2:= 0;
   697 for i:= 0 to 4 do
   697 for i:= 0 to 4 do
   698     begin
   698     begin
   699     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, -hwSign(Me^.dX)*0.45, -0.9, 1);
   699     t:= RateShove(Me, trunc(x) + 10 * hwSignf(Targ.X - x), trunc(y) - 20 * i - 5, 10, 30, 40, -hwSign(Me^.dX)*0.45, -0.9, afTrackFall);
   700     if (val2 < 0) or (t < 0) then val2:= BadTurn
   700     if (val2 < 0) or (t < 0) then val2:= BadTurn
   701     else if t > 0 then val2:= t;
   701     else if t > 0 then val2:= t;
   702     end;
   702     end;
   703 if (val1 > val2) and (val1 > 0) then 
   703 if (val1 > val2) and (val1 > 0) then 
   704     TestFirePunch:= val1
   704     TestFirePunch:= val1
   730 {first RateShove checks fartherest of two whip's AmmoShove attacks 
   730 {first RateShove checks fartherest of two whip's AmmoShove attacks 
   731 to encourage distant attacks (damaged hog is excluded from view of second 
   731 to encourage distant attacks (damaged hog is excluded from view of second 
   732 RateShove call)}
   732 RateShove call)}
   733 v1:= RateShove(Me, trunc(x) - 15, trunc(y)
   733 v1:= RateShove(Me, trunc(x) - 15, trunc(y)
   734         , 30, 30, 40
   734         , 30, 30, 40
   735         , -1, -0.8, 1 or fSetSkip);
   735         , -1, -0.8, afTrackFall or afSetSkip);
   736 v1:= v1 +
   736 v1:= v1 +
   737     RateShove(Me, trunc(x), trunc(y)
   737     RateShove(Me, trunc(x), trunc(y)
   738         , 30, 30, 40
   738         , 30, 30, 40
   739         , -1, -0.8, 1);
   739         , -1, -0.8, afTrackFall);
   740 // now try opposite direction
   740 // now try opposite direction
   741 v2:= RateShove(Me, trunc(x) + 15, trunc(y)
   741 v2:= RateShove(Me, trunc(x) + 15, trunc(y)
   742         , 30, 30, 40
   742         , 30, 30, 40
   743         , 1, -0.8, 1 or fSetSkip);
   743         , 1, -0.8, afTrackFall or afSetSkip);
   744 v2:= v2 +
   744 v2:= v2 +
   745     RateShove(Me, trunc(x), trunc(y)
   745     RateShove(Me, trunc(x), trunc(y)
   746         , 30, 30, 40
   746         , 30, 30, 40
   747         , 1, -0.8, 1);
   747         , 1, -0.8, afTrackFall);
   748 
   748 
   749 if (v2 > v1) 
   749 if (v2 > v1) 
   750     or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   750     or {don't encourage turning for no gain}((v2 = v1) and (not Me^.dX.isNegative)) then
   751     begin
   751     begin
   752     ap.Angle:= 1;
   752     ap.Angle:= 1;