def test_column_collision(): column = 5 queen1 = Queen(Position2d([column, 3])) queen2 = Queen(Position2d([column, 5])) assert queen1.isInColumnCollisionWith(queen2)
def test_row_collision(): row = 3 queen1 = Queen(Position2d([8, row])) queen2 = Queen(Position2d([3, row])) assert queen1.isInRowCollisionWith(queen2)
def findSolutions(self, rows, columns, currentColumn, pieces): for row in range(1, rows + 1): currentPiece = Queen(Position2d([currentColumn, row])) isInCollision = self.checkCollision(currentPiece, pieces) if not (isInCollision): pieces.append(currentPiece) if currentColumn < columns: self.findSolutions(rows, columns, currentColumn + 1, pieces) else: self._solutions.append(pieces.copy()) pieces.pop() else: continue
def test_not_diagonal_collision(): queen1 = Queen(Position2d([2, 2])) queen2 = Queen(Position2d([5, 4])) assert not (queen1.isInDiagonalCollisionWith(queen2))
def test_not_row_collision(): queen1 = Queen(Position2d([9, 5])) queen2 = Queen(Position2d([9, 3])) assert not (queen1.isInRowCollisionWith(queen2))
def test_not_column_collision(): queen1 = Queen(Position2d([3, 5])) queen2 = Queen(Position2d([9, 4])) assert not (queen1.isInColumnCollisionWith(queen2))
def set_up_pieces(self): self.board.houses[0][0].set_piece( Rook(BLACK, images.black_rook, self.board.houses[0][0])) self.board.houses[1][0].set_piece( Horse(BLACK, images.black_horse, self.board.houses[1][0])) self.board.houses[2][0].set_piece( Bishop(BLACK, images.black_bishop, self.board.houses[2][0])) self.board.houses[3][0].set_piece( Queen(BLACK, images.black_queen, self.board.houses[3][0])) self.board.houses[4][0].set_piece( King(BLACK, images.black_king, self.board.houses[4][0])) self.board.houses[5][0].set_piece( Bishop(BLACK, images.black_bishop, self.board.houses[5][0])) self.board.houses[6][0].set_piece( Horse(BLACK, images.black_horse, self.board.houses[6][0])) self.board.houses[7][0].set_piece( Rook(BLACK, images.black_rook, self.board.houses[7][0])) self.board.houses[0][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[0][1])) self.board.houses[1][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[1][1])) self.board.houses[2][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[2][1])) self.board.houses[3][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[3][1])) self.board.houses[4][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[4][1])) self.board.houses[5][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[5][1])) self.board.houses[6][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[6][1])) self.board.houses[7][1].set_piece( Pawn(BLACK, images.black_pawn, self.board.houses[7][1])) self.board.houses[0][7].set_piece( Rook(WHITE, images.white_rook, self.board.houses[0][7])) self.board.houses[1][7].set_piece( Horse(WHITE, images.white_horse, self.board.houses[1][7])) self.board.houses[2][7].set_piece( Bishop(WHITE, images.white_bishop, self.board.houses[2][7])) self.board.houses[3][7].set_piece( Queen(WHITE, images.white_queen, self.board.houses[3][7])) self.board.houses[4][7].set_piece( King(WHITE, images.white_king, self.board.houses[4][7])) self.board.houses[5][7].set_piece( Bishop(WHITE, images.white_bishop, self.board.houses[5][7])) self.board.houses[6][7].set_piece( Horse(WHITE, images.white_horse, self.board.houses[6][7])) self.board.houses[7][7].set_piece( Rook(WHITE, images.white_rook, self.board.houses[7][7])) self.board.houses[0][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[0][6])) self.board.houses[1][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[1][6])) self.board.houses[2][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[2][6])) self.board.houses[3][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[3][6])) self.board.houses[4][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[4][6])) self.board.houses[5][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[5][6])) self.board.houses[6][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[6][6])) self.board.houses[7][6].set_piece( Pawn(WHITE, images.white_pawn, self.board.houses[7][6]))
def movement_manager(self, selected_house, desired_house): ia_turn = False if desired_house is not None: self.board.set_selected_piece_house(selected_house) ia_turn = True position = selected_house.get_position() color_turn = self.get_turn() # verifica se há uma peça na casa if not self.checked and selected_house.get_piece( ) is not None and has_teammate(position, color_turn, self.board) and desired_house is None: selected_piece = selected_house.get_piece() # impedir que o rei em xeque faça roque if selected_piece.get_type() == KING: selected_piece.set_is_checked( self.is_checked(selected_piece.get_color())) if selected_piece.get_color() == self.get_turn(): possible_moves = selected_piece.get_possible_moves(self) self.board.clean_highlight() for possible_move in possible_moves: self.board.houses[possible_move[0]][ possible_move[1]].set_is_highlight(True) self.board.set_selected_piece_house(selected_house) else: if self.checked and not ia_turn: return self.checked = self.is_checked(self.get_turn()) # verifica se a casa clicada está realçada if selected_house.get_is_highlight() or desired_house is not None: # casa desejada desired_house = selected_house if desired_house is None else desired_house selected_house = selected_house if desired_house is None else self.board.get_selected_piece_house( ) # peca selecionada selected_piece = selected_house.get_piece() # lógica de movimentação e captura captured_piece = self.move(selected_house, desired_house) self.checked = self.is_checked(self.get_turn()) if self.checked: self.undo_move(selected_house, desired_house, captured_piece) else: if (captured_piece is not None and selected_piece.get_color() == WHITE): self.whiteCapturePieceIncator += 1 elif (captured_piece is not None and selected_piece.get_color() == BLACK): self.blackCapturePieceIncator += 1 # promocao do peao if selected_piece.get_type( ) == PAWN and selected_piece.can_be_promoted(): if selected_piece.get_color() == BLACK: queen_image = images.black_queen else: queen_image = images.white_queen queen = Queen(selected_piece.get_color(), queen_image, desired_house.get_position()) desired_house.set_piece(queen) # limpa a casa da peça selecionada self.board.set_selected_piece_house(None) # Troca o turno if not self.checked: self.switch_turn() # limpar as casas realçadas self.board.clean_highlight()