Skip to content

Commit 3f62408

Browse files
committed
Add some more docstrings
1 parent 78e4720 commit 3f62408

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

chessington/engine/board.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Square(namedtuple('Square', 'row col')):
2525

2626
@staticmethod
2727
def at(row, col):
28+
"""
29+
Creates a square at the given row and column.
30+
"""
2831
return Square(row=row, col=col)
2932

3033

@@ -55,19 +58,31 @@ def _create_starting_board():
5558
return board
5659

5760
def set_piece(self, square, piece):
61+
"""
62+
Places the piece at the given position on the board.
63+
"""
5864
self.board[square.row][square.col] = piece
5965

6066
def get_piece(self, square):
67+
"""
68+
Retrieves the piece from the given square of the board.
69+
"""
6170
return self.board[square.row][square.col]
6271

6372
def find_piece(self, piece_to_find):
73+
"""
74+
Searches for the given piece on the board and returns its square.
75+
"""
6476
for row in range(BOARD_SIZE):
6577
for col in range(BOARD_SIZE):
6678
if self.board[row][col] is piece_to_find:
6779
return Square.at(row, col)
6880
raise Exception('The supplied piece is not on the board')
6981

7082
def move_piece(self, from_square, to_square):
83+
"""
84+
Moves the piece from the given starting square to the given destination square.
85+
"""
7186
moving_piece = self.get_piece(from_square)
7287
if moving_piece is not None and moving_piece.player == self.current_player:
7388
self.set_piece(to_square, moving_piece)

chessington/engine/pieces.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ def __init__(self, player):
1414

1515
@abstractmethod
1616
def get_available_moves(self, board):
17+
"""
18+
Get all squares that the piece is allowed to move to.
19+
"""
1720
pass
1821

19-
def move_to(self, board, new_square):
20-
current_square = board.find_piece(self)
21-
board.move_piece(current_square, new_square)
22-
2322

2423
class Pawn(Piece):
2524
"""

0 commit comments

Comments
 (0)