Subversion Repositories programming

Rev

Rev 396 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 396 Rev 397
Line 1... Line 1...
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
 
2
 
3
# Fix for the lame version of python on the school's computers (v2.1)
3
from PyCompat import * # fixes for school computers
4
try:
-
 
5
	(True, False)
-
 
6
except NameError:
-
 
7
	(True, False) = (1, 0)
-
 
8
 
4
 
9
from Menu import Menu
5
from Menu import Menu
10
from PuzzlePiece import PuzzlePiece
6
from PuzzlePiece import PuzzlePiece
11
import PuzzleSearch
7
import PuzzleSearch
12
import sys
8
import sys
Line 53... Line 49...
53
			(goal_node, ), PuzzleSearch.astar_dfc)
49
			(goal_node, ), PuzzleSearch.astar_dfc)
54
 
50
 
55
################################################################################
51
################################################################################
56
 
52
 
57
def m_render_graph (result):
53
def m_render_graph (result):
58
	try:
-
 
59
		no_graphviz = False
54
	if have_yapgvb():
60
		import yapgvb
55
		import yapgvb
61
	except ImportError:
-
 
62
		no_graphviz = True
-
 
63
 
56
 
64
	from DrawGraph import DrawGraph
57
	from DrawGraph import DrawGraph
65
 
58
 
66
	if no_graphviz:
59
	if have_yapgvb():
67
		dg = DrawGraph (result.search_name, result.result_graph)
60
		dg = DrawGraph (result.search_name, result.result_graph)
68
		dg.render_stupid ('generated_by')
61
		dg.render_stupid ('generated_by')
69
		print
62
		print
70
 
63
 
71
	# Try to render the graph, nicely
64
	# Try to render the graph, nicely
72
	elif result.result_graph != None:
65
	if result.result_graph != None:
73
		fname = raw_input('Enter filename (press ENTER for \'res.svg\'): ')
66
		fname = raw_input('Enter filename (press ENTER for \'res.svg\'): ')
74
		print
67
		print
75
 
68
 
76
		if fname == '':
69
		if fname == '':
77
			fname = 'res.svg'
70
			fname = 'res.svg'
Line 87... Line 80...
87
	result = PuzzleSearch.get_nth_child (goal_node, DEPTH)
80
	result = PuzzleSearch.get_nth_child (goal_node, DEPTH)
88
 
81
 
89
	# "Fix" the node given back to us
82
	# "Fix" the node given back to us
90
	result.depth = 0
83
	result.depth = 0
91
	result.goal = goal_node
84
	result.goal = goal_node
-
 
85
	result.generated_by = 'root'
92
	return result
86
	return result
93
 
87
 
94
def getstr (prompt):
88
def getstr (prompt):
95
	return raw_input (prompt + ': ')
89
	return raw_input (prompt + ': ')
96
 
90
 
Line 128... Line 122...
128
	m.add_entry ('3', 'Quit', sys.exit)
122
	m.add_entry ('3', 'Quit', sys.exit)
129
	(entry, callback) = m.run_menu ()
123
	(entry, callback) = m.run_menu ()
130
 
124
 
131
	# Must be from #1
125
	# Must be from #1
132
	if entry == '1':
126
	if entry == '1':
133
		start_node = PuzzlePiece (callback(), 0, goal_node)
127
		start_node = PuzzlePiece (callback(), 0, goal_node, 'root')
134
	elif entry == '2':
128
	elif entry == '2':
135
		start_node = callback(goal_node)
129
		start_node = callback(goal_node)
136
 
130
 
137
	# Get set up for the next menu
131
	# Get set up for the next menu
138
	search_result = None
132
	search_result = None