Esempio n. 1
0
static long MazeDispatch( short action, long command, long *refCon, ScreenParams *params )
{
long	result;

	result = 0;
	
	switch( action )
		{
		case kDoScreenPreflight:
			result = MazePreflight( params->initValue );
			break;

		case kDoScreenReset:
			MazeReset( *refCon );
			break;

		case kDoScreenSetupCommand:
			*refCon = MazeSetup( params );
			break;

		case kDoScreenCommand:
			result = MazeCommand( command, *refCon, params );
			break;
		
		case kDoScreenKill:
			MazeKill( *refCon );
			break;
			
		default:
			ERROR_MESG( "Got bad selector in Maze Dispatch" );
			break;
			
		}
	return result;
}
Esempio n. 2
0
int main()
{
    printf("Maze Test\n");

    Maze maze;
    MazeReset(&maze);
    importMaze("mazes/Region1_2015.txt", &maze);

    RobotState state;
    MousePositionInit(&state.pos, NORTH, 0, 15);
    state.targetXmin = 7;
    state.targetYmin = 7;
    state.targetXmax = 8;
    state.targetYmax = 8;    

    // Execute Flood Fill on current maze
    FloodFill floodFill;
    floodFill.state = &state;
    floodFill.maze = &maze;

    SimpleFloodFillSolve(&floodFill);
    MazePrint(&maze, state.pos.x, state.pos.y);

    char ortho[255];
    char diag[255];
    PathGenOrtho(&maze, &state, ortho);
    PathGenDiag(ortho, diag);
    
    printf("%s\n", ortho);
    printf("%s\n", diag);
    // Maze Init
    /*Maze maze;
    MazeReset(&maze);
    importMaze("mazes/test.txt", &maze);

    Maze learningMaze;
    MazeReset(&learningMaze);

    // Robot State Init 
    RobotState state;
    MousePositionInit(&state.pos, NORTH, 15, 15);
    state.targetXmin = 13;
    state.targetYmin = 13;
    state.targetXmax = 13;
    state.targetYmax = 13;    

    // Execute Flood Fill on current maze
    FloodFill floodFill;
    floodFill.state = &state;
    floodFill.maze = &maze;

    SimpleFloodFillSolve(&floodFill);
    MazePrint(&maze, state.pos.x, state.pos.y);

    floodFill.maze = &learningMaze;

    MousePositionGoForward(&state.pos);

    char ortho[255]; 
    int lc = 0;

    while (1==1)
    {
        int i; for (i = 0; i < 255; i++) ortho[i] = 0;

        printf("---Adding Walls to Maze---\n");
        int valueForward = MazeHasAWallRelative(&maze, 
            state.pos.x, state.pos.y, state.pos.forwardDirection, FORWARD); 

        int valueLeft = MazeHasAWallRelative(&maze, 
            state.pos.x, state.pos.y, state.pos.forwardDirection, LEFT); 

        int valueRight = MazeHasAWallRelative(&maze, 
            state.pos.x, state.pos.y, state.pos.forwardDirection, RIGHT); 

        printf("Walls = F:%d L:%d R:%d\n", valueForward, valueLeft, valueRight);

        MazeSetWallRelative(&learningMaze, state.pos.x, state.pos.y, valueForward,
            state.pos.forwardDirection, FORWARD); 

        MazeSetWallRelative(&learningMaze, state.pos.x, state.pos.y, valueLeft,
            state.pos.forwardDirection, LEFT); 

        MazeSetWallRelative(&learningMaze, state.pos.x, state.pos.y, valueRight,
            state.pos.forwardDirection, RIGHT); 

        printf("---Flood Filling---\n");
 
        SimpleFloodFillSolve(&floodFill);
        MazePrint(&learningMaze, state.pos.x, state.pos.y);

        printf("---Generating Path---\n");
        PathGenOrtho(&learningMaze, &state, ortho);

        // Move!
        if (*ortho == 'f' || *ortho == 'F')
        {
            MousePositionGoForward(&state.pos);
        } 
        else if (*ortho == 'r' || *ortho == 'R')
        {
            MousePositionRotateRight(&state.pos); 
            MousePositionGoForward(&state.pos);
        }
        else if (*ortho == 'l' || *ortho == 'L')
        {
            MousePositionRotateLeft(&state.pos); 
            MousePositionGoForward(&state.pos);
        }
        else if (*ortho == 'b' || *ortho == 'B')
        {
            MousePositionGoBackward(&state.pos);
        }

        printf("New Position = %d, %d\n", state.pos.x, state.pos.y);
  
        printf("Ortho = %s\n", ortho);

        if (state.pos.x >= state.targetXmin && state.pos.x <= state.targetXmax &&
            state.pos.y >= state.targetYmin && state.pos.y <= state.targetYmax)
            break;

        if (lc++ > 15) break;       
    } 

    */

    printf("Done!\n");
    return 0;
}