hedgewars/uAIAmmoTests.pas
changeset 498 9c8b385dc9a1
parent 439 c336ed82e76d
child 509 fd58135a4407
equal deleted inserted replaced
497:adf1aee202c6 498:9c8b385dc9a1
    61 Metric:= abs(x1 - x2) + abs(y1 - y2)
    61 Metric:= abs(x1 - x2) + abs(y1 - y2)
    62 end;
    62 end;
    63 
    63 
    64 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    64 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
    65 var Vx, Vy, r: hwFloat;
    65 var Vx, Vy, r: hwFloat;
    66     rTime: hwFloat;
    66     rTime: LongInt;
    67     Score, EX, EY: LongInt;
    67     Score, EX, EY: LongInt;
    68     Result: LongInt;
    68     Result: LongInt;
    69 
    69 
    70     function CheckTrace: LongInt;
    70     function CheckTrace: LongInt;
    71     var x, y, dX, dY: hwFloat;
    71     var x, y, dX, dY: hwFloat;
    74     begin
    74     begin
    75     x:= Me^.X;
    75     x:= Me^.X;
    76     y:= Me^.Y;
    76     y:= Me^.Y;
    77     dX:= Vx;
    77     dX:= Vx;
    78     dY:= -Vy;
    78     dY:= -Vy;
    79     t:= hwRound(rTime);
    79     t:= rTime;
    80     repeat
    80     repeat
    81       x:= x + dX;
    81       x:= x + dX;
    82       y:= y + dY;
    82       y:= y + dY;
    83       dX:= dX + cWindSpeed;
    83       dX:= dX + cWindSpeed;
    84       dY:= dY + cGravity;
    84       dY:= dY + cGravity;
    96 rTime:= 350;
    96 rTime:= 350;
    97 ExplR:= 0;
    97 ExplR:= 0;
    98 Result:= BadTurn;
    98 Result:= BadTurn;
    99 repeat
    99 repeat
   100   rTime:= rTime + 300 + Level * 50 + random(300);
   100   rTime:= rTime + 300 + Level * 50 + random(300);
   101   Vx:= - cWindSpeed * rTime * _0_5 + (Targ.X - hwRound(Me^.X)) / rTime;
   101   Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(rTime);
   102   Vy:= cGravity * rTime * _0_5 - (Targ.Y - hwRound(Me^.Y)) / rTime;
   102   Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime);
   103   r:= Distance(Vx, Vy);
   103   r:= Distance(Vx, Vy);
   104   if not (r > 1) then
   104   if not (r > _1) then
   105      begin
   105      begin
   106      Score:= CheckTrace;
   106      Score:= CheckTrace;
   107      if Result <= Score then
   107      if Result <= Score then
   108         begin
   108         begin
   109         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   109         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   148 Result:= BadTurn;
   148 Result:= BadTurn;
   149 TestTime:= 0;
   149 TestTime:= 0;
   150 ExplR:= 0;
   150 ExplR:= 0;
   151 repeat
   151 repeat
   152   inc(TestTime, 1000);
   152   inc(TestTime, 1000);
   153   Vx:= (Targ.X - Me^.X) / (TestTime + tDelta);
   153   Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta);
   154   Vy:= cGravity * ((TestTime + tDelta) div 2) - (Targ.Y - Me^.Y) / (TestTime + tDelta);
   154   Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta);
   155   r:= Distance(Vx, Vy);
   155   r:= Distance(Vx, Vy);
   156   if not (r > 1) then
   156   if not (r > _1) then
   157      begin
   157      begin
   158      Score:= CheckTrace;
   158      Score:= CheckTrace;
   159      if Result < Score then
   159      if Result < Score then
   160         begin
   160         begin
   161         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
   161         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
   178 ExplR:= 0;
   178 ExplR:= 0;
   179 Time:= 0;
   179 Time:= 0;
   180 Power:= 1;
   180 Power:= 1;
   181 if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
   181 if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
   182    exit(BadTurn);
   182    exit(BadTurn);
   183 Vx:= (Targ.X - Me^.X) * _1div1024;
   183 Vx:= (int2hwFloat(Targ.X) - Me^.X) * _1div1024;
   184 Vy:= (Targ.Y - Me^.Y) * _1div1024;
   184 Vy:= (int2hwFloat(Targ.Y) - Me^.Y) * _1div1024;
   185 x:= Me^.X;
   185 x:= Me^.X;
   186 y:= Me^.Y;
   186 y:= Me^.Y;
   187 Angle:= DxDy2AttackAngle(Vx, -Vy);
   187 Angle:= DxDy2AttackAngle(Vx, -Vy);
   188 repeat
   188 repeat
   189   x:= x + vX;
   189   x:= x + vX;
   195      Result:= RateShove(Me, rx, ry, 25, 25) * 2;
   195      Result:= RateShove(Me, rx, ry, 25, 25) * 2;
   196      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
   196      if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
   197                    else dec(Result, Level * 4000);
   197                    else dec(Result, Level * 4000);
   198      exit(Result)
   198      exit(Result)
   199      end
   199      end
   200 until (hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
   200 until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x < _0) or (y < _0) or (x > _2048) or (y > _1024);
   201 TestShotgun:= BadTurn
   201 TestShotgun:= BadTurn
   202 end;
   202 end;
   203 
   203 
   204 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   204 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   205 var Vx, Vy, x, y, t: hwFloat;
   205 var Vx, Vy, x, y, t: hwFloat;
   207     Result: LongInt;
   207     Result: LongInt;
   208 begin
   208 begin
   209 ExplR:= 0;
   209 ExplR:= 0;
   210 Time:= 0;
   210 Time:= 0;
   211 Power:= 1;
   211 Power:= 1;
   212 if hwAbs(Me^.X - Targ.X) + hwAbs(Me^.Y - Targ.Y) < 80 then
   212 if Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) < 80 then
   213    exit(BadTurn);
   213    exit(BadTurn);
   214 t:= _0_5 / Distance(Targ.X - Me^.X, Targ.Y - Me^.Y);
   214 t:= _0_5 / Distance(int2hwFloat(Targ.X) - Me^.X, int2hwFloat(Targ.Y) - Me^.Y);
   215 Vx:= (Targ.X - Me^.X) * t;
   215 Vx:= (int2hwFloat(Targ.X) - Me^.X) * t;
   216 Vy:= (Targ.Y - Me^.Y) * t;
   216 Vy:= (int2hwFloat(Targ.Y) - Me^.Y) * t;
   217 x:= Me^.X;
   217 x:= Me^.X;
   218 y:= Me^.Y;
   218 y:= Me^.Y;
   219 Angle:= DxDy2AttackAngle(Vx, -Vy);
   219 Angle:= DxDy2AttackAngle(Vx, -Vy);
   220 d:= 0;
   220 d:= 0;
   221 repeat
   221 repeat
   222   x:= x + vX;
   222   x:= x + vX;
   223   y:= y + vY;
   223   y:= y + vY;
   224   if ((hwRound(x) and $FFFFF800) = 0)and((hwRound(y) and $FFFFFC00) = 0)
   224   if ((hwRound(x) and $FFFFF800) = 0)and((hwRound(y) and $FFFFFC00) = 0)
   225      and (Land[hwRound(y), hwRound(x)] <> 0) then inc(d);
   225      and (Land[hwRound(y), hwRound(x)] <> 0) then inc(d);
   226 until (hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024) or (d > 200);
   226 until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x < _0) or (y < _0) or (x > _2048) or (y > _1024) or (d > 200);
   227 if hwAbs(Targ.X - x) + hwAbs(Targ.Y - y) < 2 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   227 if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then Result:= max(0, (4 - d div 50) * 7 * 1024)
   228                                              else Result:= Low(LongInt);
   228                                                            else Result:= Low(LongInt);
   229 TestDesertEagle:= Result
   229 TestDesertEagle:= Result
   230 end;
   230 end;
   231 
   231 
   232 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   232 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   233 var Result: LongInt;
   233 var Result: LongInt;
   234 begin
   234 begin
   235 ExplR:= 0;
   235 ExplR:= 0;
   236 if (Level > 2) and not (hwAbs(Me^.X - Targ.X) + hwAbs(Me^.Y - Targ.Y) < 25) then
   236 if (Level > 2) and not (Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) < 25) then
   237    exit(BadTurn);
   237    exit(BadTurn);
   238 
   238 
   239 Time:= 0;
   239 Time:= 0;
   240 Power:= 1;
   240 Power:= 1;
   241 Angle:= DxDy2AttackAngle(hwSign(Targ.X - Me^.X), 1);
   241 if (Targ.X) - hwRound(Me^.X) >= 0 then Angle:=   cMaxAngle div 4
   242 Result:= RateShove(Me, hwRound(Me^.X) + 10 * hwSign(Targ.X - Me^.X), hwRound(Me^.Y), 15, 30);
   242                                   else Angle:= - cMaxAngle div 4;
       
   243 Result:= RateShove(Me, hwRound(Me^.X) + 10 * hwSign(int2hwFloat(Targ.X) - Me^.X), hwRound(Me^.Y), 15, 30);
   243 if Result <= 0 then Result:= BadTurn else inc(Result);
   244 if Result <= 0 then Result:= BadTurn else inc(Result);
   244 TestBaseballBat:= Result
   245 TestBaseballBat:= Result
   245 end;
   246 end;
   246 
   247 
   247 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   248 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   249 begin
   250 begin
   250 ExplR:= 0;
   251 ExplR:= 0;
   251 Time:= 0;
   252 Time:= 0;
   252 Power:= 1;
   253 Power:= 1;
   253 Angle:= 0;
   254 Angle:= 0;
   254 if (hwAbs(Me^.X - Targ.X) > 25) or (hwAbs(Me^.Y - 50 - Targ.Y) > 50) then
   255 if (Abs(hwRound(Me^.X) - Targ.X) > 25) or (Abs(hwRound(Me^.Y) - 50 - Targ.Y) > 50) then
   255    exit(BadTurn);
   256    exit(BadTurn);
   256 
   257 
   257 Result:= 0;
   258 Result:= 0;
   258 for i:= 0 to 4 do
   259 for i:= 0 to 4 do
   259     Result:= Result + RateShove(Me, hwRound(Me^.X) + 10 * hwSign(Targ.X - Me^.X), hwRound(Me^.Y) - 20 * i - 5, 10, 30);
   260     Result:= Result + RateShove(Me, hwRound(Me^.X) + 10 * hwSign(int2hwFloat(Targ.X) - Me^.X),
       
   261                                     hwRound(Me^.Y) - 20 * i - 5, 10, 30);
   260 if Result <= 0 then Result:= BadTurn else inc(Result);
   262 if Result <= 0 then Result:= BadTurn else inc(Result);
   261 TestFirePunch:= Result
   263 TestFirePunch:= Result
   262 end;
   264 end;
   263 
   265 
   264 end.
   266 end.