Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with implemented the serach cost and average time for both hill climbing and minConflicts. Also i want to only show only the
I need help with implemented the serach cost and average time for both hill climbing and minConflicts. Also i want to only show only the final board.This is my main class below, i also provided my NQueen class in the images:
main.java:
import java.util.Scanner;
public class Main
public static void mainString args
NQueen queen new NQueen;
Scanner sc new ScannerSystemin;
int n ; Set a default value
int boardsize ; for project
int mode;
int debug;
int def ;
boolean solved false;
int end ;
while solved
prompt;
mode Integer.parseIntscnextLine;
promptDefault;
def Integer.parseIntscnextLine;
ifdef
promptN;
n Integer.parseIntscnextLine;
promptSize;
boardsize Integer.parseIntscnextLine;
debug ; Always show completed boards
switch mode
case :
doSHCqueen n boardsize, debug;
break;
case :
doCSPsc queen, n boardsize, debug, ; No customization
break;
default:
solved false;
break;
promptFinished;
end Integer.parseIntscnextLine;
if end
solved true;
else if end
solved false;
private static void promptDebug
System.out.printShow completed boards?: NO YES: ;
private static void promptDefault
System.out.printDo you want to customize this run?
yes
no: ;
private static void promptFinished
System.out.printRun Again?? NO YES: ;
private static void printTimeNQueen queen
System.out.printlnAverage time ms: queen.getTime;
This function will run the steepest hill climb algorithm
private static void doSHCNQueen queen, int n int boardsize, int debug
System.out.printlnRunning steepest hill climbing algorithm...";
queen.nTrialsn boardsize, debug;
System.out.printlnqueengetReport;
printTimequeen;
This function will run the min conflict algorithm.
If customization is chosen, the user will have the additional ability to set a maximum num
private static void doCSPScanner sc NQueen queen, int n int boardsize, int debug, int def
int maxsteps ;
ifdef
promptMaxSteps;
maxsteps Integer.parseIntscnextLine;
ifmaxsteps
maxsteps ; default is set to
queen.nTrialsn boardsize, maxsteps, debug;
System.out.printlnqueengetReport;
printTimequeen;
private static void promptMaxSteps
System.out.printMaximum number of steps?: Default: ;
private static void promptSize
System.out.printSize of the board?: ;
private static void promptN
System.out.printHow many puzzles to solve?: ;
private static void prompt
System.out.printlnEnter type of search:
Steepest Hill Climbing
Minimum Conflicts CSP;
Board class:
public class Board
private Tile board;
private int size;
public Boardint n
this.board new Tilenn;
this.size n;
initBoard;
public BoardBoard copy
this.size copy.getSize;
this.board copyBoardcopy;
private Tile copyBoardBoard copy
Tile toReturn new Tilesizesize;
forint i ; i size; i
forint j ; j size; j
toReturnij new Tilecopyboardij;
return toReturn;
private void initBoard
forint i ; i size; i
forint j ; j size; j
boardij new Tileij;
public Tile getTileint i int j
return boardij;
public Tile getTileNQueenCoords coords
return boardcoordsxcoordsy;
public int getSize
return this.size;
public String toString
StringBuilder toReturn new StringBuilder;
forint i ; i size; i
forint j ; j size; j
toReturn.appendQ;
else
toReturn.append;
toReturn.append
;
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