Add Missionaries and Cannibals Problem Solution with BFS and DFS Implementations #909
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: #500
Issue Name: Request to get Community Solution for Exercise 'ex_6' in '3-Solving-Problems-By-Searching'
Description:
This PR addresses the solution for Exercise 'ex_6' in the '3-Solving-Problems-By-Searching' section. The code provides a solution to the classic Missionaries and Cannibals problem using both Breadth-First Search (BFS) and Depth-First Search (DFS) strategies. The implementation involves creating a structure to represent the state of the problem and defining methods to handle state transitions and validity checks.
Changes Made:
Problem State Representation:
RiverSide
class to represent the state of missionaries and cannibals on each side of the river.__add__
,__sub__
), validity checks (isValid
), and possible actions (action
).Custom Graph-Search BFS Implementation:
Mc
class to solve the problem.Queue
module to manage the frontier in the BFS search.solve
method to run the BFS and check for the solution.DFS Integration:
depth_first_graph_search
method from the providedsearch
module.solve2
method to run the DFS and check for the solution.Action and Result Handling:
actions
method in theMc
class to generate possible actions from the current state.result
method to compute the resulting state after applying an action.Goal Testing:
goal_test
method to check if the current state matches the goal state.Testing:
main
function to test the problem and verify the solution using both BFS and DFS methods.Notes: