i ll send u a question based on checking cheks in chess
try coding that in python ,
here is the question,

Problem 2: Check for Checks;
Source Module: checkChessCheck
Test Module: checkT est
Given a board position in chess, check if either the white king or the black
king is under check from one of the opposite color pieces.
• Input: A legal board position in chess — this is given as a list of lists
where both the main list and the sublists, each has exactly 8 elements.
Each sublist represents a row of the chess board. At the beginning of the
game the black pieces would have occupied rows 0 and 1 and the white
pieces would have occupied rows 6 and 7. White pieces are named with
upper case letters and black pieces with lower case. The alphabets used
for the different chess pieces are given below:
1. .: Blank (unoccupied) square
2. k, K: King
2
3. p, P: Pawn
4. b, B: Bishop
5. n, N: Knight
6. r, R: Rook
7. q, Q: Queen
• Output: A tuple (k, attacker, attacker_x, attacker_y) that gives
the king (black or white) which is under check, the identity of the attacker
and position of the attacker x - row, y - col). If no king is under attack in
the current board position then output None.

import unittest
from testgenDecorator import for_examples
from checkChessCheck import check_check, check_knight_attack, find_kings, check_pawn_attack

class TestChessCheck(unittest.TestCase):

    @for_examples(([['r','n','b','q','k','b','n','r'],
                    ['p','p','p','p','p','p','p','p'],
                    ['.','.','.','.','.','.','.','.'],
                    ['.','.','.','.','.','.','.','.'],
                    ['.','.','.','.','.','.','.','.'],
                    ['.','.','.','.','.','.','.','.'],
                    ['P','P','P','P','P','P','P','P'],
                    ['R','N','B','Q','K','B','N','R']], (0,4), (7,4), None),

                  ([['r','.','b','q','k','b','n','r'],
                    ['p','p','p','p','.','p','p','p'],
                    ['.','.','n','.','.','.','.','.'],
                    ['.','.','.','.','p','.','.','.'],
                    ['.','.','.','.','P','.','.','.'],
                    ['.','.','.','.','.','N','.','.'],
                    ['P','P','P','P','.','P','P','P'],
                    ['R','N','B','Q','K','B','.','R']], (0,4), (7,4), None))
    def testNoCheck(self, board, black_king, white_king, knight_check):
        '''
        Test for knight checks
        '''
        kings = find_kings(board)
        self.assertEqual(kings['k'], black_king)
        self.assertEqual(kings['K'], white_king)
        check = check_check(board)
        self.assertEqual(check, knight_check)

    @for_examples(([['.','.','.','r','k','b','.','r'],
                    ['.','.','N','.','.','p','p','.'],
                    ['p','.','P','p','.','.','.','p'],
                    ['.','p','n','.','.','P','.','.'],
                    ['.','.','.','.','.','.','.','.'],
                    ['.','.','.','.','P','.','.','.'],
                    ['P','.','.','.','.','.','P','P'],
                    ['R','.','.','.','.','R','K','.']], (0,4), (7,6), ('k','N', 1, 2)),

                  ([['.','.','.','.','.','.','.','.'],
                    ['.','.','.','k','.','.','.','.'],
                    ['.','p','n','.','p','.','.','.'],
                    ['.','p','.','.','P','p','.','.'],
                    ['.','.','.','K','.','P','.','.'],
                    ['.','R','.','.','.','.','.','R'],
                    ['P','P','.','.','.','.','.','.'],
                    ['.','.','B','.','.','.','.','.']], (1,3), (4,3), ('K','n', 2, 2)))
    def testKnightCheck(self, board, black_king, white_king, knight_check):
        '''
        Test for knight checks
        '''
        kings = find_kings(board)
        self.assertEqual(kings['k'], black_king)
        self.assertEqual(kings['K'], white_king)
        check = check_check(board)
        self.assertEqual(check, knight_check)

    @for_examples(([['r','n','b','q','.','b','n','r'],
                    ['p','p','p','p','p','.','.','.'],
                    ['.','.','.','.','.','.','p','.'],
                    ['.','.','.','.','.','.','.','k'],
                    ['.','.','.','.','.','Q','P','p'],
                    ['.','.','.','.','P','.','.','.'],
                    ['P','P','P','P','.','P','.','P'],
                    ['R','N','B','.','K','.','N','R']], (3,7), (7,4), ('k','P', 4, 6)))
    def testPawnCheck(self, board, black_king, white_king, pawn_check):
        '''
        Test for knight checks
        '''
        kings = find_kings(board)
        self.assertEqual(kings['k'], black_king)
        self.assertEqual(kings['K'], white_king)
        check = check_check(board)
        self.assertEqual(check, pawn_check)

    @for_examples(([['r','n','.','.','b','r','k','.'],
                    ['.','.','.','.','.','p','p','p'],
                    ['.','.','p','.','p','.','.','.'],
                    ['p','p','q','P','.','.','.','.'],
                    ['P','n','p','.','P','.','N','.'],
                    ['N','.','.','.','.','P','P','.'],
                    ['.','P','.','Q','.','.','B','P'],
                    ['R','.','.','R','.','.','K','.']], (0,6), (7,6), ('K','q', 3, 2)))
    def testQueenCheck(self, board, black_king, white_king, pawn_check):
        '''
        Test for knight checks
        '''
        kings = find_kings(board)
        self.assertEqual(kings['k'], black_king)
        self.assertEqual(kings['K'], white_king)
        check = check_check(board)
        self.assertEqual(check, pawn_check)

