def start():
    chx = 4
    while chx not in (1, 2):
        chx = int(
            input(
                "Souhaiter vous entrer votre propre sudoku ou aller chercher cette grille dans un fichier ? (\"1\", \"2\") : "
            ))
    if chx == 2:
        fichier = input(
            "Veuillez saisir le nom du fichier (dans le meme dossier que les scripts) : "
        )
        ligne = input("Veullez saisir la ligne à lire dans le fichier : ")
        Sudoku = SudokuGrid.from_file(fichier, int(ligne))
    else:
        Sudoku = SudokuGrid.from_stdin()
    return Sudoku
 def test_02_from_stdin(self):
     with unittest.mock.patch('sys.stdin', iter(("123456789" * 9, ))):
         with unittest.mock.patch('builtins.input',
                                  return_value="123456789" * 9):
             grid = SudokuGrid.from_stdin()
Exemple #3
0
import sys
from grid import SudokuGrid

# python -i src/play_sudoku.py sudoku_db.txt 4

if len(sys.argv) == 3:
    grid = SudokuGrid.from_file(sys.argv[1], int(sys.argv[2]))
else:
    grid = SudokuGrid.from_stdin()

while len(grid.get_empty_pos()):
    print(grid)

    row = input("Ligne : ")
    col = input("Colonne : ")
    val = input("Valeur : ")

    input_ok = True
    if row.isdigit() and col.isdigit():
        row = int(row)
        col = int(col)
        val = int(val)

        if not (0 <= row <= 8 and 0 <= col <= 8 and 1 <= val <= 9):
            input_ok = False
        if grid.grid[row][col]:
            input_ok = False
    else:
        input_ok = False

    if not input_ok:
Exemple #4
0
 def __init__(self):
     try:
         self.grille = SudokuGrid.from_file(sys.argv[1], int(sys.argv[2]))
     except IndexError:
         self.grille = SudokuGrid.from_stdin()
     self.grille_initial = self.grille.copy()
Exemple #5
0
from grid import SudokuGrid

fichier = str(input("Saisissez le nom du fichier : "))
ligne = int(input("Numero de ligne : "))

try:
    sudoku = SudokuGrid.from_file(fichier, ligne)
except:
    sudoku = SudokuGrid.from_stdin()

i = 0
while i == 0:
    print(sudoku)
    hor = int(input("Coordonnees de l'horizontale : "))
    ver = int(input("Coordonnees de la verticale : "))
    val = int(input("Valeur : "))
    print(hor)
    while hor < 0 or hor > 8:
        print("Saisissez une valeur correcte (entre 0 et 8)")
        hor = int(input("Coordonnees de l'horizontale : "))
    while ver < 0 or ver > 8:
        print("Saisissez une valeur correcte (entre 0 et 8)")
        ver = int(input("Coordonnees de la verticale : "))
    while val < 1 or val > 9:
        print("Saisissez une valeur correcte (entre 1 et 9)")
        val = int(input("Valeur : "))

    sudoku.write(ver, hor, val)