For the first part it looks like two pictures but they are in the same program e
ID: 3855403 • Letter: F
Question
For the first part it looks like two pictures but they are in the same program even though there is plenty of space in between them....it was a mistake when cropping the picture... can someone help me to write a C program that can define the integers for the first part of this program? it is basically a maze runner where a robot has to go thorugh the maze from a starting point to the end. After defining the integers in this part all the first part should go in the main program that is shown in the picture below where it says //add algorithm for the robot.
Please I will give a good rate, Can someone please help me??
#ifndef _mazer_h #define _mazer_h #include #include "maze.h" #include "dbg.h"//Global Variables int xpos; int ypos; int facing;//Function Prototypes/* Initialize the beginning position and facing of your virtual robot */int InitRunner ();/* Change the robot's facing counterclockwise */int TurnLeft ();/* Change the robot's facing clockwise */int TurnRight();/* Return true if there is a wall ('*') one space in the direction of facing Otherwise return false. You can use functions from the maze library, so figure out the XY coordinate you are interested in, then use XYToIndex to get the array index and then check the character at that index to see if it is a wall. While you're checking for walls, also look for the breadcrumb character that indicates a position has been visited from every direction, which means there is nothing Left to try. */int IsWall();/* Change the robot's position appropriately due to facing. Don't forget to leave a 'breadcrumb' in the old position (see the project requirements). */int MoveForward();/* Checks to see if the robot's position matches the destination coordinates and returns true if it does. Otherwise, return false. */int AtDestination(); #endif int main(int argc, char* argv[]) {if (argcExplanation / Answer
Observe the code below:
#ifndef _mazer_h
#define _mazer_h
#include <string.h>
#include "maze.h"
include "dbg.h"
//Current position in x direction
int xpos;
//Current position in y direction
int ypos;
// 4 values for facing variable. 1->Right 2->Down 3->Left 4->Up
int facing;
//Initialize initial positions
int InitRunner(int x,int y,int face)
{
xpos = x;
ypos = y;
facing = face;
}
// Change the facing of robot counterclockwise
int TurnLeft()
{
facing -=1;
if(facing == 0)
facing = 4;
}
// Change the facing of robot clockwise
int TurnRight()
{
facing += 1;
if(facing > 4)
facing = 1;
}
//Check whether its a wall or not
int IsWall()
{
if(maze[xpos][ypos] == '*')
return true;
return false;
}
// Move forward in the facing direction
int MoveForward()
{
//Leave a bread crumb at the current position.
maze[xpos][ypos] = 'B';
if(facing == 1)
ypos += 1;
else if(facing == 2)
xpos += 1;
else if(facing == 3)
ypos -= 1;
else if(facing == 4)
xpos -= 1;
}
int AtDestination()
{
if(xpos == x_dest && ypos == y_dest)
return true;
return false;
}
int main(int argc, char* argv[])
{
if(argc < 3)
{
usage();
return 1;
}
int width = (int)strtol(argv[1],(char**)NULL,10);
int height = (int)strtol(argv[2],(char**)NULL,10);
if(width < 9 || width > 79 || (width%2)!=1)
{
usage();
return 1;
}
if(height < 9 || width > 25 || (width%2)!=1 )
{
usage();
return 1;
}
setX(width);
setY(height);
InitMaze();
srand( time(0) );
Visit(1,1);
PrintMaze();
InitRunner(1,1,1);
PrintMaze();
return 0;
}
void usage()
{
printf("Usage: mazerunner x y ");
printf(" x must be an odd integer between 9 and 79 inclusive ");
printf(" y must be an odd integer between 9 and 25 inclusive ");
}