def Invert(self): square = array.create2D(self._squaresize, self._squaresize, 0) for i in range(self._squaresize): for j in range(self._squaresize): square[i][j] = self.points[j][i] self.points = square self._normolize()
def __init__(self, arg): self._squaresize = 5 self.points = array.create2D(5, 5, 0) self.pointsSet = set([]) self.ID = 0 if isinstance(arg, int) and arg in range(1, 22): self.ID = arg self.ID2Points() self.Points2PointSet() elif isinstance(arg, list) and len(arg) > 0: self.points = arg self.Points2ID() self.Points2PointSet() elif isinstance(arg, set) and arg is not set([]): self.pointsSet = arg self.Pointset2Points() self.Points2ID() self.Points2PointSet() elif isinstance(arg, dict): if 'Moves' in arg: self.pointsSet = self.initPointset(arg['Moves']) self.Pointset2Points() self.Points2ID() self.Points2PointSet() else: raise
def Rotate(self): square = array.create2D(self._squaresize, self._squaresize, 0) mid = 2 for i in range(self._squaresize): for j in range(self._squaresize): square[i][j] = self.points[j][2 * mid - i] self.points = square self._normolize()
def _normolize(self): square = array.create2D(self._squaresize, self._squaresize, 0) temp_list_r = [] temp_list_l = [] for i in range(self._squaresize): for j in range(self._squaresize): if self.points[i][j] is 1: temp_list_l.append(i) temp_list_r.append(j) if bool(temp_list_l): min_l = min(temp_list_l) else: min_l = 0 if bool(temp_list_r): min_r = min(temp_list_r) else: min_r = 0 for i in range(self._squaresize - min_l): for j in range(self._squaresize - min_r): square[i][j] = self.points[i + min_l][j + min_r] self.points = square
def showChess(self, chess_pos_list): board = array.create2D(14, 14, 0) for point in chess_pos_list: board[point[0]][point[1]] = 1 array.write2D(board)
def __init__(self, size, moves={}, value=0): self.board = array.create2D(size, size, value) self.size = size self.essentialPoints = self.initEsentialPoints() self.fordidenPoints = self.initForbiddenPoints() self.styles = Style(moves)
def Pointset2Points(self): square = array.create2D(5, 5, 0) for point in self.pointsSet: square[point[0]][point[1]] = 1 self.points = square
def ID2Points(self): Style_size = self._squaresize square = array.create2D(Style_size, Style_size, 0) if self.ID == 0: pass elif self.ID == 1: square[0][0] = 1 elif self.ID == 2: square[0][0] = 1 square[0][1] = 1 elif self.ID == 3: square[0][0] = 1 square[0][1] = 1 square[0][2] = 1 elif self.ID == 4: square[0][0] = 1 square[0][1] = 1 square[1][1] = 1 elif self.ID == 5: square[0] = [1, 1, 0, 0, 0] square[1] = [1, 1, 0, 0, 0] elif self.ID == 6: square[0] = [1, 1, 1, 0, 0] square[1] = [0, 1, 0, 0, 0] elif self.ID == 7: square[0] = [1, 1, 1, 1, 0] elif self.ID == 8: square[0] = [1, 1, 1, 0, 0] square[1][0] = 1 elif self.ID == 9: square[0] = [0, 1, 1, 0, 0] square[1] = [1, 1, 0, 0, 0] elif self.ID == 10: square[0][0] = 1 square[1] = [1, 1, 1, 1, 0] elif self.ID == 11: square[0][1] = 1 square[1][1] = 1 square[2] = [1, 1, 1, 0, 0] elif self.ID == 12: square[0][0] = 1 square[1][0] = 1 square[2] = [1, 1, 1, 0, 0] elif self.ID == 13: square[0] = [0, 1, 1, 1, 0] square[1] = [1, 1, 0, 0, 0] elif self.ID == 14: square[0][2] = 1 square[1] = [1, 1, 1, 0, 0] square[2][0] = 1 elif self.ID == 15: square[0] = [1, 1, 1, 1, 1] elif self.ID == 16: square[0] = [1, 1, 1, 0, 0] square[1] = [1, 1, 0, 0, 0] elif self.ID == 17: square[0] = [0, 1, 1, 0, 0] square[1] = [1, 1, 0, 0, 0] square[2] = [1, 0, 0, 0, 0] elif self.ID == 18: square[0] = [1, 1, 0, 0, 0] square[1] = [1, 0, 0, 0, 0] square[2] = [1, 1, 0, 0, 0] elif self.ID == 19: square[0] = [0, 1, 1, 0, 0] square[1] = [1, 1, 0, 0, 0] square[2] = [0, 1, 0, 0, 0] elif self.ID == 20: square[0][1] = 1 square[1] = [1, 1, 1, 0, 0] square[2][1] = 1 elif self.ID == 21: square[0][1] = 1 square[1] = [1, 1, 1, 1, 0] else: pass self.points = square