import java.io.*;
import java.util.*;

class Maze
{
	
	private char mat[][];			// 2d character array that stores the maze display
	private Coord currentMove;		// object that stores current maze position
	private ArrayStack visitStack;		// stack that stores location that have been visited
	
	class Coord
	// Coord is a class that stores a single maze location.  
	{
		private int rPos;
		private int cPos;
		public Coord (int r, int c) 		{ rPos = r; cPos = c; }
		public boolean isFree() 			{ return (rPos == 0 && cPos == 0); }
		public void setPos(int r, int c) 	{ rPos+= r; cPos+= c; }
	}
	
	  
	public Maze(int seed)
	// constructor which generates the random maze, random starting location
	// and initializes Maze class values.
	{
		Random random = new Random(seed);
		int startRow, startCol;
		mat = new char[12][12];
		for (int r = 0; r < 12; r++)
			for (int c = 0; c < 12; c++)
			{
				if (r == 0 || c == 0 || r == 11 || c == 11)
					mat[r][c] = 'X';
				else
				{
					int rndInt = random.nextInt(2);
					if (rndInt == 0)
						mat[r][c] = 'X';
					else
						mat[r][c] = 'O';
				}
			}
			
		mat[0][0] = 'O';
		startRow = random.nextInt(12);
		startCol = 11;
		mat[startRow][startCol] = '.';
		visitStack = new ArrayStack();
		currentMove = new Coord(startRow,startCol); 
		visitStack.push(currentMove);
	}


	void displayMaze() 
	// displays the current maze configuration
	{
		System.out.println("\nRANDOM MAZE DISPLAY\n");
		for (int r = 0; r < 12; r++)
		{
			for (int c = 0; c < 12; c++)
				System.out.print(mat[r][c] + "  ");
			System.out.println();
		}
		System.out.println();
		pause();
	}


	public void solveMaze() 
	// This methods solves the maze with private helper method <getMove>.
	// A loop is needed to repeat getting new moves until either a maze solution
	// is found or it is determined that there is no way out off the maze.
	{
		System.out.println("\n>>>>>   WORKING  ....  SOLVING MAZE   <<<<<\n");

	
		pause();
	}


	public void mazeSolution()
	// Short method to display the result of the maze solution
	{
		if (currentMove.isFree())
			System.out.println("\nTHE MAZE HAS A SOLUTION.\n");
		else
			System.out.println("\nTHE MAZE HAS NO SOLUTION.\n");
	}


	private boolean inBounds(int r, int c)
	// This method determines if a coordinate position is inbounds or not        
	{
	   return true; //this needs to be changed!!!!!
	}
   
   
	private boolean getMove() 
	// This method checks eight possible positions in a counter-clock wise manner
	// starting with the (-1,0) position.  If a position is found the method returns
	// true and the currentMove coordinates are altered to the new position
	{    
		boolean canMove = true;
		if (inBounds(-1,0) && mat[currentMove.rPos-1][currentMove.cPos] == 'O')
			currentMove.setPos(-1,0);
	/*	else if 
		
		
		
		
		
		
			canMove = false;*/
		return canMove;
	}
   
	private void pause() 
	{   
		 
		String dummy;
		System.out.print("\nPress <Enter> to continue  ===>>  ");						
		dummy = PMInput.readLine();								
	}


}

