-
Notifications
You must be signed in to change notification settings - Fork 0
/
act.py
53 lines (40 loc) · 1.55 KB
/
act.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
from error import GameError, IllegalMovement
from owned import friendly
from xselect import select
from seed import context,ids
#TODO:
# legal moves: s/leaf/node with free pad/
# from friendly non-leaf to any friendly node
# from friendly leaf to friendly non-leaf
# from friendly leaf to opposing leaf if not engaged in battle
# from opposing leaf to friendly leaf
def move_creatures(player, creatures, building):
""" Move all of @creatures to @building."""
if any(getattr(c, 'owner', None) != player):
raise IllegalMovement("Player does control all creatues")
is_attack = not friendly(building, creatures[0])
# To move to a opposing building a free pad is required
if is_attack and not len(building.free_pads()) > 0:
raise IllegalMovement("No free pads")
# Should the entire movement be aborted if one creature fails its pre-move check?
creatures = [x for x in creatures if x.run_hook('pre-move', building)[0]]
creatures = filter(None, map(lambda x: x.position.remove_creature(x), creatures))
creatures = filter(None, map(lambda x: building.add_creature(x), creatures))
for x in creatures:
x.position = building
def cast_spell(player, spell, targets):
if spell not in player.focused:
raise GameError("Spell not focused")
tmp = {
'self' : player,
'opponent' : None
}
tmp.update(ids)
for k,v in targets.items():
try:
help, dv = spell._desc[k]
except KeyError:
raise GameError("Unknown target name (%s)" % k)
if v not in select(dv, context, IDs = tmp):
raise GameError("Illegal target %s" % v)
player.cast_spell(spell, targets)