Exemple #1
0
 def test_pawn_check(self):
     """
     Test that a pawn will put a king of the opposite color in check
     :return:
     """
     piece_positions = [('c2', 'b1'), ('a2', 'b1')]
     for positions in piece_positions:
         pawn_position, king_position = positions
         with self.subTest(pawn_position=pawn_position, king_position=king_position):
             board = ChessBoard(empty_board=True)
             board[pawn_position] = Pawn(Color.black)
             board[king_position] = King(Color.white)
             self.assertTrue(board.is_check(Color.white), 'Pawn should put king in check')
Exemple #2
0
 def test_bishop_check(self):
     """
     Test that a bishop will put a king of the opposite color in check
     :return:
     """
     piece_positions = [('a1', 'h8'), ('a8', 'h1'),
                        ('h8', 'a1'), ('h1', 'a8')]
     for positions in piece_positions:
         bishop_position, king_position = positions
         with self.subTest(bishop_position=bishop_position, king_position=king_position):
             board = ChessBoard(empty_board=True)
             board[bishop_position] = Bishop(Color.black)
             board[king_position] = King(Color.white)
             self.assertTrue(board.is_check(Color.white), 'Bishop should put king in check')
Exemple #3
0
 def test_queen_check(self):
     """
     Test that a queen will put a king of the opposite color in check
     :return:
     """
     piece_positions = [('a1', 'a8'), ('a1', 'h1'), ('a1', 'h8'),
                        ('a8', 'a1'), ('a8', 'h8'), ('a8', 'h8'),
                        ('h8', 'a1'), ('h8', 'a8'), ('h8', 'h1'),
                        ('h1', 'a1'), ('h1', 'a8'), ('h1', 'h8')]
     for positions in piece_positions:
         queen_position, king_position = positions
         with self.subTest(queen_position=queen_position, king_position=king_position):
             board = ChessBoard(empty_board=True)
             board[queen_position] = Queen(Color.black)
             board[king_position] = King(Color.white)
             self.assertTrue(board.is_check(Color.white), 'Queen should put king in check')
Exemple #4
0
 def test_knight_check(self):
     """
     Test that a knight will put a king of the opposite color in check
     :return:
     """
     piece_positions = [('a1', 'b3'), ('a1', 'c2'),
                        ('d4', 'e6'), ('d4', 'f5'),
                        ('d4', 'f3'), ('d4', 'e2'),
                        ('d4', 'c2'), ('d4', 'b3'),
                        ('d4', 'b5'), ('d4', 'c6')]
     for positions in piece_positions:
         knight_position, king_position = positions
         with self.subTest(knight_position=knight_position, king_position=king_position):
             board = ChessBoard(empty_board=True)
             board[knight_position] = Knight(Color.black)
             board[king_position] = King(Color.white)
             self.assertTrue(board.is_check(Color.white), 'Knight should put king in check')