def symmetries(self):
"""returns a list of 8 GameState objects:
all reflections and rotations of the current board
does not check for duplicates
"""
copies = [self.copy() for i in range(8)]
# copies[0] is the original.
# rotate CCW 90
copies[1].board = np.rot90(self.board,1)
# rotate 180
copies[2].board = np.rot90(self.board,2)
# rotate CCW 270
copies[3].board = np.rot90(self.board,3)
# mirror left-right
copies[4].board = np.fliplr(self.board)
# mirror up-down
copies[5].board = np.flipud(self.board)
# mirror \ diagonal
copies[6].board = np.transpose(self.board)
# mirror / diagonal (equivalently: rotate 90 CCW then flip LR)
copies[7].board = np.fliplr(copies[1].board)
return copies
评论列表
文章目录