Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solution.py to puzzle.py to highlight_digit.py GeneratePuzzle.py to digit_sqr.py button.py Node.py 1 2 Dimport time from copy import deepcopy 3 4 5 import pygame 6 7

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

solution.py to puzzle.py to highlight_digit.py GeneratePuzzle.py to digit_sqr.py button.py Node.py 1 2 Dimport time from copy import deepcopy 3 4 5 import pygame 6 7 8 from game. GeneratePuzzle import GeneratePuzzle from game.button import Button from game highlight_digit import HighlightDigit from sol import solution 9 10 11 12 13 14 15 class Puzzle: definit__(self): self.black = (0, 0, 0) self.white = (255, 255, 255) 16 17 18 19 self.dist = 200 20 21 pygame.init() pygame. font.init() 22 23 24 25 self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((600, 600)) pygame.display.set_caption('### 8 numbers sorting Puzzle ###') self.screen.fill(self.black) 26 27 28 29 self.generate-puzzle = GeneratePuzzle(self.screen) self.highlight HighlightDigit(self.screen) 30 31 32 D def initialization(self): 33 34 35 36 37 38 self.puzzle_numbers = self.generate_puzzle.generate_puzzle() self.generate_puzzle.draw_puzzle(self.puzzle_numbers) solve_button Button(self.screen, (255, 255, 153), 450, 100, 100, 50, "BFS") solve_button2 Button(self.screen, (255, 255, 153), 450, 200, 100, 50, "DFS") solve_button3 Button(self.screen, (255, 255, 153), 450, 300, 100, 50, "A Star") solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.finish = False = 39 40 41 42 to solution.py GeneratePuzzle.py digit_sqr.py button.py Node.py to puzzle.py I highlight_digit.py self.you_win = False 43 45 46 47 48 while not self.finish: self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) puzzle_prev = [] for event in pygame.event.get(): 49 50 51 52 53 54 pos = pygame.mouse.get_pos() # print(event) if event.type == pygame. QUIT: self.finish = True 55 56 57 58 59 60 61 62 63 if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_RIGHT or event.key == pygame.K_d): # print "*** RIGHT ***" puzzle_prev = self.puzzle_numbers self.you_win index1 index2 = self.highlight.highlight_digit_to_be_swapped (100, 0, "RIGHT", sell.puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index22,"right") if Iselit:puzzle numbers.mbantem nem minden embereme 12: self. you_win = True else: self.you_win = False 64 65 66 67 68 69 70 71 72 73 74 75 76 if(event.key ==Rygame.K_LEFT or event.key=pygame.K_a): # print "*** LEFT ***" self.you_win index1 index2 = self.highlight.highlight_digit_to_be_swapped (-100, 0, "LEFT", self.puzzle_numbers) self.generate-puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index2"Left") if (selt puzzle numbers. Omd de derde 5.dembenem )): self.you_win = True else: self.you_win = False 77 78 79 80 81 82 83 if (event.keypygame. K DOWNorevent.keypy.game.K.): # print "*** DOWN ***" self.you_win index1, index2 = self.highlight.highlight_digit_to_be_swapped(0, 100, "DOWN", 84 solution.py puzzle.py 85 86 87 88 89 highlight_digit.py X GeneratePuzzle.py for digit_sqr.py to button.py Node.py self-puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index2."Down") if (self.puzzle_numbers = 12mm 5.68]): self.you_win = True else: self.you_win = False 90 91 92 o 93 94 95 96 97 98 99 if (event.key == pygame.K_UP or event.key == pygame.K_w): # print "*** UP **** self.you_win index1, index2 = self.highlight.highlight_digit_to_be_swapped(0, -100, "UP", self.puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1, index22"Up") if (sell puzzle numbers.mbhambamba namem. I.ambembem8]: self.you_win = True else: self.you_win = False if event.type == pygame. MOUSEBUTTONDOWN: posx posy=pygame.mouse.get_pos() if solve_button.isOver (pos): print("BFS button") list = self.get_sol(1) for i in range(len(list)): a = list[i] 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 for j in range(0, 9): if (self puzzle_numbers[j] == 8): pos_eight = j temp = self.puzzle_numbers [pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [[ "None","Left","None"..."Up"..."None"..."None"..." "None", "None". "None"], ["Right" "None","Left","None". "Up" "None". "None", "None", "None"], ["None"."Right". "None"..."None".."None". "Up"2,"None"..."None"."None"] , ["Down". "None". "None". "None"."Left"&"None". "Up"."None". "None"], ["None". "Down". "None" ".. "Right".."None","Left" "None".. "Up". "None"], ["None","None", "Down" "None","Right", "None", "None","None", "Up"], 125 126 puzzle.py to highlight_digit.py I GeneratePuzzle.py Le digit_sqr.py button.py feNode.py X ["None", "None", "None", "Down", "None", "None", "None","Left":"None"] , ["None"."None".."None". "None"..."Down".."None".."Right".."None","Left"], ["None","None", "None", "None", "None", "Down" "None" "Right", "None"] ] Key=list_find(int(pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index2 index1, key) self.highlight.move_count("Moves: %s" % str(i)) pygame.display.update() time.sleep(1) if(sell puzzle numbers.wbOutube en behande8]): self.you_win = True else: self.you_win = False e solution.py 127 128 129 130 A 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 A 160 161 162 163 164 165 166 167 168 elif solve button2 isover.(pos.): print("DFS button") list = self.get_sol(2). for i in range(len(list)): a = list[i] for j in range(0, 9): if (self:puzzle numbers[j] == 8): pos_eight = j temp = self.puzzle_numbers [pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [["None", "Left", "None", "Up", "None", "None", "None", "None", "None"], ["Right", "None", "Left", "None", "Up", "None", "None", "None", "None"] , e puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py ["None", "Right", "None", "None", "None", "Up", "None", "None", "None"], ["Down", "None", "None", "None", "Left", "None", "Up", "None", "None"], ["None", "Down", "None", "Right", "None", "Left", "None", "Up", "None"] , ["None", "None", "Down", "None", "right", "None" "None", "None", "Up"], ["None", "None", "None", "Down", "None" "None", "None", "Left", "None"] , ["None", "None", "None", "None", "Down", "None", "Right", "None", "Left"], ["None", "None", "None", "None", "None", "Down", "None", "Right", "None" ] ] solution.py 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 Key. = list_find(int(pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers, index2, index1, Key) self.highlight.move_count("Moves: %s" % str(i)) pygame.display.update() time.sleep(1) if (self:puzzle numbers. Oumtumbambambam.com im8]): self.you_win = True else: self.you_win = False elif solve button3.isover.(pos): print("A star button") list = self.get_sol(3). 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 for i in range(len(list)): a = list[i] for j in range(0, 9): if (sell.puzzle_numbers[j] == 8): pos_eight = ) temp = self.puzzle_numbers[pos_eight] self.puzzle_numbers[pos_eight] = self.puzzle_numbers[a] e puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py x temp = self.puzzle_numbers[pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [["None", "Left", "None", "Up", "None", "None", "None", "None", "None"], ["Right", "None", "Left", "None", "Up", "None", "None", "None", "None"], ["None", "Right", "None", "None", "None", "Up", "None", "None", "None"] , ["Down", "None", "None", "None", "Left", "None", "Up", "None", "None"], ["None", "Down", "None", "Right", "None", "Left", "None", "Up", "None"] , ["None", "None", "Down", "None", "right", "None", "None", "None", "Up"], ["None", "None", "None", "Down", "None", "None", "None", "Left", "None"], ["None", "None", "None", "None", "Down", "None", "right", "None", "Left"], ["None", "None", "None", "None", "None", "Down", "None", "Right", "None"] ] solution.py 208 209 210 211 212 213 214 215 o 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 o 244 245 246 247 248 249 Key. = list_find(int (pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle. draw_puzzle_animate(self.puzzle_numbers, index2, index1, Key) self.highlight.move_count("Moves: %S" % str(i)) pygame.display.update() time. sleep(1) if (self.puzzle numbers == [ Qu.m8]): self.you_win = True else: self.you_win = False elif posx > 100 and posx 98 and posy 400: posx.poy = pygame.mouse.get_pos() self.you_win index1 index2, Key = self.highlight.highlight_digit_to_be_swapped_click(posx poy self-puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1, index2 Key) solution.py puzzle.py button.py x Node.py 250 251 highlight_digit.py GeneratePuzzle.py e digit_sqr.py if(self.:puzzle numbers= [0,1,2,3,4,5,6718]): self.you_win = True else: self.you_win = False 252 253 A 254 255 256 257 258 259 260 261 262 if event.type == pygame .MOUSEMOTION: if solve_button.isOver (pos): solve_button.color = (0, 204, 0) elif solve_button2. isOver (pos): solve_button2.color=(0,204,0) elif solve_button3. isOver (pos): solve_button3.color=(2040) else: solve_button.color = (255, 255, 0) solve_button2.color = (255, 255, 0) solve_button3.color = (255, 255, 0) 263 264 265 266 267 D 268 269 -D 270 271 272 273 274 if self.you_win: self.highlight.move_count("8 Puzzle Puzzle", 130, 10) self.highlight.move_count("You Win !!!", 130, 450) pygame.display.update() self.clock.tick(30) time.sleep (2) self.screen.fill(self.black) self.puzzle_numbers = [0,1,2,3,4,5,6,7,8] self.highlight.m_count = 0 self.you_win self.highlight.highlight_digit_to_be_swapped(0, -100, "UP", self.puzzle_numbers) self.generate_puzzle.draw_puzzle(self.puzzle_numbers) 275 276 277 278 279 280 281 282 self.you_win = False self.finish = False 283 O 284 285 pygame.display.update() self.clock.tick (60) 286 287 288 pygame.quit() quito 289 290 291 def get_sol(self button): solution.py Le puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py X Node 292 293 counter = 0 if (button == 1): list = solution.bfs(self.puzzle_numbers) 294 295 296 A 297 298 return list if (button == 2): List = solution.dfs(self.puzzle_numbers) return list if (button == 3): list = solution.astar(self.puzzle_numbers) 299 0-D 300 301 302 303 A return list 304 305 306 def swap(self board_path index2): pos_missing = 0 307 308 309 310 311 312 313 for i in range(len(board_path)): for j in range(len(self.puzzle_numbers)): if self.puzzle_numbers [j] ==9: pos_missing = j a= board_path[i] temp self.puzzle_numbers[board_path[i]] self.puzzle_numbers[board_path[i]] = self.puzzle_numbers [pos_missing] self.puzzle_numbers [pos_missing] = temp self.generate_puzzle.draw_puzzle(self.puzzle_numbers) pygame.display.update() 314 315 316 317 318 A 319 320 321 322 323 324 325 a return False 326 327 328 329 if __name__ ' __main__': puzzle Puzzle() puzzle, initialization() 330 331 e solution.py to puzzle.py to highlight_digit.py to GeneratePuzzle.py digit_sqr.py button.py Node.py X 3 4. 5 import pygame Dimport time 6 7 8 9 Eclass HighlightDigit: def init__(self, screen): self.black = (0, 0, 0) self.white = (255, 255, 255) self.screen = screen 10 11 12 13 14 15 self.highlight_x = 200 self.highlight_y = 200 self.highlight_side = 100 16 17 18 19 self.hfont = pygame.font.SysFont("Segoe Print', 30) self.highlight_digit = pygame.draw.rect(self.screen, self.white, [self.highlight_x, self.highlight_y, self.highlight_side, self.highlight_side), 5) A 20 21 22 23 24 self.index = 0 self.m_count = 0 25 def highlight_digit_to_be_swapped(self, X, Y, key, puzzle): self.index = int(((self.highlight_digit.y - 100) / 100) * 3 + ((self.highlight_digit.x1100))) 26 self-highlight X.mintisel.highlight_digit: XX. self.highlight_y = int(self.highlight_digit.y + y) 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 if self.highlight_x = 98 and self.highlight. >= 98 and self.highlight_200 and posx100 and posy= 98 and self.highlight 98 and self.highlight 1300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) 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 pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if Spuzzlelo8): return self.swap(1, 0, puzzle)04.1_,"Left" elif Spuzzle2.8): return self.swap(1, 2, puzzle) 2.1"Right" elif Spuzzlel4l =8): return self.swap(14.4.puzzle)..4-12. "Down" elif posx>300 and posx100 and posy= 98 and self.highlight 98 and self.highlight 300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if (puzzle 1.8): return self.swap(2, 1, puzzle)..1422,"Left" elif Spuzzlella): return self swan (2 nuzzle) 5 2 "Down" 5 puzzle.py button.py highlight_digit.py to GeneratePuzzle.py digit_sqr.py return self.swap (2, 5, puzzle) 5.2" Down" Node.py X Io solution.py 128 129 130 131 o 132 133 134 135 136 137 138 139 ######2nd row ############ if posx>100 and posx200 and posy200 and posx200 and posy= 98 and self.highlight_y >= 98 and self.highlight_y 300 and posx200 and posy100 and posx300 and posy= 98 and self.highlight 98 and self.highlight 300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if (puzzle 3) == 8): return self.swap(6, 3, puzzle) 2.32.62."Up" elif (puzzlez)=8): return self swan(6. nuzzle) 7 6 "Riaht" 7 e puzzle.py fe button.py Node.py X highlight_digit.py GeneratePuzzle.py digit_sqr.py return self.swap(6, 7, puzzle).7.6., "Right" elif posx>200 and posx300 and posy300 and posx300and posy200 and posx300 and posy300 and posx300and posy300 and posx 400 and posy>300 and posy= 98 and self-hig self.screen.fill(self.black) self.highlight_digit self.highlight_digit.move(x, y) 244 o 245 246 247 248 249 250 pygame.draw.rect(self.screen, self.white, self.highlight_digi if (puzzle[5] == 8): return self.swap(8, 5, puzzle)5282,"Up" elif spuzzle7) == 8): return self.swap(8, 7, puzzle)-728..."Left" 251 252 253 254 255 256 257 return False None 258 259 260 261 262 DD 263 264 def move_count (self text.mx=50 X=400): try: self.hfont.render(text, True, self.white) self:htextsurface = self.hfont.render(text, True, self.white) self.screen.blit(self.htextsurface, (x, y)) 265 266 A 267 268 o 269 except Exception as e: # print 'Font Error, saw it coming' raise e 270 Q 271 La GeneratePuzzle.py o digit_sqr.py button.py Node.py Le solution.py to puzzle.py to highlight_digit.py 3 Dimport random import pygame 5 from game.digit_sar import Digitsar 6 7 8 10 class GeneratePuzzle: def _init__(self, screen): self.screen = screen self.digits = [] self.generate_puzzle() self.digit_sar = Digitsqr(self.screen) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 def generate puzzle(self): puzzle = [02122232425262728] del self.digits[:] possible_moves = [[1, 3], [0, 2, 4), (1, 5], [0, 4, 6], [1, 3, 5, 7], [2, 4, 8], [3, 7], [4, 6, 8], [5, 7]] for i in range(0, 5): for j in range(0, 9): if (puzzle[j] == 8): pos = j new_pos = random.choice (possible_moves[pos]) temp = puzzle[pos] puzzle[pos] = puzzle[new_pos] puzzle [new_pos] = temp a 26 27 28 29 30 return puzzle 31 32 33 34 35 def draw_puzzle(self, digits): counter_X = 1 counter-y = 1 puzzle = [] for digit in digits: puzzle.append(self.digit_sqr.design( digit, 100 * counter_x, 100 * counter-y)) O 36 37 38 39 40 41 counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 42 43 44 return puzzle solution.py te puzzle.py highlight_digit.py X GeneratePuzzle.py to digit_sqr.py button.py Node.py 39 40 o counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 41 42 A 43 44 45 46 47 48 49 o 50 51 52 53 return puzzle def draw_puzzle_animate(self digits index1 index2 Key): counter_X = 1 counter-y 1 puzzle = [] for digit in digits: if(digit != digits[index1) and digit != digits[index2]): self.digit_sqr.design (digit, 100 * counter_x, 100 * counter_y) counter_x += 1 if counter_x % 4 == 0: counter_X = 1 counter-y += 1 if(digits[index2] ==8): self.digit_sqr.animation(digits[index1), Key_index1, index2) else: counter_x = 1 counter-y = 1 puzzle [] for digit in digits: puzzle.append(self.digit_sqr.design digit, 100 * counter_x, 100 * counter-y)) 54 55 A 56 57 58 59 60 61 62 o 63 64 65 66 counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 67 68 69 70 71 72 73 74 75 76 77 e return puzzle 78 79 Io solution.py to puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py 3 4 import pygame from game.button import Button Efrom game.highlight_digit import HighlightDigit 6 7 8 TIME = 5 9 10 11 12 13 14 15 class Digitsgro: def __init__(self, screen): self.screen = screen self.green = (100, 100, 100) self.dark_green = (, 255, 0) self.black = (0, 0, 0) self.white = (255, 255, 255) self.myfont = pygame.font.SysFont('Comic Sans MS', 30) self.digit = -1 self.sqr_side = 98 A self.highlight = HighlightDigit(self.screen) 16 17 18 19 20 22 23 24 25 def design(self digit, sqr_x, sqr-y): self.digit = digit self.rect = pygame.draw.rect(self.screen, self.green, (sqr_x, sqr-y, self.sqr_side, self.sqr_side)) if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8 select = pygame.draw.rect(self.screen, self.black, (sqr_x, sqr_y, self.sqr_side, self.sqr_side)) 26 27 28 A 29 30 31 32 33 34 35 def animation(self digit, key index1.index2): self.digit = digit list_sar = [[100_100],[200,100],[300,100],[100,200],[200_200],[300,200],[100,300],[200,300],[300,300]] index_variable_x = list_sqr(index2][0] index_variable-y = list_sqr(index2][1] self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button = Button(self.screen, (255, 255, 153), 450, 100, 100, 50, "BFS") solve_button2 = Button(self.screen, (255, 255, 153), 450, 200, 100, 50, "DFS") solve_button3 = Button(self.screen, (255, 255, 153), 450, 300, 100, 50, "A Star") solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) 36 37 38 39 40 41 42 43 1=0 counter = 0 44 fs solution.py 45 46 47 48 49 50 51 52 puzzle.py to highlight_digit.py to GeneratePuzzle.py digit_sqr.py fe button.py X Node.py LUUIILUI for i in range(0,101, TIME): if (kex=Right.: self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variable_y, self.sqr_side self.sqr_side)) self.rect = pygame.draw.rect(self.screen, self.green, (index_variable_x + i, index_variable_y, self.sgr_side, self.sqr_side)) if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x + i, index_variable_y, self.sar-side, self.sqr_side)) pygame.display.update() elif (key=="left"): self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variable_y, self.sqr_side, self.sqr_side)) self.rect = pygame.draw.rect(self.screen, self.green, (index_variable_x - i, index_variable_y, self.sgr-side, self.sqr_side)) if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x - i, index_variable_y, self.sgr-side, self.sqr_side)) 53 54 55 56 57 58 59 60 61 62 63 pygame.display.update() elif (key=="02: 64 65 66 67 68 self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variable_y, self.sqr_siden self.sqr_side)) self.rect = pygame.draw.rect(self.screen, self.green, (index_variable_x, index_variable_y - i, self.sor_side, self.sqr_side)) if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x.., index_variable_y+1, self.san-side, self.sqr_side)) 69 70 71 72 73 74 pygame.display:update elif (key=="Down"): 75 76 77 78 79 80 self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variable_y, self.spr_siden self.sgr_side)) self.rect = pygame.draw.rect(self.screen, self.green, (index_variable_xindex_variable_y + i, self.sqr_side, self.sqr_side)) 81 if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: sel:rect = pygame.draw.rect(self.screen, self.black, (index_variable_xm, index_variable_y+i, self.sar-side, self.sqr_side)) 82 83 84 85 e pygame.display.update() solution.py puzzle.py ri 68 69 Po highlight_digit.py GeneratePuzzle.py x Lo digit_sqr.py button.py Node.py if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variabl 70 71 72 73 74 A pygame.display-update() elif (key=="Down"): 75 76 77 self.rect = pygame.draw.rect(self.screen, self.black, (index_variable_x, index_variable_y, self.rect = pygame.draw.rect(self.screen, self.green, (index_variable_x index_variable_y 78 79 80 81 if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8: select = pygame.draw.rect(self.screen, self.black, (index_variable_xm, index_variabi 82 83 84 85 pygame.display.update() 86 87 88 89 - counter += 1 90 91 92 93 94 95 D D 96 97 def.textto-screen(selfdtextielle try: text = str(text) self.textsurface = self.myfont.render(text, True, self.dark-green) self.screen.blit(self.textsurface, (x, y)) 98 99 100 101 except Exception as e: 102 103 - raise e 104 to puzzle.py to highlight_digit.py to GeneratePuzzle.py digit_sqr.py button.py Node.py x solution.py 1 1 2 3 import pygame 4 5 6 7 8 Eclass Button: def __init__(self, screen, color, x, y, width, height, text=''): self.color = color self.x = x self.y = y self.width = width self.height = height self.text = text self.screen = screen o def draw(self,outline=None): if outline: pygame.draw.rect(self.screen, outline, (self.x - 2, self.y - 2, self.width + 4, self.height + 4), 0) pygame.draw.rect(self.screen, self.color, (self.x, self.y, self.width, self.height), o) 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 if self.text != '': font = pygame.font.SysFont('comicsans', 30) text = font.render(self.text, 1, (0, 0, 0)) self.screen.blit(text, ( self.x + (self.width / 2 - text.get_width() / 2), self.y + (self.height / 2 - text.get_height() / 2))) def isover(self, pos): if pos[0] > self.x and pos[0] 345-... 382 018 swap with 2 342 - 6 75 342 675 6 75 6 75 6 7 8 So from this example, the right path should be {1, 2, 5, 8}. WHY? You may thought it was {4, 1, 2,5}, since the number 8 has swapped with them in this order. That is true. However, we do not care which number it swapped with, but which position the number 8 has gone through. As the numbers can be in any positions during different time, which give no hint about where the number 8 is. In contrast, the positions are fixed. So we assume the positions are in the same order as an increasing sequence: [O] [1] [2] Fixed Position = [3] [4] [5] [6] [7] [8] Here, I use "t" to distinguish the positions from the numbers. So now you can see, the number 8 starts from position [4], then swapped with number 4, which goes to the position [1]; then swapped with number 1, which goes to the position [2]; then swapped with number 2, which goes to the position [5]; finally, swapped with number 5, which goes to the position [8]. So the path you should assign to the parameter "&solution" with the path sequence {1, 2, 5, 8). solution.py Le puzzle.py highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py 2 #This is the only file you need to work on: You do NOT need to modify other files 3 # Below are the functions you need to implement. For the first project..you only need to finish implementing bfs and dfs. 5 6 7 8 9 #here you need to implement the Breadth First Search Method Edef bfs(puzzle): list = [] return list 10 11 12 13 14 #here you need to implement the Depth First Search Method def dfs (puzzle): List = [] A return list 15 16 17 18 19 20 21 22 23 #This will be for next project def astar(puzzle): list = [] return list solution.py to puzzle.py to highlight_digit.py GeneratePuzzle.py to digit_sqr.py button.py Node.py 1 2 Dimport time from copy import deepcopy 3 4 5 import pygame 6 7 8 from game. GeneratePuzzle import GeneratePuzzle from game.button import Button from game highlight_digit import HighlightDigit from sol import solution 9 10 11 12 13 14 15 class Puzzle: definit__(self): self.black = (0, 0, 0) self.white = (255, 255, 255) 16 17 18 19 self.dist = 200 20 21 pygame.init() pygame. font.init() 22 23 24 25 self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((600, 600)) pygame.display.set_caption('### 8 numbers sorting Puzzle ###') self.screen.fill(self.black) 26 27 28 29 self.generate-puzzle = GeneratePuzzle(self.screen) self.highlight HighlightDigit(self.screen) 30 31 32 D def initialization(self): 33 34 35 36 37 38 self.puzzle_numbers = self.generate_puzzle.generate_puzzle() self.generate_puzzle.draw_puzzle(self.puzzle_numbers) solve_button Button(self.screen, (255, 255, 153), 450, 100, 100, 50, "BFS") solve_button2 Button(self.screen, (255, 255, 153), 450, 200, 100, 50, "DFS") solve_button3 Button(self.screen, (255, 255, 153), 450, 300, 100, 50, "A Star") solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.finish = False = 39 40 41 42 to solution.py GeneratePuzzle.py digit_sqr.py button.py Node.py to puzzle.py I highlight_digit.py self.you_win = False 43 45 46 47 48 while not self.finish: self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) puzzle_prev = [] for event in pygame.event.get(): 49 50 51 52 53 54 pos = pygame.mouse.get_pos() # print(event) if event.type == pygame. QUIT: self.finish = True 55 56 57 58 59 60 61 62 63 if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_RIGHT or event.key == pygame.K_d): # print "*** RIGHT ***" puzzle_prev = self.puzzle_numbers self.you_win index1 index2 = self.highlight.highlight_digit_to_be_swapped (100, 0, "RIGHT", sell.puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index22,"right") if Iselit:puzzle numbers.mbantem nem minden embereme 12: self. you_win = True else: self.you_win = False 64 65 66 67 68 69 70 71 72 73 74 75 76 if(event.key ==Rygame.K_LEFT or event.key=pygame.K_a): # print "*** LEFT ***" self.you_win index1 index2 = self.highlight.highlight_digit_to_be_swapped (-100, 0, "LEFT", self.puzzle_numbers) self.generate-puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index2"Left") if (selt puzzle numbers. Omd de derde 5.dembenem )): self.you_win = True else: self.you_win = False 77 78 79 80 81 82 83 if (event.keypygame. K DOWNorevent.keypy.game.K.): # print "*** DOWN ***" self.you_win index1, index2 = self.highlight.highlight_digit_to_be_swapped(0, 100, "DOWN", 84 solution.py puzzle.py 85 86 87 88 89 highlight_digit.py X GeneratePuzzle.py for digit_sqr.py to button.py Node.py self-puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1 index2."Down") if (self.puzzle_numbers = 12mm 5.68]): self.you_win = True else: self.you_win = False 90 91 92 o 93 94 95 96 97 98 99 if (event.key == pygame.K_UP or event.key == pygame.K_w): # print "*** UP **** self.you_win index1, index2 = self.highlight.highlight_digit_to_be_swapped(0, -100, "UP", self.puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1, index22"Up") if (sell puzzle numbers.mbhambamba namem. I.ambembem8]: self.you_win = True else: self.you_win = False if event.type == pygame. MOUSEBUTTONDOWN: posx posy=pygame.mouse.get_pos() if solve_button.isOver (pos): print("BFS button") list = self.get_sol(1) for i in range(len(list)): a = list[i] 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 for j in range(0, 9): if (self puzzle_numbers[j] == 8): pos_eight = j temp = self.puzzle_numbers [pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [[ "None","Left","None"..."Up"..."None"..."None"..." "None", "None". "None"], ["Right" "None","Left","None". "Up" "None". "None", "None", "None"], ["None"."Right". "None"..."None".."None". "Up"2,"None"..."None"."None"] , ["Down". "None". "None". "None"."Left"&"None". "Up"."None". "None"], ["None". "Down". "None" ".. "Right".."None","Left" "None".. "Up". "None"], ["None","None", "Down" "None","Right", "None", "None","None", "Up"], 125 126 puzzle.py to highlight_digit.py I GeneratePuzzle.py Le digit_sqr.py button.py feNode.py X ["None", "None", "None", "Down", "None", "None", "None","Left":"None"] , ["None"."None".."None". "None"..."Down".."None".."Right".."None","Left"], ["None","None", "None", "None", "None", "Down" "None" "Right", "None"] ] Key=list_find(int(pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index2 index1, key) self.highlight.move_count("Moves: %s" % str(i)) pygame.display.update() time.sleep(1) if(sell puzzle numbers.wbOutube en behande8]): self.you_win = True else: self.you_win = False e solution.py 127 128 129 130 A 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 A 160 161 162 163 164 165 166 167 168 elif solve button2 isover.(pos.): print("DFS button") list = self.get_sol(2). for i in range(len(list)): a = list[i] for j in range(0, 9): if (self:puzzle numbers[j] == 8): pos_eight = j temp = self.puzzle_numbers [pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [["None", "Left", "None", "Up", "None", "None", "None", "None", "None"], ["Right", "None", "Left", "None", "Up", "None", "None", "None", "None"] , e puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py ["None", "Right", "None", "None", "None", "Up", "None", "None", "None"], ["Down", "None", "None", "None", "Left", "None", "Up", "None", "None"], ["None", "Down", "None", "Right", "None", "Left", "None", "Up", "None"] , ["None", "None", "Down", "None", "right", "None" "None", "None", "Up"], ["None", "None", "None", "Down", "None" "None", "None", "Left", "None"] , ["None", "None", "None", "None", "Down", "None", "Right", "None", "Left"], ["None", "None", "None", "None", "None", "Down", "None", "Right", "None" ] ] solution.py 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 Key. = list_find(int(pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers, index2, index1, Key) self.highlight.move_count("Moves: %s" % str(i)) pygame.display.update() time.sleep(1) if (self:puzzle numbers. Oumtumbambambam.com im8]): self.you_win = True else: self.you_win = False elif solve button3.isover.(pos): print("A star button") list = self.get_sol(3). 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 for i in range(len(list)): a = list[i] for j in range(0, 9): if (sell.puzzle_numbers[j] == 8): pos_eight = ) temp = self.puzzle_numbers[pos_eight] self.puzzle_numbers[pos_eight] = self.puzzle_numbers[a] e puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py x temp = self.puzzle_numbers[pos_eight] self.puzzle_numbers [pos_eight] = self.puzzle_numbers[a] self.puzzle_numbers[a] = temp index2 = pos_eight index1 = a list_find = [["None", "Left", "None", "Up", "None", "None", "None", "None", "None"], ["Right", "None", "Left", "None", "Up", "None", "None", "None", "None"], ["None", "Right", "None", "None", "None", "Up", "None", "None", "None"] , ["Down", "None", "None", "None", "Left", "None", "Up", "None", "None"], ["None", "Down", "None", "Right", "None", "Left", "None", "Up", "None"] , ["None", "None", "Down", "None", "right", "None", "None", "None", "Up"], ["None", "None", "None", "Down", "None", "None", "None", "Left", "None"], ["None", "None", "None", "None", "Down", "None", "right", "None", "Left"], ["None", "None", "None", "None", "None", "Down", "None", "Right", "None"] ] solution.py 208 209 210 211 212 213 214 215 o 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 o 244 245 246 247 248 249 Key. = list_find(int (pos_eight)][int(a)] self.screen.fill(self.black) self.highlight.move_count("Puzzle Search Game ", 130, 10) solve_button.draw((255, 255, 0)) solve_button2.draw((255, 255, 0)) solve_button3.draw((255, 255, 0)) self.generate_puzzle. draw_puzzle_animate(self.puzzle_numbers, index2, index1, Key) self.highlight.move_count("Moves: %S" % str(i)) pygame.display.update() time. sleep(1) if (self.puzzle numbers == [ Qu.m8]): self.you_win = True else: self.you_win = False elif posx > 100 and posx 98 and posy 400: posx.poy = pygame.mouse.get_pos() self.you_win index1 index2, Key = self.highlight.highlight_digit_to_be_swapped_click(posx poy self-puzzle_numbers) self.generate_puzzle.draw_puzzle_animate(self.puzzle_numbers index1, index2 Key) solution.py puzzle.py button.py x Node.py 250 251 highlight_digit.py GeneratePuzzle.py e digit_sqr.py if(self.:puzzle numbers= [0,1,2,3,4,5,6718]): self.you_win = True else: self.you_win = False 252 253 A 254 255 256 257 258 259 260 261 262 if event.type == pygame .MOUSEMOTION: if solve_button.isOver (pos): solve_button.color = (0, 204, 0) elif solve_button2. isOver (pos): solve_button2.color=(0,204,0) elif solve_button3. isOver (pos): solve_button3.color=(2040) else: solve_button.color = (255, 255, 0) solve_button2.color = (255, 255, 0) solve_button3.color = (255, 255, 0) 263 264 265 266 267 D 268 269 -D 270 271 272 273 274 if self.you_win: self.highlight.move_count("8 Puzzle Puzzle", 130, 10) self.highlight.move_count("You Win !!!", 130, 450) pygame.display.update() self.clock.tick(30) time.sleep (2) self.screen.fill(self.black) self.puzzle_numbers = [0,1,2,3,4,5,6,7,8] self.highlight.m_count = 0 self.you_win self.highlight.highlight_digit_to_be_swapped(0, -100, "UP", self.puzzle_numbers) self.generate_puzzle.draw_puzzle(self.puzzle_numbers) 275 276 277 278 279 280 281 282 self.you_win = False self.finish = False 283 O 284 285 pygame.display.update() self.clock.tick (60) 286 287 288 pygame.quit() quito 289 290 291 def get_sol(self button): solution.py Le puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py X Node 292 293 counter = 0 if (button == 1): list = solution.bfs(self.puzzle_numbers) 294 295 296 A 297 298 return list if (button == 2): List = solution.dfs(self.puzzle_numbers) return list if (button == 3): list = solution.astar(self.puzzle_numbers) 299 0-D 300 301 302 303 A return list 304 305 306 def swap(self board_path index2): pos_missing = 0 307 308 309 310 311 312 313 for i in range(len(board_path)): for j in range(len(self.puzzle_numbers)): if self.puzzle_numbers [j] ==9: pos_missing = j a= board_path[i] temp self.puzzle_numbers[board_path[i]] self.puzzle_numbers[board_path[i]] = self.puzzle_numbers [pos_missing] self.puzzle_numbers [pos_missing] = temp self.generate_puzzle.draw_puzzle(self.puzzle_numbers) pygame.display.update() 314 315 316 317 318 A 319 320 321 322 323 324 325 a return False 326 327 328 329 if __name__ ' __main__': puzzle Puzzle() puzzle, initialization() 330 331 e solution.py to puzzle.py to highlight_digit.py to GeneratePuzzle.py digit_sqr.py button.py Node.py X 3 4. 5 import pygame Dimport time 6 7 8 9 Eclass HighlightDigit: def init__(self, screen): self.black = (0, 0, 0) self.white = (255, 255, 255) self.screen = screen 10 11 12 13 14 15 self.highlight_x = 200 self.highlight_y = 200 self.highlight_side = 100 16 17 18 19 self.hfont = pygame.font.SysFont("Segoe Print', 30) self.highlight_digit = pygame.draw.rect(self.screen, self.white, [self.highlight_x, self.highlight_y, self.highlight_side, self.highlight_side), 5) A 20 21 22 23 24 self.index = 0 self.m_count = 0 25 def highlight_digit_to_be_swapped(self, X, Y, key, puzzle): self.index = int(((self.highlight_digit.y - 100) / 100) * 3 + ((self.highlight_digit.x1100))) 26 self-highlight X.mintisel.highlight_digit: XX. self.highlight_y = int(self.highlight_digit.y + y) 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 if self.highlight_x = 98 and self.highlight. >= 98 and self.highlight_200 and posx100 and posy= 98 and self.highlight 98 and self.highlight 1300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) 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 pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if Spuzzlelo8): return self.swap(1, 0, puzzle)04.1_,"Left" elif Spuzzle2.8): return self.swap(1, 2, puzzle) 2.1"Right" elif Spuzzlel4l =8): return self.swap(14.4.puzzle)..4-12. "Down" elif posx>300 and posx100 and posy= 98 and self.highlight 98 and self.highlight 300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if (puzzle 1.8): return self.swap(2, 1, puzzle)..1422,"Left" elif Spuzzlella): return self swan (2 nuzzle) 5 2 "Down" 5 puzzle.py button.py highlight_digit.py to GeneratePuzzle.py digit_sqr.py return self.swap (2, 5, puzzle) 5.2" Down" Node.py X Io solution.py 128 129 130 131 o 132 133 134 135 136 137 138 139 ######2nd row ############ if posx>100 and posx200 and posy200 and posx200 and posy= 98 and self.highlight_y >= 98 and self.highlight_y 300 and posx200 and posy100 and posx300 and posy= 98 and self.highlight 98 and self.highlight 300: self.screen.fill(self.black) self.highlight_digit = self.highlight_digit.move(x, y) pygame.draw.rect(self.screen, self.white, self.highlight_digit, 5) if (puzzle 3) == 8): return self.swap(6, 3, puzzle) 2.32.62."Up" elif (puzzlez)=8): return self swan(6. nuzzle) 7 6 "Riaht" 7 e puzzle.py fe button.py Node.py X highlight_digit.py GeneratePuzzle.py digit_sqr.py return self.swap(6, 7, puzzle).7.6., "Right" elif posx>200 and posx300 and posy300 and posx300and posy200 and posx300 and posy300 and posx300and posy300 and posx 400 and posy>300 and posy= 98 and self-hig self.screen.fill(self.black) self.highlight_digit self.highlight_digit.move(x, y) 244 o 245 246 247 248 249 250 pygame.draw.rect(self.screen, self.white, self.highlight_digi if (puzzle[5] == 8): return self.swap(8, 5, puzzle)5282,"Up" elif spuzzle7) == 8): return self.swap(8, 7, puzzle)-728..."Left" 251 252 253 254 255 256 257 return False None 258 259 260 261 262 DD 263 264 def move_count (self text.mx=50 X=400): try: self.hfont.render(text, True, self.white) self:htextsurface = self.hfont.render(text, True, self.white) self.screen.blit(self.htextsurface, (x, y)) 265 266 A 267 268 o 269 except Exception as e: # print 'Font Error, saw it coming' raise e 270 Q 271 La GeneratePuzzle.py o digit_sqr.py button.py Node.py Le solution.py to puzzle.py to highlight_digit.py 3 Dimport random import pygame 5 from game.digit_sar import Digitsar 6 7 8 10 class GeneratePuzzle: def _init__(self, screen): self.screen = screen self.digits = [] self.generate_puzzle() self.digit_sar = Digitsqr(self.screen) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 def generate puzzle(self): puzzle = [02122232425262728] del self.digits[:] possible_moves = [[1, 3], [0, 2, 4), (1, 5], [0, 4, 6], [1, 3, 5, 7], [2, 4, 8], [3, 7], [4, 6, 8], [5, 7]] for i in range(0, 5): for j in range(0, 9): if (puzzle[j] == 8): pos = j new_pos = random.choice (possible_moves[pos]) temp = puzzle[pos] puzzle[pos] = puzzle[new_pos] puzzle [new_pos] = temp a 26 27 28 29 30 return puzzle 31 32 33 34 35 def draw_puzzle(self, digits): counter_X = 1 counter-y = 1 puzzle = [] for digit in digits: puzzle.append(self.digit_sqr.design( digit, 100 * counter_x, 100 * counter-y)) O 36 37 38 39 40 41 counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 42 43 44 return puzzle solution.py te puzzle.py highlight_digit.py X GeneratePuzzle.py to digit_sqr.py button.py Node.py 39 40 o counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 41 42 A 43 44 45 46 47 48 49 o 50 51 52 53 return puzzle def draw_puzzle_animate(self digits index1 index2 Key): counter_X = 1 counter-y 1 puzzle = [] for digit in digits: if(digit != digits[index1) and digit != digits[index2]): self.digit_sqr.design (digit, 100 * counter_x, 100 * counter_y) counter_x += 1 if counter_x % 4 == 0: counter_X = 1 counter-y += 1 if(digits[index2] ==8): self.digit_sqr.animation(digits[index1), Key_index1, index2) else: counter_x = 1 counter-y = 1 puzzle [] for digit in digits: puzzle.append(self.digit_sqr.design digit, 100 * counter_x, 100 * counter-y)) 54 55 A 56 57 58 59 60 61 62 o 63 64 65 66 counter_x += 1 if counter_x % 4 == 0: counter_x = 1 counter-y += 1 67 68 69 70 71 72 73 74 75 76 77 e return puzzle 78 79 Io solution.py to puzzle.py to highlight_digit.py GeneratePuzzle.py digit_sqr.py button.py Node.py 3 4 import pygame from game.button import Button Efrom game.highlight_digit import HighlightDigit 6 7 8 TIME = 5 9 10 11 12 13 14 15 class Digitsgro: def __init__(self, screen): self.screen = screen self.green = (100, 100, 100) self.dark_green = (, 255, 0) self.black = (0, 0, 0) self.white = (255, 255, 255) self.myfont = pygame.font.SysFont('Comic Sans MS', 30) self.digit = -1 self.sqr_side = 98 A self.highlight = HighlightDigit(self.screen) 16 17 18 19 20 22 23 24 25 def design(self digit, sqr_x, sqr-y): self.digit = digit self.rect = pygame.draw.rect(self.screen, self.green, (sqr_x, sqr-y, self.sqr_side, self.sqr_side)) if self.digit != 8: self.text_to_screen(self.digit, self.rect.x + 40, self.rect.y + 25) if self.digit == 8 select = pygame.draw.rect(self.screen, self.black, (sqr_x, sqr_y, self.sqr_side, self.sqr_side)) 26 27 28 A 29 30 31 32 33 34 35 def animation(self digit, key index1.index2): self.digit = digit list_sar = [[100_100],[200,100],[300,100],[100,200],[200_200],[300,200],[100,300],[200,300],[300,300]] inde

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions