-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprioritizer.py
executable file
·146 lines (137 loc) · 6.8 KB
/
prioritizer.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import AI
import random
CLAW, ARCHER, REPAIRER, HACKER, TURRET, WALL, TERMINATOR, HANGAR = range(8)
def findDroids(x,y,radius,team,droids):
found = []
for droid in droids:
if ((droid.owner == team and droid.hackedTurnsLeft <= 0) or (droid.owner != team and droid.hackedTurnsLeft > 0)) and (radius >= (abs(x-droid.x)+abs(y-droid.y)))and droid.healthLeft > 0:
found.append(((abs(x-droid.x)+abs(y-droid.y)),droid))
found.sort()
retlist = []
for _,i in found:
retlist.append(i)
return retlist
def pickTargetClaw(droid,AI):
targetDroids = findDroids(droid.x,droid.y,5,1-AI.playerID,AI.droids)
if (len(targetDroids) > 0):
for targetDroid in targetDroids:
if targetDroid.variant == ARCHER:
return targetDroid.x,targetDroid.y
return targetDroids[0].x,targetDroids[0].y
else:
targetDroids = findDroids(droid.x,droid.y,AI.getMapHeight()+AI.getMapWidth(),1-AI.playerID,AI.droids)
if (len(targetDroids) > 0):
return targetDroids[0].x,targetDroids[0].y
else:
#return droid.x+ 4*(-2*AI.playerID+1),droid.y
return AI.getMapWidth()/2, AI.getMapHeight()/2
def pickTargetArcher(droid,AI):
targetDroids = findDroids(droid.x,droid.y,5,1-AI.playerID,AI.droids)
if (len(targetDroids) > 0):
for targetDroid in targetDroids:
if targetDroid.variant == HACKER:
return targetDroid.x,targetDroid.y
lowest = targetDroids[0]
lowestrating = targetDroids[0].armor*targetDroids[0].healthLeft
for targetDroid in targetDroids:
if lowestrating > targetDroid.armor*targetDroid.healthLeft:
lowest = targetDroid
lowestrating = targetDroid.armor*targetDroid.healthLeft
return lowest.x,lowest.y
else:
targetDroids = findDroids(droid.x,droid.y,AI.getMapHeight()+AI.getMapWidth(),1-AI.playerID,AI.droids)
# if (len(targetDroids) > 0):
# for targetDroid in targetDroids:
# if (targetDroid.variant == TERMINATOR) and ((droid.owner == 0 and targetDroid.x > droid.x) or (droid.owner == 1 and targetDroid.x < droid.x)):
# return targetDroid.x + 2*(2*AI.playerID-1),targetDroid.y
# return AI.getMapWidth()/2, AI.getMapHeight()/2
if (len(targetDroids) > 0):
return targetDroids[0].x,targetDroids[0].y
else:
return AI.getMapWidth()/2, AI.getMapHeight()/2
def pickTargetTerminator(droid,AI):
targetDroids = findDroids(droid.x,droid.y,2,1-AI.playerID,AI.droids)
if (len(targetDroids) > 0):
for targetDroid in targetDroids:
if targetDroid.variant == TURRET:
return targetDroid.x,targetDroid.y
for targetDroid in targetDroids:
if targetDroid.variant == HANGAR:
return targetDroid.x,targetDroid.y
for targetDroid in targetDroids:
if targetDroid.variant == HACKER:
return targetDroid.x,targetDroid.y
lowest = targetDroids[0]
lowestrating = targetDroids[0].armor*targetDroids[0].healthLeft
for targetDroid in targetDroids:
if lowestrating > targetDroid.armor*targetDroid.healthLeft:
lowest = targetDroid
lowestrating = targetDroid.armor*targetDroid.healthLeft
return lowest.x,lowest.y
else:
targetDroids = findDroids(droid.x,droid.y,AI.getMapHeight()+AI.getMapWidth(),1-AI.playerID,AI.droids)
if (len(targetDroids) > 0):
for targetDroid in targetDroids:
if targetDroid.variant == HANGAR:
return targetDroid.x,targetDroid.y
return targetDroids[0].x,targetDroids[0].y
else:
#return droid.x+ 4*(-2*AI.playerID+1),droid.y
return AI.getMapWidth()/2, AI.getMapHeight()/2
def pickTargetRepair(droid,AI):
possibleDroids = findDroids(droid.x,droid.y,4,AI.playerID,AI.droids)
for targetDroid in possibleDroids:
if targetDroid.armor != targetDroid.maxArmor and targetDroid.variant == TURRET:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.armor != targetDroid.maxArmor and targetDroid.variant == TERMINATOR:
return targetDroid.x,targetDroid.y
#for targetDroid in possibleDroids:
# if targetDroid.armor != targetDroid.maxArmor:
# return targetDroid.x,targetDroid.y
possibleDroids = findDroids(droid.x,droid.y,AI.getMapHeight()+AI.getMapWidth(),AI.playerID,AI.droids)
for targetDroid in possibleDroids:
if targetDroid.armor != targetDroid.maxArmor and targetDroid.variant == TURRET:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.armor != targetDroid.maxArmor and targetDroid.variant == TERMINATOR:
return targetDroid.x,targetDroid.y
#for targetDroid in possibleDroids:
# if targetDroid.armor != targetDroid.maxArmor:
# return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.armor != targetDroid.maxArmor:
return targetDroid.x,targetDroid.y
return -1,-1
def pickTargetHacker(droid,AI):
possibleDroids = findDroids(droid.x,droid.y,4,1-AI.playerID,AI.droids)
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and targetDroid.variant == CLAW:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and targetDroid.variant == TERMINATOR:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and (targetDroid.variant != HANGAR and targetDroid.variant != WALL and targetDroid.variant != TURRET):
return targetDroid.x,targetDroid.y
possibleDroids = findDroids(droid.x,droid.y,AI.getMapHeight()+AI.getMapWidth(),1-AI.playerID,AI.droids)
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and targetDroid.variant == CLAW:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and targetDroid.variant == TERMINATOR:
return targetDroid.x,targetDroid.y
for targetDroid in possibleDroids:
if targetDroid.hackedTurnsLeft == 0 and (targetDroid.variant != HANGAR and targetDroid.variant != WALL and targetDroid.variant != TURRET):
return targetDroid.x,targetDroid.y
return -1,-1
def pickTargetTurret(droid,AI):
highestAttack = -1
x = -1
y = -1
for targetDroid in findDroids(droid.x,droid.y,3,1-AI.playerID,AI.droids):
if targetDroid.attack > highestAttack:
highestAttack = targetDroid.attack
x = targetDroid.x
y = targetDroid.y
return x,y