Question
I have these two classes Board Class.......................................................................... import java.util.Arrays; import java.lang.System; public class Board { //public Board(int[][] blocks) construct a board from an N-by-N array
I have these two classes
Board Class..........................................................................
import java.util.Arrays;
import java.lang.System;
public class Board { //public Board(int[][] blocks) construct a board from an N-by-N array of blocks // (where blocks[i][j] = block in row i, column j) //public int dimension() board dimension N //public int hamming() number of blocks out of place //public int manhattan() sum of Manhattan distances between blocks and goal //public boolean isGoal() is this board the goal board? //public Board twin() a board obtained by exchanging two adjacent blocks in the same row //public boolean equals(Object y) does this board equal y? //public Iterable
public Board(int[][] blocks){ size = blocks.length; tiles =new int[size][size]; for(int i = 0; i public int hamming(){ int arrayPosition; int tile; int displaced =0; for(int i = 0; i for(int i = 0; i if(zeroRow > 0){ Board boardUP = new Board(swap(tiles,-1,0)); boards.push(boardUP); } if(zeroRow < size-1){ Board boardDown = new Board(swap(tiles,1,0)); boards.push(boardDown); } if(zeroCol > 0){ Board boardLeft = new Board(swap(tiles,0,-1)); boards.push(boardLeft); } if(zeroCol return boards; } public int[][] swap(int[][] board, int rowOffset, int colOffset){ int[][] tempBoard = deepCopy(board); tempBoard[zeroRow][zeroCol]= tiles[zeroRow+rowOffset][zeroCol+colOffset]; tempBoard[zeroRow+rowOffset][zeroCol+colOffset]=0; return tempBoard; } } Solver Class.................................................................... public class Solver { //public Solver(Board initial) // find a solution to the initial board (using the A* algorithm) //public boolean isSolvable() // is the initial board solvable? //public int moves() // min number of moves to solve initial board; -1 if no solution //public Iterable private Node goalNode; private MinPQ public int compareTo(Node that){ //StdOut.println("i:" + this.priority() + " j:" + that.priority() + " "+ ((this.priority() > that.priority()) ? 1 : -1)); if(this.priority() == that.priority()) return 0; return (this.priority() > that.priority()) ? 1 : -1; } public Node(Board b, Node prev, int m){ board = b; previous = prev; moves = m; } public int priority(){ return board.manhattan() + moves; } } public Solver(Board initial){ Board initialBoard; Queue Node currentNode = new Node(initial, null, 0); Node currentTwin = new Node(initial.twin(), null, 0); pq.insert(currentNode); pqTwin.insert(currentTwin); while(!currentNode.board.isGoal() && !currentNode.board.isGoal()){ currentNode = pq.delMin(); currentTwin = pqTwin.delMin(); for(Board b : currentNode.board.neighbors()) { if(!b.equals(currentNode.board)) pq.insert(new Node(b, currentNode, currentNode.moves +1)); } for(Board b : currentTwin.board.neighbors()) { if(!b.equals(currentNode.board)) pqTwin.insert(new Node(b, currentTwin, currentTwin.moves +1)); } } if(currentNode.board.isGoal()) goalNode = currentNode; else goalNode = currentTwin; } public Iterable All my errors have been solved but my code is not creating a GUI output. I'm doing the project in Eclipse as an sln document
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started