This repository has been archived by the owner on Mar 13, 2019. It is now read-only.
/
main.py
69 lines (55 loc) · 1.91 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from Stack import Stack
import Hanoi as h
# intialising poles
a, b, c = Stack(), Stack(), Stack()
poles = [a, b, c]
# initialising moves stack
moves = Stack()
print '''
_____ _____ _ _ _ _____ _____
|_ _| | | | | __| __ |
| | | | | | | | __| -|
|_| |_____|_____|_____|__|__|
_____ _____
| | __|
| | | __|
|_____|__|
_____ _____ _____ _____ _____
| | | _ | | | | |
| | | | | | | |- -|
|__|__|__|__|_|___|_____|_____|
\033[1mVersion 1.1\n\033[0m
* Auto solve from any position with backtracking
* Supports 3 to 10 discs
\033[1mHow to play:\n\033[0m
Move all the discs from the first pole to the third one by one.
Rule: a larger disc cannot be placed on top of a smaller disc.\n
Coded by Avery
_______________________________________________________________________'''
# populating stack with discs
# only caters to 2 and 4 atm because of the layout
# but algo will work for any number of discs
disc = h.prompt_start("Number of discs (min: 3, max: 10): ")
for i in range(disc, 0, -1):
a.push(i)
while 1:
h.view_all(disc, a, b, c)
x, y = h.prompt("Type \"0 0\" to auto-solve. \nDisc to move (eg type \"1 2\" to move disc from pole 1 to pole 2):\n")
# user entered auto-solve
if x == 0 and y == 0:
h.view_all(disc, a, b, c)
h.backtrack(disc, poles, moves)
break
# user entered pole numbers to move
else:
# if move is valid
if h.move_disc(poles[x - 1], poles[y - 1]) == 1:
moves.push([x, y])
h.view_all(disc, a, b, c)
if h.is_solved(poles, disc):
print "\n ##### SOLVED ##### \n"
exit()
else:
print "\nInvalid move."
h.time.sleep(.5)
continue