예제 #1
0
def get_cell_value(puzzle, row_id, column_id):
    if random.random() < 0.2:
        return random.choice(sudoku.DIGITS)

    cells = sudoku.get_column(puzzle, column_id) if random.random() > 0.5 else sudoku.get_row(puzzle, row_id)
    values = sudoku.get_remaining_values(cells)

    return random.choice(values) if len(values) > 0 else random.choice(sudoku.DIGITS)
예제 #2
0
    def test_get_row(self):
        puzzle = [["1", "2", "."], ["4", "5", "6"], ["7", "8", "9"]]
        pos = (0, 0)
        expected_row = ["1", "2", "."]
        actual_row = sudoku.get_row(puzzle, pos)
        self.assertEqual(expected_row, actual_row)

        puzzle = [["1", "2", "3"], ["4", ".", "6"], ["7", "8", "9"]]
        pos = (1, 0)
        expected_row = ["4", ".", "6"]
        actual_row = sudoku.get_row(puzzle, pos)
        self.assertEqual(expected_row, actual_row)

        puzzle = [["1", "2", "3"], ["4", "5", "6"], [".", "8", "9"]]
        pos = (2, 0)
        expected_row = [".", "8", "9"]
        actual_row = sudoku.get_row(puzzle, pos)
        self.assertEqual(expected_row, actual_row)
 def test_get_row(self):
     self.assertEqual(sudoku.get_row(grid_elements, 3),
                      [(3,1), (3,2), (3,3), (3,4), (3,5),
                       (3,6), (3,7), (3,8), (3,9)])
예제 #4
0
def test_get_row():
    assert sudoku.get_row(grid_elements, 3) == \
           [(3,1), (3,2), (3,3), (3,4), (3,5), (3,6), (3,7), (3,8), (3,9)]
def test_get_row():
    assert sudoku.get_row(grid_elements, 3) == [(3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9)]
예제 #6
0
 def test_row_extraction(self):
     self.assertEqual(sudoku.get_row(sudoku_problems['easy1'],0), [0,0,3,7,0,0,0,5,0])