Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MazeA;
- import Collections.*;
- import java.io.*;
- import BasicIO.*;
- public class TestPathFinder{
- private ASCIIDataFile data;
- private ASCIIDisplayer out;
- private int row;
- private int col;
- private int numRows;
- private int numCols;
- private char[][] maze;
- private LnkStack<Position> s;
- public TestPathFinder(){
- data = new ASCIIDataFile();
- readMaze();
- data.close();
- out = new ASCIIDisplayer(numRows + 1, numCols);
- displayMaze();
- }
- private boolean findPath(int x, int y){
- boolean result = false;
- Position aPos;
- s = new LnkStack<Position>();
- aPos = new Position(x,y);
- s.push(aPos);
- while (!(s.empty())){
- if ( maze[s.top().getXPosition()][s.top().getYPosition()] == 'E'){
- result = true;
- }
- else{
- if (s.top().getState() != 4){
- if( maze[s.top().getXPosition()][s.top().getYPosition()] == '#'
- || maze[s.top().getXPosition()][s.top().getYPosition()] == '*'
- || maze[s.top().getXPosition()][s.top().getYPosition()] == '.'){
- s.pop();
- aPos = s.top();
- }
- else{
- maze[s.top().getXPosition()][s.top().getYPosition()] = '*';
- s.top().setState(1);
- aPos = new Position(s.top().getXPosition(), s.top().getYPosition() + 1);
- s.push(aPos);
- break;
- }
- s.top().setState(s.top().getState() + 1);
- switch (s.top().getState()){
- case 1:
- aPos = new Position(s.top().getXPosition(), s.top().getYPosition() - 1);
- break;
- case 2:
- aPos = new Position(s.top().getXPosition() + 1, s.top().getYPosition());
- break;
- case 3:
- aPos = new Position( s.top().getXPosition() - 1, s.top().getYPosition());
- break;
- }
- s.push(aPos);
- }
- else{
- maze[s.top().getXPosition()][s.top().getYPosition()] = '.';
- s.pop();
- }
- }
- }
- return result;
- }
- private void readMaze(){
- numRows = data.readInt();
- numCols = data.readInt();
- maze = new char[numRows][numCols];
- for (int i = 0; i < numRows; i++){
- for (int j = 0; j < numCols; j++){
- maze[i][j] = data.readC();
- }
- }
- row = data.readInt();
- col = data.readInt();
- }
- private void displayMaze(){
- for (int i = 0; i < numRows; i++){
- for (int j = 0; j < numCols; j++){
- out.writeC(maze[i][j]);
- }
- }
- }
- public static void main ( String[] args ) { TestPathFinder t = new TestPathFinder(); };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement