forked from YoungHaKim/berkeley_python_project_1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknight.py
38 lines (32 loc) · 1.91 KB
/
knight.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
from chessPiece import chessPiece
class knight():
"""Computes all possible moves for a given knight piece"""
@staticmethod
def getNormalMoves(piece, position: tuple, board: list):
"""returns list of potential non-capture moves from a given position"""
row, col = position
potential_moves = []
chessPiece.moveUpdate(2, 1, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(2, -1, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(1, 2, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(1, -2, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(-1, 2, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(-1, -2, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(-2, 1, row, col, board, potential_moves, 2)
chessPiece.moveUpdate(-2, -1, row, col, board, potential_moves, 2)
return potential_moves
@staticmethod
def getCaptureMoves(piece, position: tuple, board: list):
"""returns list of potential capture moves from a given position"""
color_sign = 1 if piece == 'N' else -1
row, col = position
potential_moves = []
chessPiece.captureUpdate(2, 1, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(2, -1, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(1, 2, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(1, -2, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(-1, 2, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(-1, -2, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(-2, 1, color_sign, row, col, board, potential_moves, 2)
chessPiece.captureUpdate(-2, -1, color_sign, row, col, board, potential_moves, 2)
return potential_moves