@@ -25,6 +25,9 @@ class Square(namedtuple('Square', 'row col')):
25
25
26
26
@staticmethod
27
27
def at (row , col ):
28
+ """
29
+ Creates a square at the given row and column.
30
+ """
28
31
return Square (row = row , col = col )
29
32
30
33
@@ -55,19 +58,31 @@ def _create_starting_board():
55
58
return board
56
59
57
60
def set_piece (self , square , piece ):
61
+ """
62
+ Places the piece at the given position on the board.
63
+ """
58
64
self .board [square .row ][square .col ] = piece
59
65
60
66
def get_piece (self , square ):
67
+ """
68
+ Retrieves the piece from the given square of the board.
69
+ """
61
70
return self .board [square .row ][square .col ]
62
71
63
72
def find_piece (self , piece_to_find ):
73
+ """
74
+ Searches for the given piece on the board and returns its square.
75
+ """
64
76
for row in range (BOARD_SIZE ):
65
77
for col in range (BOARD_SIZE ):
66
78
if self .board [row ][col ] is piece_to_find :
67
79
return Square .at (row , col )
68
80
raise Exception ('The supplied piece is not on the board' )
69
81
70
82
def move_piece (self , from_square , to_square ):
83
+ """
84
+ Moves the piece from the given starting square to the given destination square.
85
+ """
71
86
moving_piece = self .get_piece (from_square )
72
87
if moving_piece is not None and moving_piece .player == self .current_player :
73
88
self .set_piece (to_square , moving_piece )
0 commit comments