Exemple #1
0
    def test_invalid_move_black_pawn(self):
        board = ChessBoard()
        testBoard = [['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
                     ['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp'],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', 'wp', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['wp', '  ', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp'],
                     ['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', 'wr']]

        set_board(board, testBoard)

        # Test 1
        selected_figure = Point(1, 1)
        new_position = Point(3, 1)
        motion = board._make_motion(selected_figure, new_position)
        self.assertTrue(board.invalid_move_black_pawn(motion, new_position))

        # Test 2
        new_position = Point(3, 2)
        motion = board._make_motion(selected_figure, new_position)
        self.assertTrue(board.invalid_move_black_pawn(motion, new_position))

        # Test 3
        selected_figure = Point(2, 2)
        new_position = Point(2, 3)
        motion = board._make_motion(selected_figure, new_position)
        self.assertFalse(board.invalid_move_black_pawn(motion, new_position))
Exemple #2
0
    def test_invalid_move_white_pawn(self):
        board = ChessBoard()

        # Test 1
        white_pawn = Point(1, 3)
        new_position = Point(1, 1)
        motion = board._make_motion(white_pawn, new_position)

        self.assertTrue(board.invalid_move_white_pawn(motion, new_position))

        # Test 2
        new_position = Point(1, 0)
        motion = board._make_motion(white_pawn, new_position)
        self.assertTrue(board.invalid_move_white_pawn(motion, new_position))

        # Test 3
        new_position = Point(1, 4)
        motion = board._make_motion(white_pawn, new_position)

        self.assertTrue(board.invalid_move_white_pawn(motion, new_position))

        # Test 4
        new_position = Point(1, 2)
        motion = board._make_motion(white_pawn, new_position)

        self.assertFalse(board.invalid_move_white_pawn(motion, new_position))
Exemple #3
0
    def test_if_try_to_jump_over_enemy_figure(self):

        board = ChessBoard()
        testBoard = [['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
                     ['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', 'bp'],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', 'wr'],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', '  '],
                     ['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', '  ']]

        set_board(board, testBoard)

        selected_figure = Point(7, 4, "wr")
        final_position = Point(7, 0)

        next_cell_while_moving = Point(7, 3)

        motion = board._make_motion(selected_figure, final_position)

        step_x, step_y = board._set_step_to_move(motion)
        prepare_moving = Point(step_x, step_y)

        self.assertTrue(board._try_jump_enemy(
            next_cell_while_moving, selected_figure, prepare_moving, motion))
Exemple #4
0
    def test_calculate_of_motion_of_figure(self):

        board = ChessBoard()

        # Test 1
        start_position = Point(1, 1)
        destination = Point(1, 2)

        motion = board._make_motion(start_position, destination)

        self.assertEqual(motion.get_x(), 0)
        self.assertEqual(motion.get_y(), 1)

        # Test 2
        start_position = Point(1, 1)
        destination = Point(1, 5)

        motion = board._make_motion(start_position, destination)

        self.assertNotEqual(motion.get_x(), 1)
        self.assertEqual(motion.get_y(), 4)
Exemple #5
0
    def test_can__get_with_black_pawn(self):

        board = ChessBoard()
        # test 1
        black_pawn_position = Point(5, 5)
        white_pawn_position = Point(4, 6)
        motion = board._make_motion(black_pawn_position, white_pawn_position)

        self.assertTrue(board._get_with_black_pawn(motion, white_pawn_position))

        # test 2
        black_pawn_position = Point(5, 5)
        white_pawn_position = Point(5, 6)
        motion = board._make_motion(black_pawn_position, white_pawn_position)

        self.assertFalse(board._get_with_black_pawn(motion, white_pawn_position))

        # test 3
        black_pawn_position = Point(3, 3)
        white_pawn_position = Point(4, 4)
        motion = board._make_motion(black_pawn_position, white_pawn_position)

        self.assertFalse(board._get_with_black_pawn(motion, white_pawn_position))
