Recursion

Recursion Overview

Maze Program

for this lab you will complete the maze algorithm add the code in described in the comments

File: main1.cpp


#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP

#include <iostream>


#include <stdlib.h>
#include <string.h>
#include "cmpslib19.h"


using namespace std;
int speed = 100;

#define  ROWS 50 
#define  COLUMNS 122


#define StartingX 1
#define StartingY 1


char MAZE[][COLUMNS] =	
{
	"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+",
	"|       |         |   |   |       |   |   |     |     |         |   |     |     | |     | |         |     | |   |   |   |",
	"+-+-+-+ + +-+ + +-+ + + + + +-+-+ + + + + +-+ + + +-+ + +-+-+-+ + + +-+ + + +-+ + + +-+ + + +-+-+ + + +-+ + + + + + + + +",
	"|       | |   |     |   | |   |   | |   | |   |   | | | |   | | | |     | | |   |   |   |   |     | | |   |   | | |   | |",
	"+ +-+-+-+ +-+-+-+-+-+-+-+ +-+ + + + +-+-+ + +-+-+-+ + + +-+ + + +-+-+-+-+ +-+ +-+ + + +-+-+ + +-+ + + + +-+-+-+ + +-+-+ +",
	"| |     |   |         | |   | | | | | |   |         | |     |     |   |   |   | | | |     | | |   | | |         |   |   |",
	"+ + + + +-+ + +-+ +-+ + + +-+ + +-+ + + +-+-+-+ +-+-+ +-+-+-+ +-+ + +-+ +-+ +-+ + + +-+-+ +-+ +-+-+ + + +-+-+-+-+-+ + +-+",
	"| | | |   | | |   |   | |   | |     | | |   |   | |   |       |   |       |   |   | |       |     |   | |           | | |",
	"+ + + +-+ + + + +-+ +-+ +-+ + +-+-+-+ + + + +-+-+ + +-+-+-+-+-+ +-+-+-+ + +-+ +-+-+ +-+-+-+ +-+-+ +-+-+ + +-+-+-+ +-+ + +",
	"| | | |   | | |   |       |   |         | | |     |           | |   |   |         | |     | |   |   |     |     | |   | |",
	"+ + + + +-+ + + + +-+-+-+ +-+-+ +-+ +-+-+ + + +-+ + +-+-+-+-+ + + + +-+ +-+-+ +-+ +-+ +-+ + + +-+-+ + +-+-+ +-+-+ + +-+ +",
	"| | | |     | | |   | |   |   | | | |   | |   | | |   |   | | |   |   |   |   | |     |   |   |     |   |     |   |     |",
	"+ + + +-+-+-+ + +-+ + + +-+-+ + + + +-+ + +-+-+ + +-+-+ + + + + +-+-+ +-+ +-+ + +-+-+-+ +-+-+ + +-+-+-+ + + +-+ +-+-+-+ +",
	"|   |     |   |   | | |       | | |     |   |   |     | |   | |     |   |   |   |   |   |   | | |     |   | |   |   |   |",
	"+-+-+-+ + + +-+-+ + + +-+-+-+-+ + +-+-+-+-+ + +-+-+-+ + +-+ + +-+-+-+-+ + + +-+-+ + + +-+ +-+ + + +-+ +-+-+ + +-+ + + +-+",
	"|   |   |   |   | | |       | | | |   |   |     |       |   |   |     | | |     | | |   |   | | |   |   |   |     | |   |",
	"+ + + +-+-+-+ + + + +-+-+-+ + + + + + +-+ +-+-+-+ +-+ +-+ +-+-+ + +-+ + +-+-+-+ + +-+-+ +-+ + + +-+-+-+ +-+-+-+-+-+ +-+-+",
	"| |   |   |   | | | |   | | |       | |   |   |   | | |   |   | |   | |   |   | |   |       |       | |   |       |     |",
	"+ +-+-+ + + +-+ + + + + + + +-+-+ +-+ + +-+ + + +-+ + + +-+ + + +-+ + +-+ + + + +-+ + +-+-+-+-+-+-+ + +-+ + +-+-+ +-+-+ +",
	"| |   | | |   | | | | |     |     | | |   | |   |     | |   | | |   | |   | |   | | | |         | | |   | | | |   |     |",
	"+ + + + +-+-+ + + + +-+ +-+-+ +-+-+ + +-+ + +-+-+ +-+-+ + +-+ + + + +-+ +-+-+ + + + + + +-+-+-+ + + +-+ + + + + +-+ +-+-+",
	"| | | |       |   |     |   | |     | | |   |   | |     |   |   | | |   |     | |     | | |         |   | | |       |   |",
	"+ +-+ +-+-+-+-+-+-+-+-+-+-+ + + + +-+ + +-+-+ + + + +-+-+-+-+-+ + + + +-+ +-+-+ +-+ +-+ + + +-+ +-+-+ +-+ + +-+-+-+-+ + +",
	"|   |   |               |   | | |     | |   | | | |   |     |     | |     | |   | |     |   | |   |     | | |   |   | | |",
	"+-+ +-+ + +-+-+-+ +-+ +-+ +-+ + +-+-+-+ + + + + + +-+ + +-+ + + +-+ +-+ +-+ + +-+ +-+ +-+-+-+ +-+ + + + + +-+ + + + + + +",
	"|   | | | |       | | |   |   | |     | | |   | | |   |   |   | |   | | |   | |   |   | |   |     | | | |     | | | | | |",
	"+ +-+ + + + +-+-+-+ + + +-+ +-+ + +-+ + +-+-+ + + + +-+ +-+-+-+ + +-+ + + + + + +-+-+-+ + +-+-+-+-+ +-+ + +-+ + +-+ +-+ +",
	"| |   |   |         |       | |   | |         |   |     |     | |     | | | | | |   |   | |           | | |   | |   |   |",
	"+ + +-+ +-+-+ +-+-+-+-+ +-+-+ +-+ + +-+ +-+-+-+-+-+-+-+-+ +-+ + +-+-+-+ +-+ + + + + + +-+ + +-+-+-+ + + + + +-+ + +-+ +-+",
	"| | |   | |     |     | |   |     |   | |           |   | |     | |   |   | |   | | |   |   |       | |   |   | | | | | |",
	"+ + + +-+ + + + + +-+ + + + +-+-+-+-+ + + +-+-+-+ + +-+ + + +-+-+ + + +-+ + +-+ + + + + + +-+ +-+-+-+ +-+-+-+ + + + + + +",
	"| | |     | | | |   |     |     |   |   | |       |     | |   |     |   | |     | |   |   |     |   | |       |   |   | |",
	"+ + +-+-+-+ + + +-+-+-+-+-+-+-+ + + +-+-+ + +-+-+-+-+-+-+ +-+ + +-+-+-+ + +-+-+-+ +-+-+-+-+-+-+ + +-+ + +-+-+-+-+-+ +-+ +",
	"| | |   |   | | |     |   |     | |       |   |     |   | |   |   |   | | |   |               | | |   | |     |   |   | |",
	"+ + + + + +-+ + + +-+ + +-+ +-+-+ +-+-+-+-+-+ +-+-+ + +-+ +-+-+-+ + + + + + +-+ +-+-+-+-+-+-+ + + + + + +-+-+ + + + +-+ +",
	"| |   |   | | | | | | |   | |   |         |   |     |   |     |   | | |   |     |     |       | |   | | |   |   | | |   |",
	"+ +-+-+-+-+ + + + + + +-+ + +-+ +-+-+-+-+ + +-+ +-+-+-+ +-+-+ + +-+ + +-+-+-+-+ + +-+ +-+-+-+-+ +-+-+ + + + + +-+ + + +-+",
	"| |       | | | |   | |   |     | |     | |       |   | |           | |   |   | | | |     |   |   |   |   | | | | | |   |",
	"+ + +-+-+ + + + +-+-+ + +-+-+-+ + + +-+ + +-+-+-+-+ + + +-+-+-+ +-+-+ +-+ + + +-+ + +-+-+ + + +-+ + +-+-+-+ + + + + +-+ +",
	"|   | |   | | | |       |   |   |     | | |         | |   |     |   |   | | |     |     | | | |   | | |     | |   |     |",
	"+ +-+ + +-+ + +-+ +-+ +-+-+ + +-+-+ + + + + + +-+-+-+ +-+ + +-+-+ + +-+ + + +-+-+-+ +-+ + + + + +-+ + + + +-+ +-+-+-+ +-+",
	"| | |   |   |     |         | |     | | |   | |     |       |   | |     | |         |   | | | | |   |   | |   |     |   |",
	"+ + +-+-+ +-+-+-+-+-+ +-+-+-+ + +-+-+-+ +-+-+-+ +-+ +-+-+ +-+-+ + +-+-+ + +-+ +-+-+-+-+-+ + + +-+ +-+-+ + + +-+ +-+ +-+ +",
	"| |   |   |     |     |       |   |   |   |       | |     |     | | |   | |   |     |     | |     |   | | | |     |   | |",
	"+ +-+ + +-+ +-+ + +-+-+-+-+-+-+-+ +-+ +-+ + + + +-+ + +-+-+ +-+-+ + + +-+ + + + +-+-+ +-+ + +-+-+-+ + +-+ + +-+ +-+-+ + +",
	"|       |     |     |     |   |   |   | |   | |   | | |     | |   |       | |   |   | |   | |       |     |       |   | |",
	"+-+-+ +-+-+-+ + +-+-+ +-+ +-+ + +-+ +-+ +-+-+-+-+ + + + +-+-+ + +-+-+ +-+-+ +-+-+ + + + +-+ +-+ +-+-+-+-+-+-+-+ + +-+-+ +",
	"|   | |       |     |   |   | |     |   |         | |   |   |   |     |     |   | | | |       | |   |     |     |   |   |",
	"+ + + + +-+-+-+-+-+ +-+-+ + + +-+-+ + + + +-+-+-+-+ + +-+ + +-+-+ + + +-+-+-+-+ + + + +-+-+-+ + + + +-+ + + +-+-+-+ + +-+",
	"| |   |           |       |   |       | |         |   |   |       | |             |   |       |   |     |         |     F",
	"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
};

