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_horse_bad(self): factor = 1 black_queen = pieces.Queen(False, 8, 8) white_horse = pieces.Horse(True, 12, 8) self.assertEqual(31, score.capture_piece(black_queen, white_horse, factor))
def test_whitehorse_valid_move_jump(self): horse = pieces.Horse(True, 8, 8) empty_square1 = pieces.EmptySquare(6, 9) # L up_right empty_square2 = pieces.EmptySquare(10, 9) # L down_right empty_square3 = pieces.EmptySquare(10, 7) # L down_left empty_square4 = pieces.EmptySquare(6, 7) # L up_left self.assertTrue(horse.valid_move(empty_square1)) self.assertTrue(horse.valid_move(empty_square2)) self.assertTrue(horse.valid_move(empty_square3)) self.assertTrue(horse.valid_move(empty_square4))
def test_whitehorse_valid_move_capture(self): horse = pieces.Horse(True, 8, 8) rival1 = pieces.Pawn(False, 6, 9) # L up_right rival2 = pieces.Pawn(False, 10, 9) # L down_right rival3 = pieces.Pawn(False, 10, 7) # L down_left rival4 = pieces.Pawn(False, 6, 7) # L up_left self.assertTrue(horse.valid_move(rival1)) self.assertTrue(horse.valid_move(rival2)) self.assertTrue(horse.valid_move(rival3)) self.assertTrue(horse.valid_move(rival4))
def test_whitehorse_invalid_move_jump(self): horse = pieces.Horse(True, 8, 8) empty_square1 = pieces.EmptySquare(7, 8) # up empty_square2 = pieces.EmptySquare(7, 9) # up_right empty_square3 = pieces.EmptySquare(8, 9) # right empty_square4 = pieces.EmptySquare(9, 9) # dow_right empty_square5 = pieces.EmptySquare(9, 8) # down empty_square6 = pieces.EmptySquare(9, 7) # down_left empty_square7 = pieces.EmptySquare(8, 7) # left empty_square8 = pieces.EmptySquare(6, 6) # up_left self.assertFalse(horse.valid_move(empty_square1)) self.assertFalse(horse.valid_move(empty_square2)) self.assertFalse(horse.valid_move(empty_square3)) self.assertFalse(horse.valid_move(empty_square4)) self.assertFalse(horse.valid_move(empty_square5)) self.assertFalse(horse.valid_move(empty_square6)) self.assertFalse(horse.valid_move(empty_square7)) self.assertFalse(horse.valid_move(empty_square8))
def test_whitehorse_invalid_move_capture(self): horse = pieces.Horse(True, 8, 8) rival1 = pieces.Pawn(False, 7, 8) # up rival2 = pieces.Pawn(False, 7, 9) # up_right rival3 = pieces.Pawn(False, 8, 9) # right rival4 = pieces.Pawn(False, 9, 9) # dow_right rival5 = pieces.Pawn(False, 9, 8) # down rival6 = pieces.Pawn(False, 9, 7) # down_left rival7 = pieces.Pawn(False, 8, 7) # left rival8 = pieces.Pawn(False, 6, 6) # up_left self.assertFalse(horse.valid_move(rival1)) self.assertFalse(horse.valid_move(rival2)) self.assertFalse(horse.valid_move(rival3)) self.assertFalse(horse.valid_move(rival4)) self.assertFalse(horse.valid_move(rival5)) self.assertFalse(horse.valid_move(rival6)) self.assertFalse(horse.valid_move(rival7)) self.assertFalse(horse.valid_move(rival8))
def test_jump_rival_horse(self): factor = -1 horse = pieces.Horse(True, 8, 8) self.assertEqual(-7, score.jump_piece(horse, factor))