Exemple #6
0
    def test_can__get_with_white_pawn(self):

        board = ChessBoard()
        # test 1
        white_pawn_position = Point(2, 2)
        black_pawn_position = Point(3, 1)
        motion = board._make_motion(white_pawn_position, black_pawn_position)

        self.assertTrue(board._get_with_white_pawn(motion, black_pawn_position))

        # test 2
        white_pawn_position = Point(3, 3)
        black_pawn_position = Point(4, 2)
        motion = board._make_motion(white_pawn_position, black_pawn_position)

        self.assertFalse(board._get_with_white_pawn(motion, black_pawn_position))

        # test 3
        white_pawn_position = Point(2, 2)
        black_pawn_position = Point(2, 1)
        motion = board._make_motion(white_pawn_position, black_pawn_position)

        self.assertFalse(board._get_with_white_pawn(motion, black_pawn_position))
Exemple #7
0
    def test_waiting_to_make_a_full_turn(self):

        board = ChessBoard()
        testBoard = [['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
                     ['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp'],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  '],
                     ['wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', '  '],
                     ['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', 'wr']]

        set_board(board, testBoard)

        selected_figure = Point(7, 7, "wr")
        final_position = Point(7, 3)
        motion = board._make_motion(selected_figure, final_position)

        step_x, step_y = board._set_step_to_move(motion)
        prepare_moving = Point(step_x, step_y)

        self.assertTrue(
            board.waiting_to_finish_this_turn(prepare_moving, motion))
Exemple #8
0
    def test_whether_the_move_would_be_make_by_rules(self):

        board = ChessBoard()
        white_pawn = Point(6, 6, "wp")
        target_cell = Point(6, 5)
        motion = board._make_motion(white_pawn, target_cell)
        # Test 1
        self.assertTrue(
            board._checking_the_move_is_correct(white_pawn, motion))

        # Test 2
        white_pawn = Point(6, 7, "wn")
        target_cell = Point(5, 5)
        motion = board._make_motion(white_pawn, target_cell)

        self.assertTrue(
            board._checking_the_move_is_correct(white_pawn, motion))

        # Test 3
        white_knight = Point(6, 7, "wn")
        target_cell = Point(6, 5)
        motion = board._make_motion(white_knight, target_cell)

        self.assertFalse(
            board._checking_the_move_is_correct(white_knight, motion))

        # Test 4
        black_pawn = Point(1, 1, "bp")
        target_cell = Point(1, 5)
        motion = board._make_motion(black_pawn, target_cell)

        self.assertFalse(
            board._checking_the_move_is_correct(black_pawn, motion))

        # Test 5
        white_bishop = Point(3, 5, "wb")
        target_cell = Point(4, 4)
        motion = board._make_motion(white_bishop, target_cell)

        self.assertTrue(
            board._checking_the_move_is_correct(white_bishop, motion))

        # Test 6
        white_bishop = Point(3, 5, "wb")
        target_cell = Point(4, 5)
        motion = board._make_motion(white_bishop, target_cell)

        self.assertFalse(
            board._checking_the_move_is_correct(white_bishop, motion))

        # Test 7
        white_rock = Point(3, 5, "wr")
        target_cell = Point(4, 4)
        motion = board._make_motion(white_rock, target_cell)

        self.assertFalse(
            board._checking_the_move_is_correct(white_rock, motion))

        # Test 8
        white_queen = Point(3, 5, "wq")
        target_cell = Point(4, 4)
        motion = board._make_motion(white_queen, target_cell)

        self.assertTrue(
            board._checking_the_move_is_correct(white_queen, motion))

        # Test 9
        white_king = Point(3, 5, "wk")
        target_cell = Point(3, 3)
        motion = board._make_motion(white_king, target_cell)

        self.assertFalse(
            board._checking_the_move_is_correct(white_king, motion))

        # Test 10
        white_king = Point(3, 5, "wk")
        target_cell = Point(4, 4)
        motion = board._make_motion(white_king, target_cell)

        self.assertTrue(
            board._checking_the_move_is_correct(white_king, motion))