forked from marcusbuffett/command-line-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.py
More file actions
29 lines (23 loc) · 932 Bytes
/
Knight.py
File metadata and controls
29 lines (23 loc) · 932 Bytes
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
from Piece import Piece
from Coordinate import Coordinate as C
from Move import Move
WHITE = True
BLACK = False
class Knight (Piece) :
stringRep = 'N'
value = 3
def __init__(self, board, side, position, movesMade=0) :
super(Knight, self).__init__(board, side, position)
self.movesMade = movesMade
def getPossibleMoves(self) :
board = self.board
currentPos = self.position
movements = [C(2, 1), C(2, -1), C(-2, 1), C(-2, -1), C(1, 2), C(1, -2), C(-1, -2), C(-1, 2)]
for movement in movements :
newPos = currentPos + movement
if board.isValidPos(newPos) :
pieceAtNewPos = board.pieceAtPosition(newPos)
if pieceAtNewPos is None :
yield Move(self, newPos)
elif pieceAtNewPos.side != self.side :
yield Move(self, newPos, pieceToCapture = pieceAtNewPos)