-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoku.py
130 lines (66 loc) · 2.26 KB
/
sudoku.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class sudok():
def __init__(self, tablero):
self.tablero = [[0 for __ in range(9)] for _ in range(9)]
self.tableroV = tablero
i = -1
j = -1
for fila in self.tableroV:
i += 1
j = -1
for valor in fila:
j += 1
if valor.isdigit():
self.tablero[i][j] = valor
if valor == 'x':
self.tablero[i][j] = valor
self.tableroV = self.tablero
def recorrer_fyc(self, num, i, j):
for columna in range (0,9):
if num == self.tablero[i][columna]:
return False
for fila in range (0,9):
if num == self.tablero[fila][j]:
return False
return True
def bloques(self, num, fila, columna):
if (fila < 3):
fila = 0
elif (fila >= 3 and fila <= 5):
fila = 3
else:
fila = 6
if (columna < 3):
columna = 0
elif (columna >= 3 and columna <= 5):
columna = 3
else:
columna = 6
for i in range(3): #"recorre de a tresen fila"
for j in range(3):#"lo mismo pero en columna"
if self.tablero[fila + i][columna + j] == num:
return False
return True
def tablerox(self, i, j):
if "x" == self.tableroV[i][j]:
return True
return False
def ganar(self):
for columna in range (0,9):
for fila in range (0,9):
if "x" == self.tablero[fila][columna]:
return False
return True
def ingresarnum(self,num, x ,y ):
if self.ganar() == True:
return 'ganaste'
if self.tablerox(x, y) == True:
if self.recorrer_fyc(num, x ,y) == True:
if self.bloques(num, x, y) == True:
self.tablero[x][y] = num
return "numero ingresado"
else:
return "ingrese otro numero"
else:
return "ingrese otro numero"
else:
return "coordenada equivocada"