-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.py
85 lines (74 loc) · 2.21 KB
/
level.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
from numchess import *
__all__ = ['LEVELS', 'get_level_name', 'get_level', 'LEVEL_BOARDS']
LEVELS = [
(
'pawns',
[
None, None, None, None,
Piece(5), None, None, None,
Piece(0), Piece(0), Piece(0), Piece(0),
Piece(0), Piece(0), Piece(0), Piece(0),
]
),
(
'pawns and queen',
[
None, None, None, Piece(4),
Piece(5), None, None, None,
Piece(0), Piece(0), Piece(0), Piece(0),
Piece(0), Piece(0), Piece(0), Piece(0),
]
),
(
'major',
[
Piece(3), None, None, Piece(4),
Piece(5), None, None, Piece(3),
Piece(0), Piece(0), Piece(0), Piece(0),
Piece(0), Piece(0), Piece(0), Piece(0),
]
),
(
'horsey',
[
Piece(3), Piece(1), None, Piece(4),
Piece(5), None, Piece(1), Piece(3),
Piece(0), Piece(0), Piece(0), Piece(0),
Piece(0), Piece(0), Piece(0), Piece(0),
]
),
(
'full army',
[
Piece(3), Piece(1), Piece(2), Piece(4),
Piece(5), Piece(2), Piece(1), Piece(3),
Piece(0), Piece(0), Piece(0), Piece(0),
Piece(0), Piece(0), Piece(0), Piece(0),
]
)
]
def get_level_name(index) -> str:
return LEVELS[index][0]
def get_level(index) -> Board:
pieces = [
(setattr(piece, 'color', BLACK),
piece)[-1] if piece is not None
else None for piece in LEVELS[index][1]
]
board = Board()
for rank in range(len(pieces) // 8):
for file in range(8):
piece = pieces[rank * 8 + file]
if piece is not None:
board.set_piece_at((7 - rank, file), piece)
king_file = board.king(BLACK)[1]
for file in range(king_file - 1, 8):
if board.rooks[7, file]:
board.castling_rights |= BB_SQUARES[SQUARES.index((7, file))]
break
for file in range(king_file - 1, -1, -1):
if board.rooks[7, file]:
board.castling_rights |= BB_SQUARES[SQUARES.index((7, file))]
break
return board
LEVEL_BOARDS = [get_level(i) for i in range(len(LEVELS))]