sudoku.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. from copy import deepcopy
  3. MAX_V = 9
  4. class Game:
  5. def __init__(self):
  6. board = []
  7. for x in range(MAX_V):
  8. row = []
  9. for y in range(MAX_V):
  10. row.append(0)
  11. board.append(row)
  12. self.board = board
  13. def printBoard(self):
  14. for x in range(MAX_V):
  15. if x%3==0:
  16. print()
  17. for y in range(MAX_V):
  18. if y%3==0:
  19. print(" ", end="")
  20. print(self.board[x][y], end="")
  21. print()
  22. print()
  23. def setValue(self, x, y, value):
  24. if x >= MAX_V or y >= MAX_V:
  25. raise OutOfRangeError('Coordinates out of range.')
  26. if value > MAX_V:
  27. raise OutOfRangeError('Value out of range.')
  28. self.board[x][y] = value
  29. def getBoard(self):
  30. return deepcopy(self.board)
  31. if __name__ == "__main__":
  32. game = Game()
  33. game.printBoard()
  34. game.setValue(8,8,9)
  35. game.printBoard()
  36. print(game.getBoard())