Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the following question Write a program to solve the 8-puzzle problem (and its natural generalizations) using the A* search algorithm. The

I need help with the following question

Write a program to solve the 8-puzzle problem (and its natural generalizations) using the A* search algorithm.

The problem. The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. It is played on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the blocks from the start state to the goal state. You are permitted to slide blocks horizontally or vertically into the blank square.

Here is the start state:

2 8 3

1 6 4

7 0 5

Here is goal state:

1 2 3

8 0 4

7 6 5

Here is a* psuedocode

A* pseudocode

1 Create a node containing the goal state node_goal
2 Create a node containing the start state node_start
3 Put node_start on the open list
4 while the OPEN list is not empty
5 {
6 Get the node off the open list with the lowest f and call it node_current
7 if node_current is the same state as node_goal we have found the solution; break from the while loop
8 Generate each state node_successor that can come after node_current
9 for each node_successor of node_current
10 {
11 Set the cost of node_successor to be the cost of node_current plus the cost to get to node_successor from node_current
12 find node_successor on the OPEN list
13 if node_successor is on the OPEN list but the existing one is as good or better then discard this successor and continue
14 if node_successor is on the CLOSED list but the existing one is as good or better then discard this successor and continue
15 Remove occurences of node_successor from OPEN and CLOSED
16 Set the parent of node_successor to node_current
17 Set h to be the estimated distance to node_goal (Using the heuristic function)
18 Add node_successor to the OPEN list
19 }
20 Add node_current to the CLOSED list
21 }

here is what I have so far

import java.util.ArrayList;

public class PuzzleGame {

public static void main(String []args)

{

//Node node_goal = new Node(null,null,1,15,15);

ArrayList OpenList = new ArrayList();

ArrayList EndList = new ArrayList();

//beginer array

int[][]beginarr={{2,8,3},

{1,6,4},

{7,0,5}};

display(beginarr);

System.out.println();

//ending

int[][]endarr={{1,2,3},

{8,0,4},

{7,6,5}};

display(endarr);

//////////////

//int[] startNode={}

//add first node to open list

OpenList.add(beginarr);

EndList.add(endarr);

//loop while open list is not empty

while(!(OpenList.isEmpty()))

{

int [][] lowestnode={

{0}

,{0}

};

//find lowest f

for(int[][] i: OpenList)

{

for(int[][] j: OpenList){

// if(OpenList.get(i)

//}

}

}

}

}

//method to dispay array

public static void display (int[][]arr){

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length; j++) {

System.out.print(arr[i][j] + " ");

}

System.out.println();

}

}

I need this wirtten in java

Please help

Thanks

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_2

Step: 3

blur-text-image_3

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

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

Students also viewed these Databases questions

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago