Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sudoku.py #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions gui/sudoku.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse

from Tkinter import Tk, Canvas, Frame, Button, BOTH, TOP, BOTTOM
from tkinter import Tk, Canvas, Frame, Button, BOTH, TOP, BOTTOM

BOARDS = ['debug', 'n00b', 'l33t', 'error'] # Available sudoku boards
MARGIN = 20 # Pixels around the board
Expand Down Expand Up @@ -68,7 +68,7 @@ def __draw_grid(self):
"""
Draws grid divided with blue lines into 3x3 squares
"""
for i in xrange(10):
for i in range(10):
color = "blue" if i % 3 == 0 else "gray"

x0 = MARGIN + i * SIDE
Expand All @@ -85,8 +85,8 @@ def __draw_grid(self):

def __draw_puzzle(self):
self.canvas.delete("numbers")
for i in xrange(9):
for j in xrange(9):
for i in range(9):
for j in range(9):
answer = self.game.puzzle[i][j]
if answer != 0:
x = MARGIN + j * SIDE + SIDE / 2
Expand Down Expand Up @@ -203,20 +203,20 @@ def __init__(self, board_file):
def start(self):
self.game_over = False
self.puzzle = []
for i in xrange(9):
for i in range(9):
self.puzzle.append([])
for j in xrange(9):
for j in range(9):
self.puzzle[i].append(self.start_puzzle[i][j])

def check_win(self):
for row in xrange(9):
for row in range(9):
if not self.__check_row(row):
return False
for column in xrange(9):
for column in range(9):
if not self.__check_column(column):
return False
for row in xrange(3):
for column in xrange(3):
for row in range(3):
for column in range(3):
if not self.__check_square(row, column):
return False
self.game_over = True
Expand All @@ -230,15 +230,15 @@ def __check_row(self, row):

def __check_column(self, column):
return self.__check_block(
[self.puzzle[row][column] for row in xrange(9)]
[self.puzzle[row][column] for row in range(9)]
)

def __check_square(self, row, column):
return self.__check_block(
[
self.puzzle[r][c]
for r in xrange(row * 3, (row + 1) * 3)
for c in xrange(column * 3, (column + 1) * 3)
for r in range(row * 3, (row + 1) * 3)
for c in range(column * 3, (column + 1) * 3)
]
)

Expand Down