hedgewars/uAIAmmoTests.pas
author unc0rr
Wed, 14 Jun 2006 15:50:22 +0000
changeset 64 9df467527ae5
parent 53 0e27949850e3
child 66 9643d75baf1e
permissions -rw-r--r--
- Start AI rewrite - Many small changes
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
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     3
uses SDLh;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     5
function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     6
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     7
implementation
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     8
uses uMisc, uAIMisc;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     9
const cMyHHDamageScore = -3000;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    10
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    11
function Metric(x1, y1, x2, y2: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    12
begin
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    13
Result:= abs(x1 - x2) + abs(y1 - y2)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    14
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    15
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    16
function TestBazooka(Me, Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
var Vx, Vy, r: real;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
    rTime: real;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    19
    Score: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    21
    function CheckTrace: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
    var x, y, dX, dY: real;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
        t: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
    begin
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    25
    x:= Me.X;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    26
    y:= Me.Y;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
    dX:= Vx;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
    dY:= -Vy;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    29
    t:= trunc(rTime);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
    repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
      x:= x + dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
      y:= y + dY;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
      dX:= dX + cWindSpeed;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
      dY:= dY + cGravity;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
      dec(t)
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    36
    until TestColl(round(x), round(y), 5) or (t <= 0);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    37
    if NoMyHHNear(round(x), round(y), 110) then
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    38
         Result:= - Metric(round(x), round(y), Targ.x, Targ.y) div 16
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    39
    else Result:= cMyHHDamageScore;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    42
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
Time:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
rTime:= 10;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    45
Result:= Low(integer);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
repeat
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    47
  rTime:= rTime + 70 + random*200;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    48
  Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    49
  Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    50
  r:= sqr(Vx) + sqr(Vy);
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    51
  if r <= 1 then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
     begin
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    53
     Score:= CheckTrace;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    54
     if Result <= Score then
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    55
        begin
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    56
        r:= sqrt(r);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    57
        Angle:= DxDy2AttackAngle(Vx, Vy);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    58
        Power:= round(r * cMaxPower);
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    59
        Result:= Score
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    60
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
     end
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    62
until (rTime >= 5000)
39
b78e7185ed13 - Increased FPS
unc0rr
parents: 37
diff changeset
    63
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
end.