-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdmaze.py
72 lines (60 loc) · 2.31 KB
/
sdmaze.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
70
71
72
"""
Main.py
Takes in an a list of rolling-die-puzzle files from the command line and, if it
exists, produces a solution.
Authors:
Joseph Fuchs <jjf2614@rit.edu>
Damien Cremilleux <dxc9849@rit.edu>
Dates editted:
Oct, 7th. 2014 (initial revision)
"""
import sys
import Search
from copy import deepcopy
from Die import Die
from Board import Board
from BoardNode import *
from Search import aStarSearch
from Board import NoStartError
def main():
if len(sys.argv) == 1:
print ("No Rolling-Die-Puzzle file provided. Now exiting")
return
for i in range(1,len(sys.argv)):
filename = sys.argv[i]
try:
board = Board(filename)
startLocation = board._dieLocation
startDie = Die()
for heuristicFunction in SequenceOfHeuristics:
print ("")
raw_input("Press ENTER to continue to next heuristic")
print ("")
print ("Heuristic Function: "+heuristicFunction.__name__)
print (board)
closedCounter = Counter()#global counter for node closing
frontierCounter = Counter()#global counter for node expansion
emptyPath = tuple()
startNode = BoardNode(board,startLocation,startDie,closedCounter,frontierCounter,emptyPath)
path = aStarSearch(heuristicFunction,startNode)
if path:#if path is found
for direction in path:
board.moveDie(direction)
print (board)
print ("")
print ("Length: " + str(len(path)))
else:#if path not found
print ("No Solution")
print ("Number Visited : "+str(closedCounter.getCount())+" (including start state)")
print ("Number Generated: "+str(frontierCounter.getCount()))
print ("End of heuristic '"+heuristicFunction.__name__+"'")
##reset board for next heuristic
board._die = Die()
board._dieLocation = startLocation
except IOError as e:
print (e)
except NoStartError as e:
print (e)
return
if __name__ == "__main__":
main()