Skip to content

Commit

Permalink
A* Search (8-puzzle Problem)
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanhakim committed Oct 6, 2020
1 parent e412e8f commit f5c42a5
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/AStarSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
import java.util.Comparator;
import java.util.PriorityQueue;

/**
* @author Adnan Hakim
* @code A* Search (8-puzzle Problem)
* @start [[1, 2, 0], [4, 5, 3], [7, 8, 6]]
* @goal [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
* @output
* [1, 2, 0]
* [4, 5, 3]
* [7, 8, 6]
*
* [1, 2, 3]
* [4, 5, 0]
* [7, 8, 6]
*
* [1, 2, 3]
* [4, 5, 6]
* [7, 8, 0]
*
* G Score: 2
* Reached goal state
*/
public class AStarSearch {
private static boolean found = false;

Expand All @@ -25,7 +46,7 @@ private static void aStar(int[][] current, int[][] goal, int gScore) {

// Move space above
if (row > 0)
priorityQueue.offer(copy(current, row, col,row - 1, col));
priorityQueue.offer(copy(current, row, col, row - 1, col));

// Move space below
if (row < current.length - 1)
Expand Down Expand Up @@ -70,8 +91,16 @@ private static int[][] copy(int[][] current, int currentRow, int currentCol, int
}

public static void main(String[] args) {
int[][] start = {{1, 2, 0}, {4, 5, 3}, {7, 8, 6}};
int[][] goal = {{1, 2, 3}, {4, 5, 6}, {7, 8, 0}};
int[][] start = {
{1, 2, 0},
{4, 5, 3},
{7, 8, 6}
};
int[][] goal = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
aStar(start, goal, 0);
}
}

0 comments on commit f5c42a5

Please sign in to comment.