Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python - Missionaries and cannibals I need to implment additional code to this project, but I have no idea on how to go about it.
Python - Missionaries and cannibals I need to implment additional code to this project, but I have no idea on how to go about it. I need to use depth first and breadth first search
from search import * class MandC(Problem): ''' This is the Missionaries and Cannibals Problem it's inherited from the Problem class (see search.py). ''' def __init__(self, initial, goal): #call ths parent class's constructor Problem.__init__(self,initial,goal) def actions(self,state): # This method should return a set of legal actions from # the current state def result(self, state, action): # This method returns the new state after applying action # to state # are there additional methods you'd like to define to help solve this problem? #Now you should test this: def main(): intial_state = #whatever your representation of the initial state is goal_state = #whatever your representation of the goal state is mc = MandC(initial_state,goal_state) soln =depth_first_graph_search(mc) print("Depth First Search") print("Solution Length: " + str(len(soln.path()))) print("Nodes Traversed:") print(soln.path()) print("Actions Taken:") print(soln.solution()) soln = bredth_first_search(mc) print("Breadth First Search") print("Solution Length: " + str(len(soln.path()))) print("Nodes Traversed:") print(soln.path()) print("Actions Taken:") print(soln.solution()) if __name__ == "__main__": main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started