Guest User

Untitled

a guest
Oct 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. class Sudoku
  2. import turtle
  3. import random
  4.  
  5. #five unsolved 4x4 puzzles
  6. incompPuzzle1 = [[1,0,0,2],[0,3,0,0],[0,0,2,0],[3,0,0,4]]
  7. incompPuzzle2 = [[4,0,2,0],[0,1,0,0],[0,0,3,0],[0,4,0,2]]
  8. incompPuzzle3 = [[1,0,4,0],[0,2,0,0],[0,0,3,0],[0,1,0,4]]
  9. incompPuzzle4 = [[1,0,3,0],[0,0,0,2],[4,0,0,0],[0,1,0,3]]
  10. incompPuzzle5 = [[0,4,0,2],[0,0,3,0],[0,1,0,0],[4,0,2,0]]
  11.  
  12. #solved 4x4s
  13. compPuzzle1 = [[1,4,3,2],[2,3,4,1],[4,1,2,3],[3,2,1,4]]
  14. compPuzzle2 = [[4,3,2,1],[2,1,4,3],[1,2,3,4],[3,4,1,2]]
  15. compPuzzle3 = [[1,3,4,2],[4,2,1,3],[2,4,3,1],[3,1,2,4]]
  16. compPuzzle4 = [[1,2,3,4],[3,4,1,2],[4,3,2,1],[2,1,4,3]]
  17. compPuzzle5 = [[3,4,1,2],[1,2,3,4],[2,1,4,3],[4,3,2,1]]
  18.  
  19. def randomPuzzle():
  20. # generates a random int that corresponds with one of the incomplete puzzles above and then returns a global matrix out of that incomplete puzzle that will be where the values entered by the user can be stored without altering the original incomplete matrix
  21. x = random.randint(1,6)
  22. if x == 1:
  23. global workingMatrix = incompPuzzle1[:]
  24. return workingMatrix
  25. if x == 2:
  26. global workingMatrix = incompPuzzle2[:]
  27. return workingMatrix
  28. if x == 3:
  29. global workingMatrix = incompPuzzle3[:]
  30. return workingMatrix
  31. if x == 4:
  32. global workingMatrix = incompPuzzle1[:]
  33. return workingMatrix
  34. if x == 5:
  35. global workingMatrix = incompPuzzle1[:]
  36. return workingMatrix
  37.  
  38. def drawGrid():
  39. x = 300
  40. y = 300
  41. l = 300
  42. turtle.right(90) #vertical lines drawn first so turtle must be turned to the right
  43. for i in xrange(5):
  44. for j in xrange(5):
  45. if j%2==0: # even numbered lines are thicker, so frame and subgrids are thicker
  46. turtle.pensize(10)
  47. turtle.penup()
  48. turtle.goto(x,y)
  49. turtle.down()
  50. turtle.forward(l)
  51. x = x - 0.2x
  52. else
  53. turtle.penup()
  54. turtle.goto(x,y)
  55. turtle.down()
  56. turtle.forward(l)
  57. x = x - 0.2x
  58. turtle.left(90) #returns to facing right from before
  59. if i%2 == 0: #thicker lines for even numbered iterations
  60. turtle.pensize(10)
  61. turtle.penup()
  62. turtle.goto(x,y)
  63. turtle.down()
  64. turtle.forward(l)
  65. y = y - 0.2y
  66. else
  67. turtle.penup()
  68. turtle.goto(x,y)
  69. turtle.down()
  70. turtle.forward(l)
  71. y = y - 0.2y
  72. turtle.goto()
  73. turtle.write(workingMatrix[i][j], move=False, align="left", font=("Arial", 28, "normal"))
  74.  
  75. def fillKnownGrid():
  76. # take global matrix and use a for loop to populate grid with all non-zero elements
  77. for i in workingMatrix:
  78. for j in workingMatrix[i]:
  79. if workingMatrix[i][j] != 0:
  80. turtle.goto(37.5 + j*75, 262.5 - i*75)
  81. turtle.write(workingMatrix[i][j], move=False, align="left", font=("Arial", 28, "normal"))
  82. def getLocationInput():
  83. str userColumnEntry =
  84.  
  85. def getNumInput():
  86. int userGuess = turtle.numiput("Sudoku", "Enter your guess: " minval = 1, maxval = 4);
  87. return userGuess
  88.  
  89. def isValidInputrealtime():
  90. if getNumInput() > 4 or getNumInput() < 1:
  91. return false
  92. # checks row for duplicates
  93. for el in workingMatrix
  94. if getNumInput()
  95.  
  96. def interface():
  97. drawGrid()
  98.  
  99. randomPuzzle()
  100.  
  101. fillKnownGrid()
  102.  
  103. playSudoku()
  104. # prompt whether user wants to play in real time; if user wants to play in real time display rules and prompt
  105. str decide = turtle.textinput("Play in realtime?", "if you would like to play in real time, please press the 'y' key, if not press any other key:")
  106. if decide == y:
  107.  
  108. else:
  109.  
  110. interface()
  111.  
  112. prompt whether user wants to play in real time
  113. if user wants to play in real time
  114. display rules and prompt
Add Comment
Please, Sign In to add comment