Add Missionaries and Cannibals Problem Solution with BFS and DFS Implementations#909
Open
UditNayak wants to merge 1 commit intoaimacode:masterfrom
Open
Add Missionaries and Cannibals Problem Solution with BFS and DFS Implementations#909UditNayak wants to merge 1 commit intoaimacode:masterfrom
UditNayak wants to merge 1 commit intoaimacode:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
RiverSideclass 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:
Mcclass to solve the problem.Queuemodule to manage the frontier in the BFS search.solvemethod to run the BFS and check for the solution.DFS Integration:
depth_first_graph_searchmethod from the providedsearchmodule.solve2method to run the DFS and check for the solution.Action and Result Handling:
actionsmethod in theMcclass to generate possible actions from the current state.resultmethod to compute the resulting state after applying an action.Goal Testing:
goal_testmethod to check if the current state matches the goal state.Testing:
mainfunction to test the problem and verify the solution using both BFS and DFS methods.Notes: