-
Notifications
You must be signed in to change notification settings - Fork 1
/
slider.py
46 lines (34 loc) · 1.19 KB
/
slider.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
#!/usr/bin/env python3
'''
CPSC 415 -- Homework #2.667 template
Stephen Davies, University of Mary Washington, fall 2023
'''
from puzzle import Puzzle
import numpy as np
import sys
def solve(p):
'''Finds a sequence of moves ("L", "U", "R", or "D") that will solve the
Puzzle object passed. Returns that sequence in a list.
'''
# THIS IS WHERE YOUR AMAZING CODE GOES
# Here's a (bogus) example return value:
return ["D","U","L","L"]
if __name__ == '__main__':
if (len(sys.argv) not in [2,3] or
not sys.argv[1].isnumeric() or
len(sys.argv) == 3 and not sys.argv[2].startswith("seed=")):
sys.exit("Usage: puzzle.py dimensionOfPuzzle [seed=###].")
n = int(sys.argv[1])
if len(sys.argv) == 3:
seed = int(sys.argv[2][5:])
else:
seed = 123
# Create a random puzzle of the appropriate size and solve it.
puzzle = Puzzle.gen_random_puzzle(n, seed)
print(puzzle)
solution = solve(puzzle)
if puzzle.has_solution(solution):
input("Yay, this puzzle is solved! Press Enter to watch.")
puzzle.verify_visually(solution)
else:
print(f"Sorry, {''.join(solution)} does not solve this puzzle.")