Esempio n. 1
0
 def test_shortest_path_1(self):
     """ Length 1 path."""
     start = rubik.I
     end = rubik.perm_apply(rubik.F, start)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 1)
     self.assertEqual(ans, [rubik.F])
Esempio n. 2
0
	def testshortestPath14(self):
		"""Length 14 path."""
		start = (6, 7, 8, 20, 18, 19, 3, 4, 5, 16, 17, 15, 0, 1, 2, 14, 12, 13, 10, 11, 9, 21, 22, 23)
		end = rubik.I
		ans = solver.shortest_path(start, end)
		self.assertEqual(len(ans), 14)
		self.assertGoodPath(start, end, ans)
Esempio n. 3
0
 def testshortestPath14(self):
     """Length 14 path."""
     start = (6, 7, 8, 20, 18, 19, 3, 4, 5, 16, 17, 15, 0, 1, 2, 14, 12, 13, 10, 11, 9, 21, 22, 23)
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 14)
     self.assertGoodPath(start, end, ans)
Esempio n. 4
0
 def testShortestPath0(self):
     """Length 0 path."""
     start = rubik.I
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 0)
     print("Test 1 Pass")
Esempio n. 5
0
 def testShortestPath1(self):
     """Length 1 path."""
     start = rubik.I
     end = rubik.perm_apply(rubik.F, start)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 1)
     self.assertEqual(ans, [rubik.F])
Esempio n. 6
0
 def test_shortest_path_bad(self):
     """ No solution."""
     start = (7, 8, 6, 20, 18, 19, 3, 4, 5, 16, 17, 15, 0, 1, 2, 14, 12, 13,
              10, 11, 9, 21, 22, 23)
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(ans, None)
Esempio n. 7
0
 def test_shortest_path_2(self):
     """ Length 2 path."""
     start = rubik.I
     middle = rubik.perm_apply(rubik.F, start)
     end = rubik.perm_apply(rubik.L, middle)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 2)
     self.assertEqual(ans, [rubik.F, rubik.L])
Esempio n. 8
0
 def testShortestPath2(self):
     """Length 2 path."""
     start = rubik.I
     middle = rubik.perm_apply(rubik.F, start)
     end = rubik.perm_apply(rubik.L, middle)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 2)
     self.assertEqual(ans, [rubik.F, rubik.L])
 def testShortestPath1(self):
     """Length 1 path."""
     start = rubik.I
     end = rubik.perm_apply(rubik.F, start)
     ans = solver.shortest_path(start, end)
     #        print 'ans ',ans, 'has length',len(ans)
     self.assertEqual(len(ans), 1)
     self.assertEqual(ans, [rubik.F])
Esempio n. 10
0
 def test_shortest_path_3(self):
     """ Length 3 path."""
     start = rubik.I
     middle1 = rubik.perm_apply(rubik.F, start)
     middle2 = rubik.perm_apply(rubik.F, middle1)
     end = rubik.perm_apply(rubik.Li, middle2)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 3)
     self.assert_good_path(start, end, ans)
Esempio n. 11
0
 def testShortestPath3(self):
     """Length 3 path."""
     start = rubik.I
     middle1 = rubik.perm_apply(rubik.F, start)
     middle2 = rubik.perm_apply(rubik.F, middle1)
     end = rubik.perm_apply(rubik.Li, middle2)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 3)
     self.assertGoodPath(start, end, ans)
Esempio n. 12
0
 def testShortestPath3(self):
     """Length 3 path."""
     start = rubik.I
     middle1 = rubik.perm_apply(rubik.F, start)
     middle2 = rubik.perm_apply(rubik.F, middle1)
     end = rubik.perm_apply(rubik.Li, middle2)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 3)
     self.assertGoodPath(start, end, ans)
     print("Test 4 Pass")
