Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this question by using Java program 3. (40 points) 8-puzzle is a board game with tiles numbered 1 therough & located on

Please help with this question by using Java program
image text in transcribed
3. (40 points) 8-puzzle is a board game with tiles numbered 1 therough & located on a leaving one space blank. Ties adjacent to the blank space can be sld into it verticaly or horirontally. The goail of the game is to reach the following board configuration Lach state in the state space corresponds to a particular configuration on the board. There are four operators (actions) corresponding to blank space moving uplUL lefeiti, downjD) or right Suppose each state the board is represented by a list of 9 elements which indicate the tile located at each cell of the board [cl c2 e3 4 o c7 c c3 For example, 11 23804765 represents the state valoe that matches the board configuration for the goal jshown in the figure). Note that the number O is used to represent the position of the blank tile. Also note that the tles are listed in row- major order in this question, you write a simple Java program for creating and manipulating nodes for arn 8-puzzle (this can later be used for a tree or graph search). As discussed in class, in a search implementation, there is a difference between a node data structure in a program, and a state in the state-space. State is one field in a node, but there are other fields as well Your Java program declare a class Node. Class Node should have at a minimum the folowing fields and methods: 6) A field/attribute stote that is an array (ist) of integers representing the corresponding state in the described format (board configuration). (a) A field porent which takes an array of two elements as its value. The first element shal correspond to the parent node (an object of the same class; nul for the start/initial statel, and the second element to the action for the transition from (n) three fields, each an integer. hDsploced- No. ofl displaced tiles; (no. tiles not in desired location, do not count the blank tle hManhattan- The Manhattan/block distance; (sum of block distances of tiles from desired location, do not count the blank tilel gVal- gVal of parent+1 :Eval of start/initial node is O liv) A field children which is a list (eg. an arraylist), and each item in the lint has twe elements first element is an action name, and the second element is a nade object Then, isnonem in this list for the parent node. lv) A method eaua State that given any two node objects, will return true if the states in the two node objects are equal and false if the two states are not equal (careful: states ane equal their board representations are the same/equal not if they point to the same object. (vi) A method espandD. When called it computes the children of this node object and fills the value of the field children as describe in (N. For each child, it creates the node object and initializes the values described in (i).0 and (4, but not (in lvi) There should be getters and setter methods for the fields Your program should open and take its input from a text file (txt) named "inputsde t input le.txt" contains five lines, each corresponding to a configuration for one configuration of the 8 puzzle problem. Each lme has nine numbers separated by . " delmiter between them, for example, 1,.23784065 You demonstrate your program by reading each configuration (line) from the input flie, create a node object, call the method expand) to generate its children (and create a node object for each of themJ, sort the children node objects to createa sortedlist of nodes and write out the sortedList into output files. Your program should print output to two fles named OutileHeuristkc1, and "Outfileteuristic. The "Outfileteuristica" is printed from a sonted.st that has nodes sorted using hDisplaced gval, and "OutfileHeuritie" is sortedList that has nodes sorted using hManhattanegval Output: The output in each file should show () the problem (the starting confiuration read from a line of the input filel, followed by (i) the sorted list of nodes created from the children fter calling expand) on the start node, printing for each node (aj the action, (b) the state.i the gVal, hManhattan, and hDisplaced. Lach child node and its associated information is shown on one line. For example: printed from a PROBLEM:- "Sorted List Node 1: - "Node 2: Turnin Your turn in material should include (0 your program file, () the input file and the output files OutfileHeuristic1, OutfileHeuristic2, Demonstrate your program and its output by running it on a 3. (40 points) 8-puzzle is a board game with tiles numbered 1 therough & located on a leaving one space blank. Ties adjacent to the blank space can be sld into it verticaly or horirontally. The goail of the game is to reach the following board configuration Lach state in the state space corresponds to a particular configuration on the board. There are four operators (actions) corresponding to blank space moving uplUL lefeiti, downjD) or right Suppose each state the board is represented by a list of 9 elements which indicate the tile located at each cell of the board [cl c2 e3 4 o c7 c c3 For example, 11 23804765 represents the state valoe that matches the board configuration for the goal jshown in the figure). Note that the number O is used to represent the position of the blank tile. Also note that the tles are listed in row- major order in this question, you write a simple Java program for creating and manipulating nodes for arn 8-puzzle (this can later be used for a tree or graph search). As discussed in class, in a search implementation, there is a difference between a node data structure in a program, and a state in the state-space. State is one field in a node, but there are other fields as well Your Java program declare a class Node. Class Node should have at a minimum the folowing fields and methods: 6) A field/attribute stote that is an array (ist) of integers representing the corresponding state in the described format (board configuration). (a) A field porent which takes an array of two elements as its value. The first element shal correspond to the parent node (an object of the same class; nul for the start/initial statel, and the second element to the action for the transition from (n) three fields, each an integer. hDsploced- No. ofl displaced tiles; (no. tiles not in desired location, do not count the blank tle hManhattan- The Manhattan/block distance; (sum of block distances of tiles from desired location, do not count the blank tilel gVal- gVal of parent+1 :Eval of start/initial node is O liv) A field children which is a list (eg. an arraylist), and each item in the lint has twe elements first element is an action name, and the second element is a nade object Then, isnonem in this list for the parent node. lv) A method eaua State that given any two node objects, will return true if the states in the two node objects are equal and false if the two states are not equal (careful: states ane equal their board representations are the same/equal not if they point to the same object. (vi) A method espandD. When called it computes the children of this node object and fills the value of the field children as describe in (N. For each child, it creates the node object and initializes the values described in (i).0 and (4, but not (in lvi) There should be getters and setter methods for the fields Your program should open and take its input from a text file (txt) named "inputsde t input le.txt" contains five lines, each corresponding to a configuration for one configuration of the 8 puzzle problem. Each lme has nine numbers separated by . " delmiter between them, for example, 1,.23784065 You demonstrate your program by reading each configuration (line) from the input flie, create a node object, call the method expand) to generate its children (and create a node object for each of themJ, sort the children node objects to createa sortedlist of nodes and write out the sortedList into output files. Your program should print output to two fles named OutileHeuristkc1, and "Outfileteuristic. The "Outfileteuristica" is printed from a sonted.st that has nodes sorted using hDisplaced gval, and "OutfileHeuritie" is sortedList that has nodes sorted using hManhattanegval Output: The output in each file should show () the problem (the starting confiuration read from a line of the input filel, followed by (i) the sorted list of nodes created from the children fter calling expand) on the start node, printing for each node (aj the action, (b) the state.i the gVal, hManhattan, and hDisplaced. Lach child node and its associated information is shown on one line. For example: printed from a PROBLEM:- "Sorted List Node 1: - "Node 2: Turnin Your turn in material should include (0 your program file, () the input file and the output files OutfileHeuristic1, OutfileHeuristic2, Demonstrate your program and its output by running it on a

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

More Books

Students also viewed these Databases questions

Question

Repeat Example 4.17 for 90% evaporation of the water.

Answered: 1 week ago

Question

What are the key differences?

Answered: 1 week ago