def setUp(self): puzzle6_graph = { 1: frozenset([2]), 2: frozenset([1, 3, 4, 5]), 3: frozenset([2, 4, 6]), 4: frozenset([2, 3, 5, 6]), 5: frozenset([2, 4, 6]), 6: frozenset([3, 4, 5, 7]), 7: frozenset([6]), } puzzle6_node_colors = { 1: 'b', 2: 'r', 3: 'y', 4: 'b', 5: 'y', 6: 'r', 7: 'b', } puzzle6_moves_left = 3 print("### Puzzle 6 initial state:") print(puzzle6_graph) print(puzzle6_node_colors) self.puzzle6_step0 = kami2.PuzzleState(puzzle6_graph, puzzle6_node_colors, puzzle6_moves_left) self.puzzle6 = kami2.Kami2Puzzle(self.puzzle6_step0)
7: 'o', 8: 'b', 9: 'c', 10: 'w', 11: 'o', 12: 'b', 13: 'o', 14: 'b', 15: 'o', 16: 'b' } puzzle17_moves_left = 4 puzzle17_step0 = kami2.PuzzleState(puzzle17_graph, puzzle17_node_colors, puzzle17_moves_left) puzzle17 = kami2.Kami2Puzzle(puzzle17_step0) def main(): print("Solving using DFS:") search.DepthFirstSearch().solve(puzzle17) print("Solving using UCS:") search.UniformCostSearch().solve(puzzle17) print("Solving using A* (# colors heuristic):") informed_search.AStarSearch( informed_search.num_colors_heuristic).solve(puzzle17) print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(
25: 'dg', 26: 'y', 27: 'y', 28: 'r', 29: 'y', 30: 'g', 31: 'dg', 32: 'y', 33: 'dg', 34: 'r', 35: 'y' } puzzle54_moves_left = 7 puzzle54_step0 = kami2.PuzzleState(puzzle54_graph, puzzle54_node_colors, puzzle54_moves_left) puzzle54 = kami2.Kami2Puzzle(puzzle54_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle54) # print("Solving using UCS:") # search.UniformCostSearch().solve(puzzle54) # print("Solving using A* (# colors heuristic):") # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle54) # num states explored: 952, actions: [(4, 'y'), (16, 'r'), (24, 'r'), (30, 'r'), (30, 'y'), (30, 'dg'), (30, 'g')] print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle54)
18: 'dr', 19: 'dr', 20: 'dr', 21: 'dr', 22: 'dr', 23: 'dr', 24: 'dr', 25: 'p', 26: 'g', 27: 'p', 28: 'r', 29: 'dr' } puzzle98_moves_left = 6 puzzle98_step0 = kami2.PuzzleState(puzzle98_graph, puzzle98_node_colors, puzzle98_moves_left) puzzle98 = kami2.Kami2Puzzle(puzzle98_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle98) # print("Solving using A* (# colors heuristic):") # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle98) print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle98) if __name__ == "__main__": main()
43: 'r', 44: 'g', 45: 'g', 46: 'g', 47: 'g', 48: 'g', 49: 'y', 50: 'y', 51: 'y', 52: 'y', 53: 'y' } puzzle71_moves_left = 5 puzzle71_step0 = kami2.PuzzleState(puzzle71_graph, puzzle71_node_colors, puzzle71_moves_left) puzzle71 = kami2.Kami2Puzzle(puzzle71_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle71) # print("Solving using UCS:") # search.UniformCostSearch().solve(puzzle71) # 6242 states explored, solution: [(2, 'g'), (2, 'y'), (12, 'y'), (12, 'r'), (12, 'g')] # print("Solving using A* (# colors heuristic):") # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle71) # 281 states explored, solution: [(2, 'g'), (2, 'y'), (12, 'y'), (12, 'r'), (12, 'g')] print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle71)
9: 'b', 10: 'b', 11: 'o', 12: 'g', 13: 'o', 14: 'o', 15: 'o', 16: 'b', 17: 'b', 18: 'b', 19: 'g' } puzzle33_moves_left = 4 puzzle33_step0 = kami2.PuzzleState(puzzle33_graph, puzzle33_node_colors, puzzle33_moves_left) puzzle33 = kami2.Kami2Puzzle(puzzle33_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle33) # print("Solving using UCS:") # search.UniformCostSearch().solve(puzzle33) print("Solving using A* (# colors heuristic):") informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle33) print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle33) if __name__ == "__main__":
54: 'g', 55: 'g', 56: 'g', 57: 'g', 58: 'g', 59: 'g', 60: 'g', 61: 'g', 62: 'g', 63: 'g', 64: 'r' } puzzle72_moves_left = 6 puzzle72_step0 = kami2.PuzzleState(puzzle72_graph, puzzle72_node_colors, puzzle72_moves_left) puzzle72 = kami2.Kami2Puzzle(puzzle72_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle72) # print("Solving using UCS:") # search.UniformCostSearch().solve(puzzle72) # print("Solving using A* (# colors heuristic):") # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle72) # 26 states explored, solution: [(3, 'y'), (62, 'y'), (62, 'r'), (62, 't'), (62, 'y'), (62, 'g')] print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle72)
44: 'r', 45: 'b', 46: 'b', 47: 'b', 48: 'r', 49: 'w', 50: 'r', 51: 'w', 52: 'r', 53: 'w' } puzzle103_moves_left = 8 puzzle103_step0 = kami2.PuzzleState(puzzle103_graph, puzzle103_node_colors, puzzle103_moves_left) puzzle103 = kami2.Kami2Puzzle(puzzle103_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle103) # print("Solving using A* (# colors heuristic):") # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle103) print("Solving using A* (color distance heuristic):") informed_search.AStarSearch( informed_search.color_distance_heuristic).solve(puzzle103) if __name__ == "__main__":
17: 'o', 18: 'w', 19: 'c', 20: 'w', 21: 'c', 22: 'c', 23: 'o', 24: 'w', 25: 'b', 26: 'w' } puzzle18_moves_left = 5 puzzle18_step0 = kami2.PuzzleState(puzzle18_graph, puzzle18_node_colors, puzzle18_moves_left) puzzle18 = kami2.Kami2Puzzle(puzzle18_step0) def main(): # print("Solving using DFS:") # search.DepthFirstSearch().solve(puzzle18) # print("Solving using UCS:") # search.UniformCostSearch().solve(puzzle18) print("Solving using A* (# colors heuristic):") informed_search.AStarSearch( informed_search.num_colors_heuristic).solve(puzzle18) print("Solving using A* (color distance heuristic):") informed_search.AStarSearch(