def setUp(self): self.user4 = Interfaz() self.user9 = Interfaz() lista4 = [["4", "x", "3", "1"], ["x", "3", "x", "x"], ["3", "1", "x", "2"], ["x", "4", "x", "x"]] self.user4.tam = 4 self.user4.level = "1" self.user4.game = Sudoku(lista4) lista9 = [["5", "3", "x", "x", "7", "x", "x", "x", "x"], ["6", "x", "x", "x", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]] self.user9.tam = 9 self.user9.level = "1" self.user9.game = Sudoku(lista9)
def impossible_test(self): # impossible puzzles = [ # From https://norvig.com/sudoku.html -> column 4, no 1 possible because of triple 5-6 doubles and triple 1s '.....5.8....6.1.43..........1.5........1.6...3.......553.....61........4.........', # obvious doubles '12.......34...............5...........5..........................................', '11.......34...............5......................................................', ] for puzzle in puzzles: puzzle = str2grid(puzzle) s = Sudoku(puzzle) s.flush_candidates() self.assertFalse(s.check_possible()[0]) # possible puzzles = [ '280070309600104007745080006064830100102009800000201930006050701508090020070402050', '000010030009005008804006025000000600008004000120087000300900200065008000900000000', '1.....................................5..........................................', ] for puzzle in [puzzles[1]]: puzzle = str2grid(puzzle) s = Sudoku(puzzle) s.flush_candidates() self.assertTrue(s.check_possible()[0])
def test_sudoku_1x1(self): sudoku = Sudoku(self.tablero_1x1) self.assertTrue(sudoku.solve_sudoku()) sudoku = Sudoku(self.tablero_1x1_2) self.assertTrue(sudoku.solve_sudoku()) esp = np.array([[1]]) self.assertEqual(esp.any(),(sudoku.sudoku).any(),msg="Compara Resultado esperado con el resultado obtenido, True--> si son iguales, False-->si no lo son")
def test_candidates_advanced(self): grid = [ [0, 8, 0, 0, 0, 1, 2, 0, 6], [0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 2, 0, 3, 0, 5, 0, 4, 0], [0, 6, 0, 0, 1, 0, 9, 0, 0], [0, 0, 2, 0, 5, 0, 4, 0, 0], [0, 0, 8, 0, 0, 0, 0, 1, 0], [0, 3, 0, 7, 0, 4, 0, 5, 0], [0, 0, 0, 0, 3, 0, 0, 0, 0], [4, 0, 6, 1, 0, 0, 0, 8, 0] ] # June 7 Extreme 'https://www.sudokuwiki.org s = Sudoku(SudokuGrid().with_matrix(grid)) candidates = [ [{9, 3, 5, 7}, set(), {3, 4, 5, 7, 9}, {9, 4}, {9, 4, 7}, set(), set(), {9, 3, 7}, set()], [{1, 3, 5, 6, 7, 9}, {1, 4, 5, 7, 9}, {1, 3, 4, 5, 7, 9}, {8, 9, 4, 6}, set(), {8, 9, 6, 7}, {1, 3, 5, 7, 8}, {9, 3, 7}, {1, 3, 5, 7, 8, 9}], [{1, 9, 6, 7}, set(), {1, 9, 7}, set(), {8, 9, 6, 7}, set(), {8, 1, 7}, set(), {8, 1, 9, 7}], [{3, 5, 7}, set(), {3, 4, 5, 7}, {8, 2, 4}, set(), {8, 2, 3, 7}, set(), {2, 3, 7}, {2, 3, 5, 7, 8}], [{1, 3, 9, 7}, {1, 9, 7}, set(), {8, 9, 6}, set(), {3, 6, 7, 8, 9}, set(), {3, 6, 7}, {8, 3, 7}], [{9, 3, 5, 7}, {9, 4, 5, 7}, set(), {9, 2, 4, 6}, {9, 4, 6, 7}, {2, 3, 6, 7, 9}, {3, 5, 6, 7}, set(), {2, 3, 5, 7}], [{8, 1, 2, 9}, set(), {1, 9}, set(), {8, 9, 6}, set(), {1, 6}, set(), {1, 2, 9}], [{1, 2, 5, 7, 8, 9}, {1, 5, 9, 7}, {1, 5, 9, 7}, {2, 5, 6, 8, 9}, set(), {8, 9, 2, 6}, {1, 6, 7}, {9, 2, 6, 7}, {1, 2, 4, 7, 9}], [set(), {9, 5, 7}, set(), set(), {9}, {9, 2}, {3, 7}, set(), {9, 2, 3, 7}] ] self.assertTrue(self.candidates_equal(s.grid.candidates, candidates)) inds = [(i, 0) for i in range(9)] #self.assertEqual(s.get_pairs(inds), [([(6, 0), (7, 0)], (2, 8))]) uniques = s.get_unique(inds, type=[2])[0] uniques[0].sort() self.assertEqual(uniques, ([(6, 0), (7, 0)], (2, 8)) ) grid = [ [0, 0, 0, 0, 0, 1, 0, 3, 0], [2, 3, 1, 0, 9, 0, 0, 0, 0], [0, 6, 5, 0, 0, 3, 1, 0, 0], [6, 7, 8, 9, 2, 4, 3, 0, 0], [1, 0, 3, 0, 5, 0, 0, 0, 6], [0, 0, 0, 1, 3, 6, 7, 0, 0], [0, 0, 9, 3, 6, 0, 5, 7, 0], [0, 0, 6, 0, 1, 9, 8, 4, 3], [3, 0, 0, 0, 0, 0, 0, 0, 0] ] # https://www.sudokuwiki.org/Hidden_Candidates#HP s = Sudoku(SudokuGrid().with_matrix(grid)) inds = [(0, j) for j in range(9)] uniques = s.get_unique(inds, type=[3])[0] uniques[0].sort() self.assertEqual(uniques, ([(0, 3), (0, 6), (0, 8)], (2, 5, 6)) ) s.grid.candidates[0][8] = {2, 5} inds = [(i, 8) for i in range(9)] uniques = s.get_unique(inds, type=[3])[0] uniques[0].sort() self.assertEqual(uniques, ([(1, 8), (2, 8), (5, 8)], (4, 8, 7)) )
def setUp(self): self.sudoku9 = Sudoku([["5", "3", "x", "x", "7", "x", "x", "x", "x"], ["6", "x", "x", "x", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.sudoku4 = Sudoku([["4", "x", "3", "1"], ["x", "3", "x", "x"], ["3", "1", "x", "2"], ["x", "4", "x", "x"]])
def test_hardest(self): grid = [ [8,0,0,0,0,0,0,0,0], [0,0,3,6,0,0,0,0,0], [0,7,0,0,9,0,2,0,0], [0,5,0,0,0,7,0,0,0], [0,0,0,0,4,5,7,0,0], [0,0,0,1,0,0,0,3,0], [0,0,1,0,0,0,0,6,8], [0,0,8,5,0,0,0,1,0], [0,9,0,0,0,0,4,0,0] ] expected = [ [8,1,2,7,5,3,6,4,9], [9,4,3,6,8,2,1,7,5], [6,7,5,4,9,1,2,8,3], [1,5,4,2,3,7,8,9,6], [3,6,9,8,4,5,7,2,1], [2,8,7,1,6,9,5,3,4], [5,2,1,9,7,4,3,6,8], [4,3,8,5,2,6,9,1,7], [7,9,6,3,1,8,4,5,2] ] sudoku = Sudoku() actual = sudoku.solve((3, 3), grid) self.assertEquals(actual, expected)
def solveRecursive(value, x, y): global counter if counter == 0: print(str(sudoku)) return True if sudoku.field[y][x].value != 0: return False if sudoku.field[y][x].constant or isNumberInBlock( value, x, y) or isNumberInCol(value, x) or isNumberInRow(value, y): sudokuFailed = Sudoku(sudoku.field) failedStates.add(sudokuFailed) #print("added to failed states") return False sudoku.field[y][x] = Cell(value, False) counter -= 1 for i in range(1, fieldSize + 1): for y2 in range(fieldSize): for x2 in range(fieldSize): if solveRecursive(i, x2, y2): return True sudoku.field[y][x] = Cell(0, False) counter += 1 return False
def test_all_boards(self): grid_files = sorted([f for f in os.listdir(GRID_DIR) if f.split('.')[1] == 'jpg'], key=lambda f: int(f.split('.')[0])) successes = 0 total_time = 0 missed_digits = 0 for grid in grid_files: print('Processing %s...' % grid) start = time.time() sudoku = Sudoku(os.path.join(GRID_DIR, grid), DIGIT_MODEL) total_time += time.time() - start with open(os.path.join(GRID_DIR, '%s.dat' % grid.split('.')[0]), 'r') as f: board = solver.parse_sudoku_puzzle(f.read()) # Add up the mis-classified digits diff = [] guess = sudoku.board_dict for position in guess: if guess[position] != board[position]: diff.append(position) missed_digits += len(diff) if sudoku.board_dict == board: successes += 1 print('Success: %s\tFail: %s\tRatio: %s' % (successes, len(grid_files) - successes, successes / len(grid_files))) print('Elapsed: %ss\tAverage: %ss' % (total_time, total_time / len(grid_files))) print('Total Digits: %s\tMissed Digits: %s\tRatio: %s' % (len(grid_files) * 81, missed_digits, missed_digits / (len(grid_files) * 81))) self.assertGreaterEqual(successes / len(grid_files), TOLERANCE)
def run(self, problem): print("초기 시작") print("스도쿠 문제번호 : ") print("스도쿠 난이도 : ") temp = np.array(list(map(int, list(problem)))).reshape(3, 3, 3, 3) self.helpArray = Sudoku( np.array([[SubBlock(subblock) for subblock in subblocks] for subblocks in temp])) print("helpArray: ") self.helpArray.printSudoku() self.manager = Manager(self.helpArray) count = self.gaCount while not self.end: # and self.gaCount < 3: print("세대 : ", self.gaCount) print("fitness : ", self.manager.fmin) print("best solution: ") self.manager.sudokuPool[0].printSudoku() if count > 2000: self.restart() count = 1 self.end = self.manager.nextGeneration() self.gaCount = self.gaCount + 1 count += 1 self.print()
def test(self): grid = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9] ] expected = [ [5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], [9, 6, 1, 5, 3, 7, 2, 8, 4], [2, 8, 7, 4, 1, 9, 6, 3, 5], [3, 4, 5, 2, 8, 6, 1, 7, 9] ] sudoku = Sudoku() actual = sudoku.solve((3, 3), grid) self.assertEquals(actual, expected)
def __init__(self, file_name, cnf_filename=None): if cnf_filename is None: #-- Set up and load in puzzle self.sudoku = Sudoku() self.puzzle_name = str(file_name[:-4]) self.solution_filename = self.puzzle_name + ".sol" self.cnf_filename = self.puzzle_name + ".cnf" self.sudoku.load(file_name) self.sudoku.generate_cnf(self.cnf_filename) else: self.puzzle_name = str(file_name[:-4]) self.solution_filename = self.puzzle_name + ".sol" self.cnf_filename = cnf_filename #-- Load in clauses clauses = [] with open(self.cnf_filename, 'r') as cnf: lines = cnf.readlines() for line in lines: clause = list(map(int, line.rstrip('\n').strip().split(' '))) clauses.append(clause) #-- Make sudoku variables variables = [ int(''.join(str(x) for x in var)) for var in itertools.product(range(1, 10), repeat=3) ] #-- Set up generic class super().__init__(variables, clauses, problem_name='Sudoku')
def index(): # delete old input and output images if os.path.exists(INPUT_IMAGE_PATH): os.remove(INPUT_IMAGE_PATH) if os.path.exists(OUTPUT_IMAGE_PATH): os.remove(OUTPUT_IMAGE_PATH) if request.method == 'POST': image = request.files['image'] if image and allowed_image(image.filename): image.save(INPUT_IMAGE_PATH) sudoku = Sudoku(img_path=INPUT_IMAGE_PATH) status = sudoku.get_status() if status == 'solved': sudoku.save_solved_image(OUTPUT_IMAGE_PATH) return render_template('index.html', input_img=True, output_img=True) else: return render_template('index.html', input_img=True, status=status) else: return render_template('index.html', error=True) return render_template('index.html')
def classify_digits(name, src): print('%s Classification' % name) # Some housekeeping mkdir(os.path.join(CLASSIFIED_DIR, name)) for i in range(10): digit_dir = os.path.join(CLASSIFIED_DIR, name, str(i)) mkdir(digit_dir) # Sort files by their number otherwise we'll run into problems when classifying the digits files = [f for f in os.listdir(src) if f.split('.')[1] == 'jpg'] files = sorted(files, key=lambda x: int(x.split('.')[0])) for i, f in enumerate(files): print('Classifying %s...' % i) original = [ v.replace('.', '0') for k, v in read_original_board(i, src).items() ] grid = Sudoku(os.path.join(src, f), include_gray_channel=True, skip_recog=True) # Ignore completely blank images, not required in the training set digits_idx = [(j, digit) for j, digit in enumerate(grid.digits) if not np.array_equal(digit, blank)] for j, digit in digits_idx: cv2.imwrite( os.path.join(CLASSIFIED_DIR, name, original[j], '%s.jpg' % get_next_file(name, original[j])), digit)
def test_Sudoku_4_gano(self): sudoku = Sudoku([["4", "2", "3", "1"], ["1", "3", "2", "4"], ["3", "1", "4", "2"], ["2", "4", "1", "3"]]) self.assertTrue(sudoku.gano())
def _iterate(self, oldBoard, solveAlg): """ The iterate function should: Execute a solving alrogithm (passed in args?) Have a way to catch the algorithm if it executes a previosly run node placement Inform the old board of the new board's decision. :param board: this is the sudoku board to run the algorithm on :param solveAlg: this is the solving algorithm that takes in a board and a decision function :return: newBoard, oldBoard :: each Board is a Sudoku Board :raise: DeadEndError :: If there are 0 nodes that can be filled in that have not been tried out This catches a special case where a valid board exists but none of the soltions from that branch of the search tree are valid. THe main portion of the algorithm does not catch this so the exception allows it to be caught. """ priorityList = solveAlg(oldBoard) nodeList, row, column = priorityList[0] newBoard = Sudoku.Sudoku(oldBoard.getSize(), oldBoard.getBoard()) placedNode = False for node in nodeList: if newBoard.placeNode(node(), row, column): oldBoard.setConstraint(node(), row, column) return oldBoard, newBoard raise DeadEndError( "None of the nodes found are viable, this is a dead end.")
def traiteSaisieGrille(self, csock, donnejesRecues): self.ejnoncej = '' # 11=3&12=1&13=&...&98=&99=&raz=raz if 'raz=raz' in donnejesRecues: self.afficheSaisieGrille(csock) return # 11=3&12=1&13=&...&98=&99=&soumettre=soumettre match = re.search('(11=.*)&soumettre=soumettre', donnejesRecues) if not match: print('saisie-grille INCONNU') self.afficheSaisieGrille(csock) return for affectation in match.group(1).split('&'): # 12=1 ou 13= valeur = affectation.split('=')[1] if valeur == '': self.ejnoncej += '.' else: self.ejnoncej += valeur # max 81 + 8 virgules if len(self.ejnoncej) == 89: break # insertion barre sejparation if len(self.ejnoncej) % 10 == 9: self.ejnoncej += '|' if len(self.ejnoncej) != 89: print('saisie-grille ERRONNÉE ({})'.format(len(self.ejnoncej))) self.afficheSaisieGrille(csock) return # avec le programme de calcul maintenant lignes = self.ejnoncej.replace('|', ',') lignes = lignes.replace('.', '0') self.sudoku = Sudoku(lignes) # affiche self.afficheEnTeste(csock) self.afficheTitreEtSaisie(csock) self.afficheCalculPartiel(csock) self.afficheValeursPossibles(csock) self.afficheQueue(csock)
def check_done(self): # Easy puzzle = '280070309600104007745080006064830100102009800000201930006050701508090020070402050' solution = '281576349693124587745983216964835172132749865857261934426358791518697423379412658' puzzle, solution = str2grid(puzzle), str2grid(solution) s = Sudoku(puzzle) self.assertFalse(s.check_done()) s = Sudoku(solution) self.assertTrue(s.check_done()) # Medium puzzle = '100020400035040900704000001800000000091032080000100097070900600000000000000450000' solution = '189327465235641978764895321827569143491732586653184297372918654546273819918456732' puzzle, solution = str2grid(puzzle), str2grid(solution) s = Sudoku(puzzle) self.assertFalse(s.check_done()) s = Sudoku(solution) self.assertTrue(s.check_done())
def test_sudoku_4x4(self): esperado = np.array([[2, 1, 3, 4], [4, 3, 1, 2], [1, 4, 2, 3], [3, 2, 4, 1]]) sudoku = Sudoku(self.tablero_4x4) self.assertTrue(sudoku.solve_sudoku()) self.assertEqual(esperado.any(),(sudoku.sudoku).any(),msg="Compara Resultado esperado con el resultado obtenido, True--> si son iguales, False-->si no lo son")
def setUp(self): self.table = ["53xx7xxxx", "6xx195xxx", "x98xxxx6x", "8xxx6xxx3", "4xx8x3xx1", "7xxx2xxx6", "x6xxxx28x", "xxx419xx5", "xxxx8xx79"] self.sudoku = Sudoku(self.table, 9) self.ori_pos = ["00", "01", "04", "10", "13", "14", "15", "21", "22", "27", "30", "34", "38", "40", "43", "45", "48", "50", "54", "58", "61", "66", "67", "73", "74", "75", "78", "84", "87", "88"]
def sudoku(fname): f_path = os.path.join(application.config['UPLOAD_FOLDER'], fname) # create sudokuimage object sdku_img = SudokuImage(f_path) # catch any initial image processing errors # if len(rows/cols) != 10, the object sets them to false if sdku_img.rows and sdku_img.cols: sudoku_grid = np.zeros((9,9), dtype = int) # note: empty cells will be denoted by 0 # use knn to predict the value of non-empty sdku_img cells for cell in sdku_img.predict_cells(): sudoku_grid[cell[0], cell[1]] = cell[2] no_failure = True solved_grid = sudoku_grid.copy() if request.method == 'POST': sdku = Sudoku(solved_grid) # create sudoku object no_failure, solution = sdku.solve() # solve sudoku # if sudoku cant be solved, redirect with error message # typically this is due to bad prediction if not no_failure: flash("Oops, I am having trouble processing your Sudoku! Take a clearer photo and try again.") return redirect(url_for('sudokusolver')) # render when everything goes according to plan return render_template('sudoku_image.html',image = url_for('static', filename = 'uploads/'+fname), initial_sudoku = sudoku_grid, solved_sudoku = solved_grid) # initial rendering to user, before they hit submit return render_template('sudoku_image.html',image = url_for('static', filename = 'uploads/'+fname), initial_sudoku = sudoku_grid, solved_sudoku = solved_grid) else: # this is rendered when the image can't be processed initially flash("Oops, I am having trouble processing your Sudoku! Take a clearer photo and try again.") return redirect(url_for('sudokusolver'))
def check_row_test(self): grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 0, 0, 0, 0, 0, 0, 0, 0], [3, 3, 0, 0, 0, 0, 0, 0, 0], [4, 0, 0, 0, 0, 0, 0, 0, 0], [5, 0, 0, 0, 0, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0, 0, 0, 0], [7, 0, 0, 0, 0, 0, 0, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0, 0], [9, 0, 0, 0, 0, 0, 0, 0, 0]] s = Sudoku(grid) self.assertTrue(s.no_duplicates(grid[0])) self.assertTrue(s.no_duplicates(grid[1])) self.assertFalse(s.no_duplicates(grid[2]))
def check_unique_test(self): s = Sudoku([[1]]) arr = [1, 2, 3, 4, 5] self.assertTrue(s.no_duplicates(arr)) arr = [1, 2, 2, 1] self.assertFalse(s.no_duplicates(arr)) arr = [i for i in range(10)] self.assertTrue(s.no_duplicates(arr)) arr += [9] self.assertFalse(s.no_duplicates(arr))
def test_position_originals(self): self.table = ["53xx7xxxx", "6xx195xxx", "x98xxxx6x", "8xxx6xxx3", "4xx8x3xx1", "7xxx2xxx6", "x6xxxx28x", "xxx419xx5", "xxxx8xx79"] self.sudoku = Sudoku(self.table, 9) self.assertEqual(self.sudoku.ori_pos, ["00", "01", "04", "10", "13", "14", "15", "21", "22", "27", "30", "34", "38", "40", "43", "45", "48", "50", "54", "58", "61", "66", "67", "73", "74", "75", "78", "84", "87", "88"])
def ingresar_tamaño_tablero(self):#se ingresa el tamaño del tablero self.tamaño = 0 while self.tamaño != "9" and self.tamaño != "4": self.tamaño = input("Ingrese el tamaño del tablero (4/9)\n") if self.tamaño != "9" and self.tamaño != "4": print("Ingrese el tamaño del tablero nuevamente\n") self.tamaño = int(self.tamaño) self.board = api(int(self.tamaño)) self.game = Sudoku(self.board)
def test_Sudoku_Gano(self): sudoku = Sudoku([["4", "1", "3", "8", "2", "5", "6", "7", "9"], ["5", "6", "7", "1", "4", "9", "8", "3", "2"], ["2", "8", "9", "7", "3", "6", "1", "4", "5"], ["1", "9", "5", "4", "6", "2", "7", "8", "3"], ["7", "2", "6", "9", "8", "3", "5", "1", "4"], ["3", "4", "8", "5", "1", "7", "2", "9", "6"], ["8", "5", "1", "6", "9", "4", "3", "2", "7"], ["9", "7", "2", "3", "5", "8", "4", "6", "1"], ["6", "3", "4", "2", "7", "1", "9", "5", "8"]]) self.assertTrue(sudoku.gano())
def test_Sudoku_Perdio(self): sudoku = Sudoku([["5", "3", "x", "x", "x", "7", "x", "x", "x"], ["6", "x", "x", "1", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.assertFalse(sudoku.gano())
def test_Sudoku_Valores_Fijos(self): sudoku = Sudoku([["5", "3", "x", "x", "7", "x", "x", "x", "x"], ["6", "x", "x", "1", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "3", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.assertFalse(sudoku.ingresar_numero(0, 0, 1))
def test_Sudoku_Zona(self): sudoku = Sudoku([["5", "3", "x", "x", "x", "7", "x", "x", "x"], ["6", "x", "x", "1", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.assertFalse(sudoku.ingresar_numero(2, 2, 5))
def test_Sudoku_Columna_2(self): sudoku = Sudoku([["5", "3", "x", "x", "x", "7", "x", "x", "x"], ["6", "x", "x", "1", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.assertFalse(sudoku.ingresar_numero(0, 8, 9))
def find_options_test(self): grid = [[5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9]] s = Sudoku(grid) self.assertEqual(s.find_options(0, 2), {1, 2, 4}) self.assertEqual(s.find_options(4, 4), {5}) self.assertEqual(s.find_options(5, 1), {1, 5}) self.assertEqual(s.find_options(8, 6), {1, 3, 4, 6})