Theory and Practice of Artificial Intelligence | My Assignment Tutor

University of HertfordshireSchool of Computer ScienceDaniel PolaniHatfield, March 5, 2021Theory and Practice of Artificial Intelligence • 2020-2021,Semester BExercise Sheet 2Motto: Puzzles and SearchAssignment 2.1Create a variation of the optimal nim player to address variations of the game rules:• nim_2 or nim_4: a different number of sticks to be taken (up to 2, or up to 4)• nim_last_loses: a different winning condition (whoever takes the last stick, loses)!Assignment 2.2Modify the Hero/Sidekick Problem in terms of state variables, start node, goal node and transitionsto handle 2 heros with 2 sidekicks only.Assignment 2.3?Formulate the 6-Coins Problem in terms of state variables, start node, goal node and transitionsand write a class that represents it.import searchimport pathimport best_first_searchclass Six_Coins(search.Nodes):def cleanup(self, node):# in-place!!# remove dummy entries from begin and end of list# clean f

💡 Buy the answer for only $12 Get it now →

rom the frontwhile not node[0]:node.pop(0)while not node[-1]:node.pop()def start(self):return [1,2,1,2,1,2]def goal(self, node):return node == [1,1,1,2,2,2] or node == [2,2,2,1,1,1]def succ(self, node):for i in range(len(node)-1): # stop at second last# always move two adjacent coins to the rightif not node[i] or not node[i+1]:# if one of them empty, try other movecontinue# try all movesfor target in range(i+1, len(node)+1):#print “move from”, i, “to”, target new_node = node[:]doublet = new_node[i:i+2]new_node[i:i+2] = [0,0]new_node.extend([0,0])# copy# empty them# buffer at the end if new_node[target:target+2] == [0,0]:# target area emptynew_node[target:target+2] = doubletself.cleanup(new_node) # in-place!!if new_node == node:continue#print “Successor:”, node, new_nodeyield new_nodeclass Six_Coins_Path(path.Path):def __le__(self, path2):# compare not only length of path,# but length of representationsif self.length

💡 Buy the answer for only $12 Get it now →