//--------------------------------------------------------------------
void printMaze()
{
	// we want to redraw the maze so move the cursor back so we print in the same place
	PositionCursor(0,0);

	cout << ChangeToGreen() ;
	for(int rows=0;rows <= ROWS  ;rows++)
	{
		for (int columns=0;columns < COLUMNS;columns++)
		{
			PositionCursor(rows,columns);
			cout <<  MAZE[rows][columns];
		}
		cout <<"\n";
	}
}

//---------------------------------------------------------------------

bool Step(int x, int y, int level)
{ 
    // we need a terminating condititon so we dont keep calling the function forever
    // we stop when we find the end of the maze 
    // is the point x, y the finish? 'F'  (MAZE[x][y]=='F')     
    // if so cout "Finish Found at.... "
	// and return true


	// if the point x,y is not an empty space ' ' return false
    // we can only proceed if it is and empty space 


	// so now we know that point x,y  is a space
	// set  MAZE[x][y] to the char '@'
    // draw the @ in the maze at the appropriate position
	// set the cursor postition to x,y   , use function PositionCursor
	// print the char '@'


	// print some debugging info, mine prints current location
    // and how many levels deep we are */
	PositionCursor(ROWS +1,0);
	cout << ChangeToGreen()<< "currently at "<<x<<","<<y<< "    " << endl;
	cout << level << " levels deep\n";
	// pause for a while
	WaitHundredth(speed); 
    // call Step and pass in the coordinates of one space to the right ( x+1,y ) 
	// if it returns true you found the end and return true as well
	// call Step and pass in the coordinates of one space to the left ( x-1,y ) 
	// if it returns true you found the end and return true as well
	// call Step and pass in the coordinates of one space down ( x,y+1 ) 
	// if it returns true you found the end and return true as well
	// call Step and pass in the coordinates of one space up ( x,y-1 ) 
	// if it returns true you found the end and return true as well
  // if we are here we have not found the end...
  // we tried going up , down , left and right and didnt find the end
  // we must be at a dead end so we want erase that we came this way
  // and return false 
  // first set this position in the array to ' '  to delete the '@'
  // and draw a space back to erase our path on the map as we go back and try another direction
  // set the cursor position to x and y
  // and print a space at this position
  // return false

	return false;
}



//-----------------------------------------------------------------
int main()
{

	Prompt("What delay do you want between moves... 1-99:",speed,1,99);

	system("clear");
	printMaze();

	Step(StartingX ,StartingY,1);

	return 0;
}