if __name__ == "__main__":


        import unittest
    from testgenDecorator import for_examples
    from checkChessCheck import check_check, check_knight_attack, find_kings, check_pawn_attack

    class TestChessCheck(unittest.TestCase):

        @for_examples(([['r','n','b','q','k','b','n','r'],
                        ['p','p','p','p','p','p','p','p'],
                        ['.','.','.','.','.','.','.','.'],
                        ['.','.','.','.','.','.','.','.'],
                        ['.','.','.','.','.','.','.','.'],
                        ['.','.','.','.','.','.','.','.'],
                        ['P','P','P','P','P','P','P','P'],
                        ['R','N','B','Q','K','B','N','R']], (0,4), (7,4), None),

                      ([['r','.','b','q','k','b','n','r'],
                        ['p','p','p','p','.','p','p','p'],
                        ['.','.','n','.','.','.','.','.'],
                        ['.','.','.','.','p','.','.','.'],
                        ['.','.','.','.','P','.','.','.'],
                        ['.','.','.','.','.','N','.','.'],
                        ['P','P','P','P','.','P','P','P'],
                        ['R','N','B','Q','K','B','.','R']], (0,4), (7,4), None))
        def testNoCheck(self, board, black_king, white_king, knight_check):
            '''
            Test for knight checks
            '''
            kings = find_kings(board)
            self.assertEqual(kings['k'], black_king)
            self.assertEqual(kings['K'], white_king)
            check = check_check(board)
            self.assertEqual(check, knight_check)

        @for_examples(([['.','.','.','r','k','b','.','r'],
                        ['.','.','N','.','.','p','p','.'],
                        ['p','.','P','p','.','.','.','p'],
                        ['.','p','n','.','.','P','.','.'],
                        ['.','.','.','.','.','.','.','.'],
                        ['.','.','.','.','P','.','.','.'],
                        ['P','.','.','.','.','.','P','P'],
                        ['R','.','.','.','.','R','K','.']], (0,4), (7,6), ('k','N', 1, 2)),

                      ([['.','.','.','.','.','.','.','.'],
                        ['.','.','.','k','.','.','.','.'],
                        ['.','p','n','.','p','.','.','.'],
                        ['.','p','.','.','P','p','.','.'],
                        ['.','.','.','K','.','P','.','.'],
                        ['.','R','.','.','.','.','.','R'],
                        ['P','P','.','.','.','.','.','.'],
                        ['.','.','B','.','.','.','.','.']], (1,3), (4,3), ('K','n', 2, 2)))
        def testKnightCheck(self, board, black_king, white_king, knight_check):
            '''
            Test for knight checks
            '''
            kings = find_kings(board)
            self.assertEqual(kings['k'], black_king)
            self.assertEqual(kings['K'], white_king)
            check = check_check(board)
            self.assertEqual(check, knight_check)

        @for_examples(([['r','n','b','q','.','b','n','r'],
                        ['p','p','p','p','p','.','.','.'],
                        ['.','.','.','.','.','.','p','.'],
                        ['.','.','.','.','.','.','.','k'],
                        ['.','.','.','.','.','Q','P','p'],
                        ['.','.','.','.','P','.','.','.'],
                        ['P','P','P','P','.','P','.','P'],
                        ['R','N','B','.','K','.','N','R']], (3,7), (7,4), ('k','P', 4, 6)))
        def testPawnCheck(self, board, black_king, white_king, pawn_check):
            '''
            Test for knight checks
            '''
            kings = find_kings(board)
            self.assertEqual(kings['k'], black_king)
            self.assertEqual(kings['K'], white_king)
            check = check_check(board)
            self.assertEqual(check, pawn_check)

        @for_examples(([['r','n','.','.','b','r','k','.'],
                        ['.','.','.','.','.','p','p','p'],
                        ['.','.','p','.','p','.','.','.'],
                        ['p','p','q','P','.','.','.','.'],
                        ['P','n','p','.','P','.','N','.'],
                        ['N','.','.','.','.','P','P','.'],
                        ['.','P','.','Q','.','.','B','P'],
                        ['R','.','.','R','.','.','K','.']], (0,6), (7,6), ('K','q', 3, 2)))
        def testQueenCheck(self, board, black_king, white_king, pawn_check):
            '''
            Test for knight checks
            '''
            kings = find_kings(board)
            self.assertEqual(kings['k'], black_king)
            self.assertEqual(kings['K'], white_king)
            check = check_check(board)
            self.assertEqual(check, pawn_check)

    if __name__ == "__main__":
        unittest.main()

Edited 3 Years Ago by pyTony: From second post inserted the code in proper format

This question has already been answered. Start a new discussion instead.