The code needed to keep track of all the available moves for a player is as follows:
def get_all_available_moves(self, color):
result = []
for position in self.keys():
piece = self.get_piece_at(position)
if piece and piece.color == color:
moves = piece.moves_available(position)
if moves:
result.extend(moves)
return result
The description of the code is as follows:
- We have already coded the moves_available method in the previous iteration
- The preceding method simply iterates through every item in the dictionary and appends the moves_available result for every chess piece of a given color in a list named result