def __init__(self): self.edge = 30 self.cell_size = 63 self.field = [[None for _ in range(8)] for _ in range(8)] for i in range(8): self.field[i][1] = Pawn('w', (i, 1)) self.field[i][6] = Pawn('b', (i, 6)) self.field[0][7] = Rook('b', (0, 7)) self.field[7][7] = Rook('b', (7, 7)) self.field[1][7] = Knight('b', (1, 7)) self.field[6][7] = Knight('b', (6, 7)) self.field[2][7] = Bishop('b', (2, 7)) self.field[5][7] = Bishop('b', (5, 7)) self.field[4][7] = King('b', (4, 7)) self.field[3][7] = Queen('b', (3, 7)) self.field[0][0] = Rook('w', (0, 0)) self.field[7][0] = Rook('w', (7, 0)) self.field[1][0] = Knight('w', (1, 0)) self.field[6][0] = Knight('w', (6, 0)) self.field[2][0] = Bishop('w', (2, 0)) self.field[5][0] = Bishop('w', (5, 0)) self.field[4][0] = King('w', (4, 0)) self.field[3][0] = Queen('w', (3, 0)) self.field_copy = self.field.copy() self.curr_player = 'w' self.move_history = []
def set_figures(self): for x in range(8): self.figures.append( Pawn(x, 1, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Pawn(x, 6, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Bishop(2, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Bishop(5, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Bishop(2, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Bishop(5, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Knight(1, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Knight(6, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Knight(1, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Knight(6, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Rook(0, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Rook(7, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Rook(0, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Rook(7, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( Queen(3, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( Queen(3, 7, Color.WHITE, self.width // 8, self.height // 8)) self.figures.append( King(4, 0, Color.BLACK, self.width // 8, self.height // 8)) self.figures.append( King(4, 7, Color.WHITE, self.width // 8, self.height // 8))
def chess_start(self): for figures_color in self.starting_positions: for coords in self.starting_positions[figures_color]: constructor_args = [coords[0], coords[1], 'wheat' if coords[1] == 0 or coords[1] == 1 else 'snow4'] if coords[1] == 1 or coords[1] == 6: self.all_heroes.append(Pawn(constructor_args)) else: if coords[0] == 0 or coords[0] == 7: self.all_heroes.append(Rook(constructor_args)) elif coords[0] == 1 or coords[0] == 6: self.all_heroes.append(Knight(constructor_args)) elif coords[0] == 2 or coords[0] == 5: self.all_heroes.append( Bishop(constructor_args)) elif coords[0] == 3: self.all_heroes.append(Queen(constructor_args)) else: self.all_heroes.append(King(constructor_args))
def test_check_valid_position_move_up_right(self): bishop = Bishop(4, 4, Color.BLACK) self.assertTrue(bishop.check_valid_position(1, 7, []))