4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
51
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
4
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*)
|
|
33 |
|
|
34 |
unit uAI;
|
|
35 |
interface
|
|
36 |
{$INCLUDE options.inc}
|
|
37 |
procedure ProcessBot;
|
64
|
38 |
procedure FreeActionsList;
|
4
|
39 |
|
|
40 |
implementation
|
64
|
41 |
uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc;
|
4
|
42 |
|
|
43 |
var Targets: TTargets;
|
64
|
44 |
Actions, BestActions: TActions;
|
4
|
45 |
|
64
|
46 |
procedure FreeActionsList;
|
|
47 |
begin
|
|
48 |
BestActions.Count:= 0;
|
|
49 |
BestActions.Pos:= 0;
|
|
50 |
end;
|
4
|
51 |
|
64
|
52 |
procedure TestAmmos(Me: PGear);
|
|
53 |
var MyPoint: TPoint;
|
|
54 |
Time: Longword;
|
|
55 |
Angle, Power, Score: integer;
|
|
56 |
i: integer;
|
4
|
57 |
begin
|
64
|
58 |
Mypoint.x:= round(Me.X);
|
|
59 |
Mypoint.y:= round(Me.Y);
|
|
60 |
for i:= 0 to Pred(Targets.Count) do
|
|
61 |
begin
|
|
62 |
Score:= TestBazooka(MyPoint, Targets.ar[i].Point, Time, Angle, Power);
|
|
63 |
if Actions.Score + Score + Targets.ar[i].Score > BestActions.Score then
|
4
|
64 |
begin
|
64
|
65 |
BestActions:= Actions;
|
|
66 |
inc(BestActions.Score, Score + Targets.ar[i].Score);
|
|
67 |
AddAction(BestActions, aia_Weapon, Longword(amBazooka), 500);
|
|
68 |
if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
|
|
69 |
else if (Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200);
|
|
70 |
Angle:= integer(Me.Angle) - Abs(Angle);
|
|
71 |
if Angle > 0 then
|
|
72 |
begin
|
|
73 |
AddAction(BestActions, aia_Up, aim_push, 500);
|
|
74 |
AddAction(BestActions, aia_Up, aim_release, Angle)
|
|
75 |
end else if Angle < 0 then
|
48
|
76 |
begin
|
64
|
77 |
AddAction(BestActions, aia_Down, aim_push, 500);
|
|
78 |
AddAction(BestActions, aia_Down, aim_release, -Angle)
|
|
79 |
end;
|
|
80 |
AddAction(BestActions, aia_attack, aim_push, 300);
|
|
81 |
AddAction(BestActions, aia_attack, aim_release, Power);
|
|
82 |
end
|
|
83 |
end
|
|
84 |
end;
|
4
|
85 |
|
64
|
86 |
procedure Walk(Me: PGear);
|
|
87 |
begin
|
|
88 |
TestAmmos(Me)
|
|
89 |
end;
|
|
90 |
|
|
91 |
procedure Think(Me: PGear);
|
|
92 |
begin
|
|
93 |
FillTargets(Targets);
|
|
94 |
Actions.Score:= 0;
|
|
95 |
Actions.Count:= 0;
|
|
96 |
Actions.Pos:= 0;
|
|
97 |
BestActions.Score:= Low(integer);
|
|
98 |
if Targets.Count > 0 then
|
|
99 |
Walk(Me)
|
4
|
100 |
end;
|
|
101 |
|
|
102 |
procedure ProcessBot;
|
64
|
103 |
var Me: PGear;
|
4
|
104 |
begin
|
64
|
105 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
53
|
106 |
if (Gear <> nil)and((Gear.State and gstHHDriven) <> 0) and (TurnTimeLeft < 29990) then
|
4
|
107 |
begin
|
64
|
108 |
Me:= CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear;
|
|
109 |
if BestActions.Count = BestActions.Pos then Think(Me);
|
|
110 |
ProcessAction(BestActions, Me)
|
4
|
111 |
end
|
|
112 |
end;
|
|
113 |
|
|
114 |
end.
|