Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use python and shoe screenshots of output the problem goes like this: you are a shepherd tasked with getting sheep and wolves across a

please use python and shoe screenshots of output the problem goes like this: you are a shepherd tasked with getting sheep and wolves across a river for some reason. If the wolves ever outnumber the sheep on either side of the river, the wolves will overpower and eat the sheep. You have a boat, which can only take one or two animals in it at a time, and must have at least one animal in it because you'll get lonely (and because the problem is trivial otherwise). How do you move all the animals from one side of the river to the other? In the original Sheep & Wolves (or Guards & Prisoners) problem, we specified there were 3 sheep and 3 wolves; here, though, your agent should be able to solve the problem for an arbitrary number of initial sheep and wolves. You may assume that the initial state of the problem will follow those rules (e.g. we won't give you more wolves than sheep to start). However, not every initial state will be solvable; there may be combinations of sheep and wolves that cannot be solved. You will return a list of moves that will solve the problem, or an empty list if the problem is unsolvable based on the initial set of Sheep and Wolves. You will also submit a brief report describing your approach. Create your agent, using thissolve()method, def solve(self, initial_sheep, initial_wolves): #Add your code here! Your solve method should receive #the initial number of sheep and wolves as integers, #and return a list of 2-tuples that represent the moves #required to get all sheep and wolves from the left #side of the river to the right. # #If it is impossible to move the animals over according #to the rules of the problem, return an empty list of #moves. You will create your agent in SemanticNetsAgent.py. You may test your agent by running main.py.( which is already created) yoursolve()method will have two parameters: the number of sheep and the number of wolves. For example, for the original Sheep & Wolves problem from the lectures, we would call your agent withyour_agent.solve(3, 3). You may assume that the initial state is valid (there will not be more Wolves than Sheep in the initial state). Returning your solution: Yoursolve()method should return a list of moves that will result in the successful solving of the problem. These areonlythe moves your agent ultimately selected to be performed, not the entire web of possible moves. Each item in the list should be a 2-tuple where each value is an integer representing the number of sheep (the first integer) or wolves (the second integer) to be moved; we assume the moves are alternating. So, if your first move is (1, 1), that means you're moving one sheep and one wolf to the right. If your second move is (0, 1), that means you're moving one wolf to the left. For example, one possible solution to the test case of 3 sheep and 3 wolves would be: [(1, 1), (1, 0), (0, 2), (0, 1), (2, 0), (1, 1), (2, 0), (0, 1), (0, 2), (0, 1), (0, 2)] he result of running the moves in order should be (a) that all animals are successfully moved from left to right, and (b) that all intermediate states along the way are valid (wolves never outnumber sheep in any state).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions