Example #1
0
    def test_findBlank(self):

        self.assertEqual(Solve.find_blank(self.validBoard1), (1, 7))
        self.assertEqual(Solve.find_blank(self.validBoard2), (0, 1))
        for i in range(0, 9):
            for j in range(0, 9):
                self.assertNotEqual(Solve.find_blank(self.solvedBoard1), (i, j))
Example #2
0
def brute_force(raw_board):
    # Return true if solved.  This will bring the correct board up through the chain of calls.
    if Solve.is_solved_board(raw_board):
        return raw_board, True
    # If board is not valid, move up the call chain once.
    if not Solve.is_valid_board(raw_board):
        return raw_board, False

    # Find the first blank space from the top left
    x, y = Solve.find_blank(raw_board)

    # Create a copy of board to be possed down the chain
    new_board = [[raw_board[i][j] for j in range(0, 9)] for i in range(0, 9)]

    for value in range(1, 10):

        # Place a value in the empty spot and go to the next spot.
        new_board[x][y] = value
        result_board, result = brute_force(new_board)

        # If the call below this found a solved board, bring the solved board up to the next call
        if result is True:
            return result_board, result
            # If the call below found an invalid board, replace the current spot with the next value

    # If all values were found to be invalid, go up a call and check the next value for the previous blank spot
    return raw_board, False
Example #3
0
    def test_checkBoxes(self):

        self.assertTrue(Solve.check_boxes(self.solvedBoard1))
        self.assertTrue(Solve.check_boxes(self.solvedBoard2))
        self.assertTrue(Solve.check_boxes(self.validBoard1))
        self.assertTrue(Solve.check_boxes(self.validBoard2))
        self.assertTrue(Solve.check_boxes(self.validBoard3))
        self.assertFalse(Solve.check_boxes(self.invalidBoard1))
        self.assertFalse(Solve.check_boxes(self.invalidBoard2))
        self.assertFalse(Solve.check_boxes(self.invalidBoard3))
        self.assertFalse(Solve.check_boxes(self.invalidBoard4))
        self.assertFalse(Solve.check_boxes(self.invalidBoard5))
Example #4
0
    def test_isSolvedBoard(self):

        self.assertTrue(Solve.is_solved_board(self.solvedBoard1))
        self.assertTrue(Solve.is_solved_board(self.solvedBoard2))
        self.assertFalse(Solve.is_solved_board(self.validBoard1))
        self.assertFalse(Solve.is_solved_board(self.validBoard2))
        self.assertFalse(Solve.is_solved_board(self.validBoard3))
        self.assertFalse(Solve.is_solved_board(self.invalidBoard1))
        self.assertFalse(Solve.is_solved_board(self.invalidBoard2))
        self.assertFalse(Solve.is_solved_board(self.invalidBoard3))
        self.assertFalse(Solve.is_solved_board(self.invalidBoard4))
        self.assertFalse(Solve.is_solved_board(self.invalidBoard5))