Esempio n. 13
0
 def testshortestPath14(self):
     """Length 14 path."""
     start = (6, 7, 8, 20, 18, 19, 3, 4, 5, 16, 17, 15, 0, 1, 2, 14, 12, 13,
              10, 11, 9, 21, 22, 23)
     end = rubik.I
     start_time = time.time()
     ans = solver.shortest_path(start, end)
     print("--- %s seconds for Solution ---" % (time.time() - start_time))
     self.assertEqual(len(ans), 14)
     self.assertGoodPath(start, end, ans)
Esempio n. 14
0
 def testShortestPath4(self):
     """Length 4 path."""
     start = rubik.I
     middle1 = rubik.perm_apply(rubik.F, start)
     middle2 = rubik.perm_apply(rubik.L, middle1)
     middle3 = rubik.perm_apply(rubik.F, middle2)
     end = rubik.perm_apply(rubik.L, middle3)
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 4)
     self.assertGoodPath(start, end, ans)
Esempio n. 15
0
    def testHuman(self):
        position = rubik.input_configuration()
        path = solver.shortest_path(position, rubik.I)
        instructions = [rubik.quarter_twists_names[move] for move in path]

        prompt = "solver.shortest_path gives the following move sequence:\n" +\
                 str(instructions) +\
                 "\nSolve the cube." +\
                 "\nEnter 1 if you solved the cube. Enter 0 otherwise: "
        ans = raw_input(prompt)
        self.assertEqual(ans, '1')
Esempio n. 16
0
    def testHuman(self):
        position = rubik.input_configuration()
        path = solver.shortest_path(position, rubik.I)
        instructions = [rubik.quarter_twists_names[move] for move in path]

        prompt = "solver.shortest_path gives the following move sequence:\n" +\
                 str(instructions) +\
                 "\nSolve the cube." +\
                 "\nEnter 1 if you solved the cube. Enter 0 otherwise: "
        ans = input(prompt)
        self.assertEqual(ans, '1')
def solve_puzzle(starting_faces):
    # takes the starting face configuration
    # returns a list of face configuration of the solution
    try:
        if check_rep(starting_faces)==False: return "Invalid color configuration, each\n color can only occurs 4 times."
        start=faces_to_list(starting_faces)
        ans=solver.shortest_path(start,I)
    except:
        return "Invalid color configuration, please\n check the colors on your cube."
    lf=[]
    ls=[]
    if ans == None:
        return "No solution"
    for p in ans:
        ls.extend([quarter_twists_names[p]])
        start=perm_apply(p,start)
        lf.extend([list_to_faces(start)])
    return [lf,ls]
Esempio n. 18
0
def solve_puzzle(starting_faces):
    # takes the starting face configuration
    # returns a list of face configuration of the solution
    try:
        if check_rep(starting_faces)==False: return "Invalid color configuration, each\n color can only occurs 4 times."
        start=faces_to_list(starting_faces)
        ans=solver.shortest_path(start,I)
    except:
        return "Invalid color configuration, please\n check the colors on your cube."
    lf=[]
    ls=[]
    if ans == None:
        return "No solution"
    for p in ans:
        ls.extend([quarter_twists_names[p]])
        start=perm_apply(p,start)
        lf.extend([list_to_faces(start)])
    return [lf,ls]
Esempio n. 19
0
def main():
    start = rubik.I
    end = rubik.perm_apply(rubik.F, start)
    ans = solver.shortest_path(start, end)
    print 'ans:{}'.format(ans)
Esempio n. 20
0
import rubik
from solver import shortest_path

shortest_path(rubik.input_configuration(), rubik.I)
Esempio n. 21
0
 def testShortestPath0(self):
     """Length 0 path."""
     start = rubik.I
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 0)
Esempio n. 22
0
 def testshortestPathBad(self):
     """No solution."""
     start = (7, 8, 6, 20, 18, 19, 3, 4, 5, 16, 17, 15, 0, 1, 2, 14, 12, 13, 10, 11, 9, 21, 22, 23)
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(ans, None)
Esempio n. 23
0
 def test_shortest_path_0(self):
     """ Length 0 path."""
     start = rubik.I
     end = rubik.I
     ans = solver.shortest_path(start, end)
     self.assertEqual(len(ans), 0)