Question: ******************THIS SHOULD BE USING PYTHON The program defines and prints a couple of states. A state is defined by the monster and munchkin count on

******************THIS SHOULD BE USING PYTHON

******************THIS SHOULD BE USING PYTHON The program defines and prints a couple

The program defines and prints a couple of states. A state is defined by the monster and munchkin count on the left river bank, and the side the boat is on.

Define and test two boolean methods:

goal(s) returns True if s is a goal state (all monsters and munchkins on right river bank).

and

legal(s) which returns True if s is legal (meets the conditions described in the puzzle).

Note that the state tuple stores how many Munchkins, Monsters are on the left bank. Subtracting these numbers from the total count gives the number on the right bank. In the program the variables munchkin_count and monster_count store the total counts.

if s is a state 3 tuple:

left_bank_munchkin_count = s[0]

right_bank_munchkin_count = munchkin_count - left_bank_munchkin_count

left_bank_monster_count = s[1]

right_bank_monster_count = monster_count - left_bank_monster_count

A legal state must meet the conditions:

left_bank_munchkin_count is between 0 and munchkin_count (this ensures the right bank is ok also)

left bank monsters cannot out number left bank munchkins and

right bank monsters cannot out number right bank munchkins

Note that it is not enough to just test left_bank_munchkin_count >= left_bank_monster_count

because there can be as any number of monsters on a river bank if there are no munchkins.

The state (2, 3, 1) us not legal, too many monsters on left bank.

(0, 3, 1) is legal.

(2, 1, 1) is not legal as there will be 1 munchkin and 2 monsters on the right river bank.

The last number is the boat side and it does not matter for checking legality, we will use it later when computing state changes.

******************THIS SHOULD BE USING PYTHON

Use Recursive Backytacking Search to solve River applying Puzzle: There are 3 monsters and 3 munchkins on the left river bank. A boat is available to move all 6 creatures to the right river bank. A maximum of two creatures are allowed in the boat for each applying The munchkins must never be outnumbered by the monsters. The boat will not move if there is no creature in it. Created on Sat Oct 12 22:26:17 2019 @author: rutkowsk + index number into state List mun = 0 mon=1 boat = 2 # boat side left = -1 right = 1 munchkin_count = 3 monster_count = 3 boat_capacity = 3 # state stores the state of the puzzle as a 3-tuple, # state[mun) = number of munchkins on left bank #state[mon) = number of monsters on left bank # state[boat] = boat side start_state = (munchkin_count, monster_count, left) prints a state def print_state(s): print(.. print('Munchkins\t'str(s[mun])+'\t\tMunchkins t'estr (munchkin_count-s(mun))) print("Monsters\t'str(s[mon])+"\t\tMonsters\t'str(monster_count-s[mon])) print(s[boat] \t\t\t\t Boat) print('-- print_state(start_state) state2 = (munchkin_count - 1, monster_count, right) print_state(state2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!