-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpieces.py
61 lines (43 loc) · 1.14 KB
/
pieces.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
import sys
SHORT_NAME = {
'R': 'Rook',
'N': 'Knight',
'B': 'Bishop',
'Q': 'Queen',
'K': 'King',
'P': 'Pawn'
}
def makePiece(piece, colour='white'):
if piece in (None, ' '):
return
if len(piece) == 1:
# CHecks if the the name is lower case letter, if it is then it is a black piece
if not piece.isupper():
colour = 'black'
else:
colour = 'white'
piece = SHORT_NAME[piece.upper()]
module = sys.modules[__name__]
return module.__dict__[piece](colour)
class Piece(object):
def __init__(self, colour):
if colour == 'white':
self.shortname = self.shortname.upper()
elif colour == 'black':
self.shortname = self.shortname.lower()
self.colour = colour
def place(self, board):
# Tracks the board
self.board = board
class Rook(Piece):
shortname = 'r'
class Knight(Piece):
shortname = 'n'
class Bishop(Piece):
shortname = 'b'
class Queen(Piece):
shortname = 'q'
class King(Piece):
shortname = 'k'
class Pawn(Piece):
shortname = 'p'