Question: Create a Node class that supports a singly linked list that links backwards from tail to root. The node constructor is given below: class Node:

Create a Node class that supports a singly linked list that links backwards from tail to root.

The node constructor is given below:

class Node:

def __init__(self, state, parent, action, cost):

self.state = state

self.parent = parent

self.action = action

self.cost = cost

The linked list represents Pacman as it traverses through an (x, y) coordinate system, where the tail represents the current location and the root represents the starting point.

self.state is a tuple containing the current state: (x, y) location of Pacman

self.parent is a Node reference, the link that connects a node to its parent

self.action is a string, the action (North, South, East, West) that Pacman took from the parent to arrive at the current state

self.cost is a float, the cost taken by Pacman when moving from the parent to the current state

Create a Node class that supports a singly linked list that linksYou must also define a Python "main" function that accepts command-line arguments for the starting state of Pacman and gets user input for actions to move him. The function must maintain a linked list of Nodes and use it to print the total cost of the traversal and a list of actions from start to end. The start of it is given below:

import sys if __name__ == '__main__':

if len(sys.argv)!= 3:

print("usage: python node.py 2 3 to start at (2, 3)")

sys.exit()

You must define the following methods: def totalcost(self): The accumulated cost of traversing from start to current state Returns float def actions FromRoot(self): A list of actions ('North', 'South, 'East', 'West') taken from start to current state Returns list of strings def _str_(self): Human readable representation of a Node Returns string Note: str is the name of the built-in method for converting an object into a string, formatted like below: (1, -2) -West-> (0, -2), cost:1 Note: the cost of every action is 1 (except root whose cost is 0) You must define the following methods: def totalcost(self): The accumulated cost of traversing from start to current state Returns float def actions FromRoot(self): A list of actions ('North', 'South, 'East', 'West') taken from start to current state Returns list of strings def _str_(self): Human readable representation of a Node Returns string Note: str is the name of the built-in method for converting an object into a string, formatted like below: (1, -2) -West-> (0, -2), cost:1 Note: the cost of every action is 1 (except root whose cost is 0)

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!