-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_piece_moves.py
36 lines (31 loc) · 1022 Bytes
/
generate_piece_moves.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
from gen_board import setupBags
from collections import defaultdict
import yaml
from yaml.representer import Representer
yaml.add_representer(defaultdict, Representer.represent_dict)
def printYaml(bag):
move_names = yaml.load(open('move_types.yml'))
sides = {0:'front', 1:'back'}
pieces = {
piece.name: {
sides[index]: buildMoveDict(side, move_names) for index, side in enumerate(piece.actions)
} for piece in bag
}
stream = file('yamlpieces.yaml', 'w')
yaml.dump(pieces, stream)
def buildMoveDict(action_list, move_names):
move_dict = defaultdict(list)
for action in action_list:
move_name = move_names[action[0]]
if len(action) > 2:
move_dict[move_name].append(
{
'x': action[1],
'y': action[2],
}
)
else:
move_dict['special'] = move_name
return move_dict
white_bag, black_bag, names = setupBags()
printYaml(white_bag)