def complete_matrix_pieces(self): for row, pieces_row in enumerate(self.matrix): for col, piece in enumerate(pieces_row): # Creates a list with black pieces if piece == '♟': black_pawn = pieces.Pawn(False, row, col) self.matrix_pieces[row][col] = black_pawn elif piece == '♞': black_horse = pieces.Horse(False, row, col) self.matrix_pieces[row][col] = black_horse elif piece == '♝': black_bishop = pieces.Bishop(False, row, col) self.matrix_pieces[row][col] = black_bishop elif piece == '♜': black_rook = pieces.Rook(False, row, col) self.matrix_pieces[row][col] = black_rook elif piece == '♛': black_queen = pieces.Queen(False, row, col) self.matrix_pieces[row][col] = black_queen elif piece == '♚': black_king = pieces.King(False, row, col) self.matrix_pieces[row][col] = black_king # Creates a list with white pieces elif piece == '♙': white_pawn = pieces.Pawn(True, row, col) self.matrix_pieces[row][col] = white_pawn elif piece == '♘': white_horse = pieces.Horse(True, row, col) self.matrix_pieces[row][col] = white_horse elif piece == '♗': white_bishop = pieces.Bishop(True, row, col) self.matrix_pieces[row][col] = white_bishop elif piece == '♖': white_rook = pieces.Rook(True, row, col) self.matrix_pieces[row][col] = white_rook elif piece == '♕': white_queen = pieces.Queen(True, row, col) self.matrix_pieces[row][col] = white_queen elif piece == '♔': white_king = pieces.King(True, row, col) self.matrix_pieces[row][col] = white_king # Creates a list with empty squares else: empty_square = pieces.EmptySquare(row, col) self.matrix_pieces[row][col] = empty_square
def test_capture_piece_bishop_bad(self): factor = 1 black_queen = pieces.Queen(False, 8, 8) white_bishop = pieces.Bishop(True, 12, 8) self.assertEqual( 41, score.capture_piece(black_queen, white_bishop, factor))
def test_scan_bishop(self): new_score = score.Score() bishop = pieces.Bishop(False, 1, 14) moves = [{'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': -8}, {'from_row': 1, 'from_col': 14, 'to_row': 2, 'to_col': 13, 'score': -97}, {'from_row': 1, 'from_col': 14, 'to_row': 0, 'to_col': 13, 'score': -8}] up = scans.scan_up(self.actual_board, bishop) up_right = scans.scan_up_right(self.actual_board, bishop) right = scans.scan_right(self.actual_board, bishop) down_right = scans.scan_down_right(self.actual_board, bishop) down = scans.scan_down(self.actual_board, bishop) down_left = scans.scan_down_left(self.actual_board, bishop) left = scans.scan_left(self.actual_board, bishop) up_left = scans.scan_up_left(self.actual_board, bishop) L = scans.scan_L(self.actual_board, bishop) player.scan(new_score, up, bishop, True) player.scan(new_score, up_right, bishop, True) player.scan(new_score, right, bishop, True) player.scan(new_score, down_right, bishop, True) player.scan(new_score, down, bishop, True) player.scan(new_score, down_left, bishop, True) player.scan(new_score, left, bishop, True) player.scan(new_score, up_left, bishop, True) player.scan(new_score, L, bishop, True) self.assertEqual(moves, new_score.play_moves)
def test_whitebishop_invalid_move_jump(self): bishop = pieces.Bishop(True, 7, 7) empty_square1 = pieces.EmptySquare(6, 7) # up empty_square2 = pieces.EmptySquare(7, 9) # right empty_square3 = pieces.EmptySquare(11, 7) # down empty_square4 = pieces.EmptySquare(7, 1) # left self.assertFalse(bishop.valid_move(empty_square1)) self.assertFalse(bishop.valid_move(empty_square2)) self.assertFalse(bishop.valid_move(empty_square3)) self.assertFalse(bishop.valid_move(empty_square4))
def test_whitebishop_valid_move_jump(self): bishop = pieces.Bishop(True, 7, 7) empty_square1 = pieces.EmptySquare(3, 3) # up_left empty_square2 = pieces.EmptySquare(5, 9) # up_right empty_square3 = pieces.EmptySquare(11, 11) # down_right empty_square4 = pieces.EmptySquare(8, 6) # down_left self.assertTrue(bishop.valid_move(empty_square1)) self.assertTrue(bishop.valid_move(empty_square2)) self.assertTrue(bishop.valid_move(empty_square3)) self.assertTrue(bishop.valid_move(empty_square4))
def test_whitebishop_invalid_move_capture(self): bishop = pieces.Bishop(True, 7, 7) rival1 = pieces.Pawn(False, 6, 7) # up rival2 = pieces.Pawn(False, 7, 9) # right rival3 = pieces.Pawn(False, 11, 7) # down rival4 = pieces.Pawn(False, 7, 1) # left self.assertFalse(bishop.valid_move(rival1)) self.assertFalse(bishop.valid_move(rival2)) self.assertFalse(bishop.valid_move(rival3)) self.assertFalse(bishop.valid_move(rival4))
def test_whitebishop_valid_move_capture(self): bishop = pieces.Bishop(True, 7, 7) rival1 = pieces.Pawn(False, 3, 3) # up_left rival2 = pieces.Pawn(False, 5, 9) # up_right rival3 = pieces.Pawn(False, 11, 11) # down_right rival4 = pieces.Pawn(False, 8, 6) # down_left self.assertTrue(bishop.valid_move(rival1)) self.assertTrue(bishop.valid_move(rival2)) self.assertTrue(bishop.valid_move(rival3)) self.assertTrue(bishop.valid_move(rival4))
def test_jump_rival_bishop(self): factor = -1 bishop = pieces.Bishop(True, 8, 8) self.assertEqual(-8, score.jump_piece(bishop, factor))