hedgewars/uAIAmmoTests.pas
author unc0rr
Tue, 20 Jun 2006 21:20:06 +0000
changeset 67 3101306251e5
parent 66 9643d75baf1e
child 70 82d93eeecebe
permissions -rw-r--r--
- 2 more Land templates - prevent generated land to be outbound
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
unit uAIAmmoTests;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     2
interface
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     3
uses SDLh, uGears, uConsts;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     4
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     5
function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     6
function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     7
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     8
type TAmmoTestProc = function (Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     9
const AmmoTests: array[TAmmoType] of TAmmoTestProc =
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    10
                 (
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    11
{amGrenade}       TestGrenade,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    12
{amBazooka}       TestBazooka,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    13
{amUFO}           nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    14
{amShotgun}       nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    15
{amPickHammer}    nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    16
{amSkip}          nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    17
{amRope}          nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    18
{amMine}          nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    19
{amDEagle}        nil,
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    20
{amDynamite}      nil
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    21
                  );
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
implementation
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    24
uses uMisc, uAIMisc;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    26
function Metric(x1, y1, x2, y2: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
begin
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    28
Result:= abs(x1 - x2) + abs(y1 - y2)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    29
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    31
function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
var Vx, Vy, r: real;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
    rTime: real;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    34
    Score: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    36
    function CheckTrace: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    37
    var x, y, dX, dY: real;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    38
        t: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
    begin
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    40
    x:= Me.X;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    41
    y:= Me.Y;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    42
    dX:= Vx;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
    dY:= -Vy;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    44
    t:= trunc(rTime);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
    repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
      x:= x + dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
      y:= y + dY;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    48
      dX:= dX + cWindSpeed;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    49
      dY:= dY + cGravity;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    50
      dec(t)
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    51
    until TestColl(round(x), round(y), 5) or (t <= 0);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    52
    Result:= RateExplosion(Me, round(x), round(y), 101) - Metric(Targ.X, Targ.Y, round(x), round(y)) div 16
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    53
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    54
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
Time:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    57
rTime:= 10;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    58
Result:= Low(integer);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    59
repeat
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    60
  rTime:= rTime + 100 + random*250;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
  Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
  Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
  r:= sqr(Vx) + sqr(Vy);
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    64
  if r <= 1 then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
     begin
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    66
     Score:= CheckTrace;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    67
     if Result <= Score then
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    68
        begin
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    69
        r:= sqrt(r);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    70
        Angle:= DxDy2AttackAngle(Vx, Vy);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    71
        Power:= round(r * cMaxPower);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    72
        Result:= Score
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    73
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
     end
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    75
until (rTime >= 5000)
39
b78e7185ed13 - Increased FPS
unc0rr
parents: 37
diff changeset
    76
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    78
function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    79
const tDelta = 10;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    80
var Vx, Vy, r: real;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    81
    Score: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    82
    TestTime: Longword;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    83
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    84
    function CheckTrace: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    85
    var x, y, dY: real;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    86
        t: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    87
    begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    88
    x:= Me.X;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    89
    y:= Me.Y;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    90
    dY:= -Vy;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    91
    t:= TestTime;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    92
    repeat
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    93
      x:= x + Vx;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    94
      y:= y + dY;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    95
      dY:= dY + cGravity;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    96
      dec(t)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    97
    until TestColl(round(x), round(y), 5) or (t = 0);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    98
    if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    99
              else Result:= Low(integer)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   100
    end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   101
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   102
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   103
Result:= Low(integer);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   104
TestTime:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   105
repeat
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   106
  inc(TestTime, 1000);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   107
  Vx:= (Targ.X - Me.X) / (TestTime + tDelta);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   108
  Vy:= cGravity*((TestTime + tDelta) div 2) - (Targ.Y - Me.Y) / (TestTime + tDelta);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   109
  r:= sqr(Vx) + sqr(Vy);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   110
  if r <= 1 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   111
     begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   112
     Score:= CheckTrace;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   113
     if Result <= Score then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   114
        begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   115
        r:= sqrt(r);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   116
        Angle:= DxDy2AttackAngle(Vx, Vy);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   117
        Power:= round(r * cMaxPower);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   118
        Time:= TestTime;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   119
        Result:= Score
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   120
        end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   121
     end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   122
until (TestTime = 5000)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   123
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   124
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   125
end.