-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchessassets.py
More file actions
57 lines (52 loc) · 1.64 KB
/
chessassets.py
File metadata and controls
57 lines (52 loc) · 1.64 KB
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
"""reverse chess objects used globally"""
PTYPES = ['p', 'k', 'r', 'b', 'q', 'n']
IMAGES = {}
for team in ['b', 'w']:
for ptype in PTYPES:
for boo in (True, False):
IMAGES[(team, ptype, boo)] = './chessimages/'+team+'_'
IMAGES[(team, 'p', False)] += 'pawn.png'
IMAGES[(team, 'p', True)] += 'pawn_p.png'
IMAGES[(team, 'k', False)] += 'king.png'
IMAGES[(team, 'r', False)] += 'rook.png'
IMAGES[(team, 'r', True)] += 'rook_p.png'
IMAGES[(team, 'b', False)] += 'bishop.png'
IMAGES[(team, 'b', True)] += 'bishop_p.png'
IMAGES[(team, 'q', False)] += 'queen.png'
IMAGES[(team, 'q', True)] += 'queen_p.png'
IMAGES[(team, 'n', False)] += 'knight.png'
IMAGES[(team, 'n', True)] += 'knight_p.png'
def offboard_count(pieces):
"""count the pieces not on the board
of a specific team
"""
ret = {}
for piece in pieces:
ptype = piece.ptype if not piece.promoted else 'p'
if ptype not in ret:
ret[ptype] = 0
if not piece.ontheboard:
ret[ptype] += 1
if 'q' in ret:
assert ret['q'] <= 1, ret
if 'k' in ret:
assert ret['k'] <= 1, ret
if 'b' in ret:
assert ret['b'] <= 2, ret
if 'r' in ret:
assert ret['r'] <= 2, ret
if 'n' in ret:
assert ret['n'] <= 2, ret
return ret
def onboard_count(pieces):
"""count the pieces not on the board
of a specific team
"""
ret = {}
for piece in pieces:
ptype = piece.ptype if not piece.promoted else 'p'
if ptype not in ret:
ret[ptype] = 0
if piece.ontheboard:
ret[ptype] += 1
return ret