-
Notifications
You must be signed in to change notification settings - Fork 1
/
strategy_utils.pas
56 lines (47 loc) · 1.19 KB
/
strategy_utils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
unit strategy_utils;
interface
uses
bullets,
geom,
bonus,
tanks,world,globals;
type
TTankSearchCriteria=(WEAKEST_TANK,NEAREST_TANK,POWERFUL_TANK);
TTankSearchCriterias=set of TTankSearchCriteria;
function findTank(except_tank:TTank;
SearchCriteria:TTankSearchCriterias):TTank;
implementation
function findTank(except_tank:TTank;
SearchCriteria:TTankSearchCriterias):TTank;
var minHP:integer;
i:integer;
tank:TTank;
minDist:double;
dist:double;
begin
Result:=nil;
minHP:=TANK_MAX_HP+1;
minDist:=distance(0,0,getWorld.width,getWorld.height);
for i:=0 to getworld.tanks.Count-1 do
begin
tank:=getworld.tanks.at(i);
if tank<>except_tank then
begin
if WEAKEST_TANK in SearchCriteria then
if tank.getHP<minHP then
begin
minHP:=tank.getHP;
Result:=tank;
end;
if NEAREST_TANK in SearchCriteria then
begin
dist:=distance(tank.getX,tank.getY,
except_tank.getX,
except_tank.getY);
if dist<minDist then
begin minDist:=dist; Result:=tank end;
end;
end;
end;
end;
end.