Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you please write pseudo code (in java language)for this!!! package MazeGame; import java.util. Vector; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter: import java.nio.file.Files;

image text in transcribedcan you please write "pseudo code" (in java language)for this!!!

package MazeGame; import java.util. Vector; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter: import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class GameBoard { private GameCell[][] aBoard; private int n Square Size; private int n StartRow; private int nStartCol; private Vector path=new Vector(); private ArrayList allRoute = new ArrayList(); public GameBoard(String sFileName) throws Exception File file = new File(sFileName); J. ArrayList board = new ArrayList(); Jl Scanner file Scan = new Scanner(file); JL while(file Scan.hasNextLine()). I JL Il board.add(file Scan.nextLine()); } nSquareSize=board.size(); JL aBoard=new GameCell[n Square Size][n Square Size]; Il for(int nRow=0;nRow board = new ArrayList(); Scanner file Scan = new Scanner(file); while(file Scan.hasNextLine()) { board.add(file Scan.nextLine()); nSquare Size=board.size(); aBoard=new GameCelln Square Size][nSquare Size]; for(int nRow=0;nRow board = new ArrayList(); Scanner fileScan = new Scanner(file); while(file Scan.hasNextLine()) board.add(file Scan.nextLine()); return board.size(); ~ public void playGame() { findStart(); Vector path = findPath(nStartRow,nStartCol); JL JL // to store all possible paths ---> not complete yet if(allRoute.size()==0 ) allRoute.add(path); while(allRoute.size()!=2) path = findPath(nStartRow,nStartCol); for(int i=0;i "); m System.out.println(); System.out.println("Cost: "+pathCost(path)); private void findStart() for (int i = 0; i findPath(int nRow,int nCol) int random=(int)(Math.random()*3+1); if(aBoard[nRow][nCol].is End()==true) System.out.println("Yayyy!!!!"); path.add(aBoard[nRow][nCol]); return path; else switch(random) case 1: if(can GoUp(nRow, nCol)) { System.out.println("in cangoup"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow-1,nCol);} else if(canGoDown(nRow, nCol)) { System.out.println("in cangodown"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow+1,nCol);} else if(can GoLeft(nRow, nCol)) { System.out.println("in cangoleft"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow,nCol-1);} else if(can GoRight(nRow, nCol)) { System.out.println("in cangoright"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow,nCol+1);} else for (int i = 0; i findPath(int nRow,int nCol) JL { JL if(aBoard[nRow][nCol].isEnd()==true) JL System.out.println("Yayyy!!!!"); path.add(aBoard[nRow][nCol]); return path; JL JL else JL if(canGoUp(nRow, nCol)) JL if(can GoDown(nRow, nColl|can GoLeft(nRow, nColl|canGoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } IL System.out.println("in cangoup"); aBoard[nRow][n Col].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow-1,nCol); I else if(canGoDown(nRow, nCol)) JL if(can GoUp(nRow, nCol)||can GoLeft(nRow, n Col)||can GoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangodown"); aBoard[nRow][nCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow+1,nCol); I else if(can GoLeft(nRow, nCol)) JL if(can GoDown(nRow, nCol)||can GoUp(nRow, nCol)||canGoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangoleft"); aBoard[nRowlnCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow,nCol-1); I else if(canGoRight(nRow, nCol)) JL if(canGoDown(nRow, nCol|can GoLeft(nRow, nCol)||can GoUp(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangoright"); aBoard[nRow][nCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow,nCol+1); else System.out.println("Path has been changed"); Jl for(int i=path.size()-1;i>=0;i--) if(path.get(i).isCheckPoint() && path.get(i).isCheckUsed()==false) path.get(i).setCheckUsed(true); path.subList(i+1, path.size()).clear(); findPath(path.get(i).getRow(),path.get(i).getCol()); return path; JL } Jl return path; / } protected boolean canGoUp(int n Row,int nCol) if((n Row-1>=0 && nRow-1=0 && nCol-1=0 && nCol+1=0 && nRow+1 obPath) int cost=0; for(GameCell cell:path) switch(cell.getVal()) case '.': cost++; break; case 'D': cost+=75; break; case 'R': cost+=10; break; default: cost+=0; return cost; public void printBoard() for (int i = 0; i path=new Vector(); private ArrayList allRoute = new ArrayList(); public GameBoard(String sFileName) throws Exception File file = new File(sFileName); J. ArrayList board = new ArrayList(); Jl Scanner file Scan = new Scanner(file); JL while(file Scan.hasNextLine()). I JL Il board.add(file Scan.nextLine()); } nSquareSize=board.size(); JL aBoard=new GameCell[n Square Size][n Square Size]; Il for(int nRow=0;nRow board = new ArrayList(); Scanner file Scan = new Scanner(file); while(file Scan.hasNextLine()) { board.add(file Scan.nextLine()); nSquare Size=board.size(); aBoard=new GameCelln Square Size][nSquare Size]; for(int nRow=0;nRow board = new ArrayList(); Scanner fileScan = new Scanner(file); while(file Scan.hasNextLine()) board.add(file Scan.nextLine()); return board.size(); ~ public void playGame() { findStart(); Vector path = findPath(nStartRow,nStartCol); JL JL // to store all possible paths ---> not complete yet if(allRoute.size()==0 ) allRoute.add(path); while(allRoute.size()!=2) path = findPath(nStartRow,nStartCol); for(int i=0;i "); m System.out.println(); System.out.println("Cost: "+pathCost(path)); private void findStart() for (int i = 0; i findPath(int nRow,int nCol) int random=(int)(Math.random()*3+1); if(aBoard[nRow][nCol].is End()==true) System.out.println("Yayyy!!!!"); path.add(aBoard[nRow][nCol]); return path; else switch(random) case 1: if(can GoUp(nRow, nCol)) { System.out.println("in cangoup"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow-1,nCol);} else if(canGoDown(nRow, nCol)) { System.out.println("in cangodown"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow+1,nCol);} else if(can GoLeft(nRow, nCol)) { System.out.println("in cangoleft"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow,nCol-1);} else if(can GoRight(nRow, nCol)) { System.out.println("in cangoright"); aBoard[nRow][nCol].setVisited(true); path.add(aBoard[nRow][nCol]); findPath(nRow,nCol+1);} else for (int i = 0; i findPath(int nRow,int nCol) JL { JL if(aBoard[nRow][nCol].isEnd()==true) JL System.out.println("Yayyy!!!!"); path.add(aBoard[nRow][nCol]); return path; JL JL else JL if(canGoUp(nRow, nCol)) JL if(can GoDown(nRow, nColl|can GoLeft(nRow, nColl|canGoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } IL System.out.println("in cangoup"); aBoard[nRow][n Col].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow-1,nCol); I else if(canGoDown(nRow, nCol)) JL if(can GoUp(nRow, nCol)||can GoLeft(nRow, n Col)||can GoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangodown"); aBoard[nRow][nCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow+1,nCol); I else if(can GoLeft(nRow, nCol)) JL if(can GoDown(nRow, nCol)||can GoUp(nRow, nCol)||canGoRight(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangoleft"); aBoard[nRowlnCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow,nCol-1); I else if(canGoRight(nRow, nCol)) JL if(canGoDown(nRow, nCol|can GoLeft(nRow, nCol)||can GoUp(nRow, nCol)) { aBoard[nRow][nCol].setCheckPoint(true); } JL System.out.println("in cangoright"); aBoard[nRow][nCol].setVisited(true); if(!(path.contains(aBoard[nRow][nCol]))) {path.add(aBoard[nRow][nCol]);} findPath(nRow,nCol+1); else System.out.println("Path has been changed"); Jl for(int i=path.size()-1;i>=0;i--) if(path.get(i).isCheckPoint() && path.get(i).isCheckUsed()==false) path.get(i).setCheckUsed(true); path.subList(i+1, path.size()).clear(); findPath(path.get(i).getRow(),path.get(i).getCol()); return path; JL } Jl return path; / } protected boolean canGoUp(int n Row,int nCol) if((n Row-1>=0 && nRow-1=0 && nCol-1=0 && nCol+1=0 && nRow+1 obPath) int cost=0; for(GameCell cell:path) switch(cell.getVal()) case '.': cost++; break; case 'D': cost+=75; break; case 'R': cost+=10; break; default: cost+=0; return cost; public void printBoard() for (int i = 0; i <><><><><><><><><><>

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

=+ (d) Show that \, (He 0) =0 and A*(H) =1.

Answered: 1 week ago

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago