-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlianhezuozhan.py
54 lines (41 loc) · 1.4 KB
/
lianhezuozhan.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
# Practice using modulo to loop over an array
# Choose the mix and order of units you want to summon by populating this array:
summonTypes = ['archer', 'archer', 'archer', 'archer', 'archer', 'archer', 'soldier']
def moveTo(position, fast=True):
if (hero.isReady("jump") and hero.distanceTo > 10 and fast):
hero.jumpTo(position)
else:
hero.move(position)
# pickup coin
def pickUpNearestItem():
items = hero.findItems()
nearestItem = hero.findNearest(items)
if nearestItem:
moveTo(nearestItem.pos)
def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)
def commandSoldiers():
for soldier in hero.findFriends():
enemy = hero.findNearest(hero.findEnemies())
if enemy and (soldier.type == 'archer' or soldier.type == 'soldier'):
hero.command(soldier, "attack", enemy)
def attack(target):
if target:
if (hero.distanceTo(target) > 10):
moveTo(target.pos)
elif (hero.isReady("bash")):
hero.bash(target)
elif (hero.isReady("attack")):
hero.attack(target)
else:
hero.shield()
while True:
summonTroops()
commandSoldiers()
enemy = hero.findNearest(hero.findEnemies())
if (enemy and hero.distanceTo(enemy) < 10):
attack(enemy)
else:
pickUpNearestItem()