コード例 #1
0
main(){
	//declaration
	char array[M][N]={0};
	FILE *fptr;
	char c1;														//your char
	char file_name[20];												//name of file
	char dir;														//direction
	int i,j;														//iterator
	int x,y;							 							//map size
	int a,b=0;														//start location
	int c,d=0;														//end location
	// declaration end
	//getting data
	printf("how many rows in your map\n");							// ask for the hight of the map
	scanf("%d",&x);
	printf("how many columns in your map\n");						// ask for the width of the map 
	scanf("%d",&y);
	printf("Type in the name of the file containing the Field\n");	// ask for the file with the maze
	scanf("%s",file_name);
	//end getting data
	
	fptr=fopen(file_name,"r");										// save the maze to fptr
	
	for (i=0; i<x; i++){											// inputs the maze in to an array
		for (j=0; j<y; j++){
			c1=fgetc(fptr); 
			while ( !((c1 == '1')||(c1 =='0')) )c1=fgetc(fptr);
			array[i][j]=c1;
		}				
	}																//end maze set up
	fclose(fptr);
	printMaze(array,x,y);
	startEnd(array,&a,&b,&c,&d,x,y);
	dir=enter(a,b,x,y);
	traverse (array,a,b,c,d,dir);
	printMaze(array,x,y);
}
コード例 #2
0
ファイル: maze.c プロジェクト: nick-singh/Maze-c
int main()
{
	int m, n;

	in = fopen("input.txt","r");
	out = fopen("output.txt","w");

	if (in == NULL || out == NULL)
	{
		printf("Error opening files\n");
		return 0;
	}	

	fscanf(in,"%d %d", &m, &n);
	int **maze = initMaze(m, n), a, b, c, d;	
	int row = (m*ROW) - ( m - 1), col = (n*COL) - (n - 1), maxsec;
	
	buildMaze(in, maze,row, col);
	printMaze(out, maze, row, col);	
	evalMaze(out, maze, row, col);
	fscanf(in, "%d %d %d %d", &a, &b, &c, &d);

	a *= 2;
	b *= 2;
	c *= 2;
	d *= 2;	

	if(findPath(maze,a,b,c,d,row, col)){
		printMaze(out, maze, row, col);	
	}else{
		fprintf(out, "No Path Found!\n");
	}
	
	fclose(in);
	fclose(out);
	return 0;
}
コード例 #3
0
main() {
	void getData(FILE *);
	int findPath(int, int);
	void printMaze(FILE *);

	FILE * in = fopen("maze.in", "r");
	FILE * out = fopen("maze.out", "w");

	getData(in);
	if (findPath(sr, sc)) printMaze(out);
	else fprintf(out, "\nNo solution\n");

	fclose(in);
	fclose(out);
} //end main
コード例 #4
0
ファイル: maze.CPP プロジェクト: zxlooong/DsAlgVc
void main()
{cout<<"maze.cpp运行结果:\n";
 cout<<"迷宫问题求解:\n";
 char maze[ROWS][COLS];
 int xStart,yStart,x,y;
 srand(time(0));
 for(int loop=0;loop<ROWS;++loop )
  for(int loop2=0;loop2<COLS;++loop2 )
     maze[loop][loop2]='#';
 mazeGenerator(maze,&xStart,&yStart);
 x=xStart;//开始行
 y=yStart;//开始列
 mazeTraversal(maze,xStart,yStart,x,y,RIGHT);
 printMaze(maze);cin.get();
}
コード例 #5
0
ファイル: robotInterface.c プロジェクト: pacabot/zhonx3
int test_maze_flash ()
{
    int rv = MAZE_SOLVER_E_SUCCESS;
    labyrinthe maze, maze_to_discovert = {{{{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT}},{{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,WALL_PRESENCE,INFINITY_WEIGHT},{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,WALL_PRESENCE,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,NO_WALL,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,NO_WALL,NO_WALL,INFINITY_WEIGHT}},{{WALL_PRESENCE,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,NO_WALL,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT},{NO_WALL,WALL_PRESENCE,WALL_PRESENCE,NO_WALL,INFINITY_WEIGHT}}}};
    coordinate end_coordinate = {0,0};
    positionRobot start_position = {0,FALSE,{8,8}};
    rv=saveMaze(&maze_to_discovert, &start_position, &end_coordinate);
    if (rv != FLASH_DRIVER_E_SUCCESS)
    {
    }
    loadMaze(&maze, &start_position, &end_coordinate);
    printMaze(maze,end_coordinate);
    printLength(maze, end_coordinate.x, end_coordinate.y);
    while (expanderJoyFiltered() != JOY_LEFT);
    return rv;
}
コード例 #6
0
ファイル: maze.c プロジェクト: alemic/datastruct
void path(int *maze, int row, int col)
{
    stack *s = (stack *)malloc(sizeof(stack));
    int i, j, m, n, d, k;
    k=0;
    maze[8]=2;
    s->top = -1;
    push(s, 1, 1, 0);
    while(s->top > -1)
    {
        pop(s, &i, &j, &d);
        while(d<4)
        {
            m=i+move[d].vert;
            n=j+move[d].horiz;
            if(maze[m*col+n] == 0)
            {
                //printMaze(maze, row, col);
                maze[m*col+n]=2;
                if(m == row-2 && n == col-2)
                {
                    k++;
                    printf("===========After Calculate==========\n");
                    printMaze(maze, row, col);
                    d=9;
                    return;
                }
                else
                {
                    push(s, i, j, d+1);
                    i=m;
                    j=n;
                    d=0;
                }
            }
            else
            {
                d++;
            }
        }
        maze[i*col+j]=0;
    }
    printf("Result: %d ways found to out of this maze.\n", k);
}
コード例 #7
0
ファイル: mazeGenerator.cpp プロジェクト: daleman/maze
int main()

{
    std::vector< std::vector<int> > mh(M, std::vector<int>(N-1));
    std::vector< std::vector<int> > mv(M-1, std::vector<int>(N));
    std::vector< std::vector<int> > visited(M, std::vector<int>(N));

	initialize(visited, mh, mv);

	srand (time(NULL));
	//empiezo en una posicion random

	int posx = rand() % N;
	int posy = rand() % M;

	crear(posx, posy, visited, mh, mv);
    printMaze(mh,mv);
    return 0;
}
コード例 #8
0
ファイル: testAStar.c プロジェクト: dcollien/Alcubierre
int main(int argc, char *argv[]) {
   maze_t maze;

   maze.start.x = 1;
   maze.start.y = 1;

   maze.end.x = 15;
   maze.end.y = 15;

   path_t path;
   int pathLength;

   generateMaze(&maze);

   pathLength = aStar_shortestPath(
      (location_t)&(maze.start),
      isGoal,
      &path,
      expandCoord,
      coordHeuristic,
      coordHash,
      isEqualCoord,
      (void *)&maze
   );

   if (pathLength == NO_PATH) {
      printf("No Path Found\n");
   } else {
      printf("Path Length: %d\n", pathLength);
   }

   drawPath(&maze, path, pathLength);

   printMaze(&maze);

   assert(pathLength == 32);

   printf("All Tests Passed\n");

   return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: maze.c プロジェクト: eriiiiiic/hammerdown
//dibuja perra!!!!
void drawMaze(){
	
	//genera el laberinto y sus caminos de la chingada
	mazeFuck(0, 0);
	//se inicializa con algun caracter cagada
	int i, j;
	for (i = 0; i < mazeRow; i++){
		for (j = 0; j < mazeCol;  j++){
			mazeDraw[i][j] = 0;			
		}
	}

	//harcodea entrada y salida, que pendejo y webon
	mazeDraw[1][0] = 1; 
	mazeDraw[mazeRow - 2][mazeCol - 1] = 1;
	
	//recorre al arreglo lameculos para dibujar el putillo recorrido
	int x, y, z;
	for (x = 0; x < renglones; x++){
		for (y = 0; y < columnas; y++){
			for(z = 0; z < 4; z++){
				//si el putin valor es -1 no tumba pared
				if(maze[x][y][z] != -1){
					//guarda el mierda de valor del movimiento
					int tempr = row[ maze[x][y][z] ]; 
	    				int tempc = column[ maze[x][y][z] ];
					int posR = 2*x + 1;
					int posC = 2*y + 1;
					//pinta caminillo hijo de puta en posicion actual, +1 y +2 en respecputamente
					mazeDraw[posR][posC] = 1;
					mazeDraw[ posR + tempr ][ posC + tempc ] = 1;
			  		mazeDraw[ posR + 2*tempr ][ posC + 2*tempc ] = 1;
				}
			}
		}
	}
	
	//imprime el laberinto pinche cabron
	printMaze();
}
コード例 #10
0
ファイル: maze.c プロジェクト: alemic/datastruct
int main()
{
    //定义上下左右的游标,由于规定入口为左上角(1,1),出口(5,5),故设定移动优先级为左-下-右-上
    move[0].vert=0;
    move[1].vert=1;
    move[2].vert=0;
    move[3].vert=-1;
    move[0].horiz=1;
    move[1].horiz=0;
    move[2].horiz=-1;
    move[3].horiz=0;
    int row, col;
    row=col=7;
    int maze[MAX][MAX];
    int *p=&maze[0][0];
    //drawMaze(p, row, col); //手动输入方式绘制
    drawMaze2(p, row, col); //固定迷宫方式绘制
    printMaze(p, row, col);
    path(p, row, col);
    //printMaze(p, row, col);
    return 0;
}
コード例 #11
0
ファイル: maze.c プロジェクト: DerrickChanCS/COEN12
int main(void)
{
    int x, y;
    WINDOW *win;


    win = initscr();
    curs_set(0);
    getmaxyx(win, y, x);
    width = x / 2 - 1;
    height = y / 2 - 1;
    createMaze();

    do {
	clear();
	refresh();
	initMaze();

	dp = createDeque();
	buildMaze(0, 0);
	destroyDeque(dp);

	printMaze();

	dp = createDeque();
	solveMaze();
	destroyDeque(dp);

	move(height * 2 + 1, 0);
	printw("Press 'q' to quit or any other key to run again.");
	refresh();
    } while (getchar() != 'q');

    clear();
    refresh();
    endwin();
    return EXIT_SUCCESS;
}
コード例 #12
0
int main(int argc, char *argv[]) {
	Maze maze;

	readMazeFromFile(&maze, "maze3D.txt");

	unsigned int solution_count = 13;
	Direction solution[] = {EAST, NORTH, EAST, SOUTH, EAST, NORTH, UP, WEST, WEST, NORTH, NORTH, DOWN, SOUTH};

	Position position, goal;
	getPosition(maze, &position);
	getGoal(maze, &goal);

	printf("Current position: "); printPositionWithNewline(position);
	printf("Goal: "); printPositionWithNewline(goal); printf("\n");

	printMaze(maze);

	printPossibleMoves(maze);
	printf("\n");

	for (int i=0; i < solution_count; i++) {
		if (makeMove(&maze, solution[i]) == 1) {
			if (isSolved(maze)) {
				printf("Maze solved!\n");
				printPathWithNewline(maze.path);
				break;
			}
			else {
				printf("Movement successful, maze not solved.\n");
			}
		}
		else {
			printf("Error moving from: "); printPosition(maze.pos); printf (" to %s\n", convertDirectionToString(solution[i]));
		}
	}
	return EXIT_SUCCESS;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: JulianDomingo/EE312
int main(void) {
	const int magic_number = time(NULL);

	/* test min */
	int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//	printf("the smallest of the first 10 natural numbers is: %d\n", minIt(a, 10));
	printf("the smallest of the first 10 natural numbers is: %d\n", minRec1(a, 10));
	printf("the smallest of the first 10 natural numbers is: %d\n", minRec2(a, 10));
	a[3] = -1;
//	printf("now the smallest is %d\n", minIt(a, 10));
	printf("now the smallest is %d\n", minRec1(a, 10));
	printf("now the smallest is %d\n", minRec2(a, 10));
	
	/* test sqrt */
//	printf("the sqrt of 25 is %g\n", sqrtIt(25.0, 0, 25.0));
//	printf("the sqrt of 26 is %g\n", sqrtIt(26.0, 0, 26.0));
//	printf("the sqrt of 2 is %g\n", sqrtIt(2.0, 0, 2.0));
	// printf("the sqrt of 25 is %g\n", sqrtRec(25.0, 0, 25.0));
	// printf("the sqrt of 26 is %g\n", sqrtRec(26.0, 0, 26.0));
	// printf("the sqrt of 2 is %g\n", sqrtRec(2.0, 0, 2.0));
	//printf("sqrt of 2e60 is %.17g\n", sqrtRec(2.0 * pow10(60), 1.4142135623731, 1.5 * pow10(30)));

	/* test strCompare */
	char* s1; char* s2;
	s1 = "apple"; s2 = "apricot";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}
			
	s1 = "Apple"; s2 = "apple";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "baby boy"; s2 = "banana";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "a rather silly string"; s2 = "a rather silly string";
	if (strCompare(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "12345"; s2 = "12345";
	if (strCompare(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "Numbers: 12345"; s2 = "12345";
	if (strCompare(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	s1 = "Texas"; s2 = "California";
	if (strCompare(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	/* test strCompare2 */
	s1 = "apple"; s2 = "Apricot";
	if (strCompare2(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "Batman!"; s2 = "bat man";
	if (strCompare2(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "OMG, WTF?"; s2 = "oh my goodness, what the heck?";
	if (strCompare2(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	printf("********************************************\n");


	s1 = "!79857#*#*b*&atm#@@an 989^";
	s2 = "     b   a   t   m   a   ! n";

	if (strCompare2(s1, s2) == 0) {
		printf("Good\n");
	}
	else {
		printf("Bad\n");
	}

	s1 = "CAPITAL LETTERS DON'T MATTER FOR STRCOMPARE2";
	s2 = "capital letters don't matter for strcompare2";

	if (strCompare2(s1, s2) == 0) {
		printf("Good\n");
	}
	else {
		printf("Bad\n");
	}

	s1 = "asdf ASDF jkl JKL a   *&@#^&^#";
	s2 = "asdf ASDF jkl JKL b   *&@#^&^#";
	if (strCompare2(s1, s2) == -1) {
		printf("Good\n");
	}
	else {
		printf("Bad\n");
	}

	printf("Strong test case:\n");
	s1 = "strongg";
	s2 = "strong";
	printf("%d\n", strCompare(s1, s2));
	printf("%d\n", strCompare2(s1, s2));

	/* test maze */		
	srand(magic_number);
	makeMaze();
	recodeMaze();
	printf("recursive solution to the maze\n");
	fflush(stdout);
	solveMazeRec(0, start_col);
	printMaze();
	printf("\n\n\n");
	
//	printf("iterative solution to the maze\n");
//	srand(magic_number);
//	makeMaze();
//	recodeMaze();
//	solveMazeIt(0, start_col);
//	printMaze();
/*
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");

	// for (double j = 3; j < 2e3; j+= 2) {
	// 	printf("the sqrt of %g is %g expected: %g\n", j, sqrtRec(j, 0, 9000), sqrt(j));
	// 	double_equals(sqrtRec(j, 0, 9000), sqrt(j));
	// }


	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");

	//printf("%.17g\n", sqrtRec(27.0, 0.0, 50.0));
*/
	/* test Martian */
/*	Martian change1 = change(15);
	printf("change 1 should be 0d, 3n, 0p and is: %dd %dn %dp\n", change1.dodeks, change1.nicks, change1.pennies);

	int c = 0;
int d = 0;
int n = 0;
int p = 0;
int i = 0;
int iterate = 20;
FILE *fp;
fp = fopen("output.txt", "r");

while (!feof(fp) && i < iterate) {
  change1 = change(i);
  fscanf(fp, "%d", &c);
  fscanf(fp, "%d", &d);
  fscanf(fp, "%d", &n);
  fscanf(fp, "%d", &p);
  printf("change: %d %d %d %d\n", i ,change1.dodeks, change1.nicks, change1.pennies);
  printf("python: %d %d %d %d\n", c, d, n, p);
  assert(change1.pennies == p);
  assert(change1.nicks == n);
  assert(change1.dodeks == d);
  i++;
}
fclose(fp);

	Martian change2 = change(0);
	printf("change 2 should be 0d, 0n, 0p and is: %dd %dn %dp\n", change2.dodeks, change2.nicks, change2.pennies);

	Martian change3 = change(17);
	printf("change 3 should be 1d, 1n, 0p and is: %dd %dn %dp\n", change3.dodeks, change3.nicks, change3.pennies);

	Martian change4 = change(25);
	printf("change 4 should be 2d, 0n, 1p and is: %dd %dn %dp\n", change4.dodeks, change4.nicks, change4.pennies);
*/
    //************************************************* PERSONAL TESTS *****************************************************//
    Martian change5 = change(16);
    printf("change 5 should be 0d, 3n, 1p and is: %dd %dn %dp\n", change5.dodeks, change5.nicks, change5.pennies);

	/* A very simple and obvious test of the general form of Martian
	 * be sure and test your solution more thoroughly!!!! */
	Martian change6 = change(25, 5, 12);
	printf("change 6 should be 2d, 0n, 1p and is: %dd %dn %dp\n", change6.dodeks, change6.nicks, change6.pennies);

    Martian change7 = change(16, 5, 12);
    printf("change 7 should be 0d, 3n, 1p and is: %dd %dn %dp\n", change7.dodeks, change7.nicks, change7.pennies);

    Martian change8 = change(20, 5, 10);
    printf("change 8 should be 2d, 0n, 0p and is: %dd %dn %dp\n", change8.dodeks, change8.nicks, change8.pennies);

    Martian change9 = change(21, 5, 10);
    printf("change 9 should be 2d, 0n, 1p and is: %dd %dn %dp\n", change9.dodeks, change9.nicks, change9.pennies);

/*
    printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	n = 5;
	int z[] = {0, 0, 0, 0, 0};
	printf("Min of z: %d\n", minRec1(z, n));
	printf("Min of z: %d\n", minRec2(z, n));
	int oi[] = {-5, 0, 0, 0, -4};
	printf("Min of oi: %d\n", minRec1(oi, n));
	printf("Min of oi: %d\n", minRec2(oi, n));
	int koi[] = {-5, -234, -2525, 2, 4};
	printf("Min of koi: %d\n", minRec1(koi, n));
	printf("Min of koi: %d\n", minRec2(koi, n));
	char* str1 = "Genji";
	char* str2 = "GENJI";
	printf("%d\n", strCompare(str1, str2));
	printf("%d\n", strCompare2(str1, str2));
	str1 = " hehe xD";
	str2 = "hehe xD";
	printf("%d\n", strCompare(str1, str2));
	printf("%d\n", strCompare2(str1, str2));
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");

	Martian change45 = change(28);
    printf("%dd %dn %dp\n", change45.dodeks, change45.nicks, change45.pennies);

    */
}
コード例 #14
0
ファイル: MouseManager.c プロジェクト: JMarple/Micromouse2014
void solveMaze()
{		
	//Reset maze to 0
	initializeMaze(&maze);
		
	//We Know at the starting point, there's something behind us
	setN(&maze[0][0], 1);
	mouse.direction.x = 0;
	mouse.direction.y = -1;
	mouse.x = 0;
	mouse.y = 0;

	//Disable the mouse for now
	enableDrive(0);
	turnOnTimers(0, 0);
	
	int areWeSearching = UserInterfaceIntro();
	
	//Does the user want to skip the search phase and load a maze from EEPROM
	if(areWeSearching)
	{
		/* SEARCH MAZE */
		for(int i = 0; i < 10; i++)
		{
			turnOnLeds(7);
			_delay_ms(10);
			turnOnLeds(0);
			_delay_ms(90);
		}
		
		//Init Mouse
		enableDrive(1);
		turnOnTimers(1, 1);
		setDirection(0, 0);
		
		//Update Sensors
		updateSensors();
		updateSensors();	
		updateWalls();
		
		//Go Forward first block
		mouse.IR_LONG_CHECK_LEFT = 2;
		mouse.IR_LONG_CHECK_RIGHT = 2;
		straight(480, 0, mouse.maxVelocity, mouse.maxVelocity, mouse.acceleration, mouse.deceleration);
		mouse.x += mouse.direction.x;
		mouse.y -= mouse.direction.y;	
		
		/* SEARCH */
		InitialSearchRun();
		
			//Search is Complete!
			updateWalls();
			
			/* TURN AROUND */
			mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
			StopFromSpeedHalf();
			mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
			moveBackwards();			
				
			//Save Maze to EEPROM
			saveCurrentMaze();
			writeMemByte(MOUSE_DIRECTION, firstTurn);
		
			mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
			moveForwardHalf();
			
			//Current Mouse Direction
			int dirx = mouse.direction.x;
			int diry = mouse.direction.y;
			
			//Reverse and go back
			mouse.direction.x  = -dirx;
			mouse.direction.y = -diry;
			
			//Set Position to next block
			mouse.x += mouse.direction.x;
			mouse.y -= mouse.direction.y;
		
		/* RETURN SEARCH*/
		ReturnSearchRun();
			
			//Turn Around
			mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
			StopFromSpeedHalf();
			mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
			moveBackwards();
		
			//Save Maze to EEPROM
			saveCurrentMaze();
			writeMemByte(MOUSE_DIRECTION, firstTurn);
		
		/* PICK UP AND PLACE MOUSE */
		enableDrive(0);
		waitForButtonPressed();
	}
	
	/* FAST RUN */
	FastRun();
	
		//Completed Search run, go back and search some more
		turnAroundInPlace();	
		
		floodFill(maze, firstTurn, mouse.x, mouse.y);
	
	/* RETURN */	
	ReturnSearchRun();
		
		//Turn Around
		mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
		StopFromSpeedHalf();
		mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0;	
		moveBackwards();	
		
		//Save Maze to EEPROM
		saveCurrentMaze();
		writeMemByte(MOUSE_DIRECTION, firstTurn);
		
	stopMouse();
	
	while(!isButtonPushed(1));
		printMaze(maze);
}
コード例 #15
0
ファイル: cscd240_s12_hw2Tester.c プロジェクト: Xe/code
int main(int argc, char ** argv) {
	//Clear the screen
	system("clear");
	srand(time(0));

	printf("Escape from the Everfree Forest!\n\n");
	printf("Apple Bloom is stuck in the Everfree Forest trying to get the flowers to Zecora's house.\nHelp her find her way through the scary forest! Be careful though, the Great and Powerful\nTrixie is hidden in the forest, and encountering her will surely cause your doom.\nYour flashlight lets you see one square ahead of you.\n\nMoves are given in compass directions.\nThis game is best enjoyed with headphones.\nPress Enter to start\n");
	
	getchar();

	FILE * fout = fopen(OUTPUT, APPEND);	

	int alive = false;
	int other = true;
	
	if(argc > 1) {
		populateMaze(argv[1], maze);
	} else {
		populateMaze("", maze);
	}
	fow[x][y] = true;

	fprintf(fout, "Initial position: %i,%i\n", x, y);	

	strcpy(lastMessage, "You hear Zecora's voice echo, 'Hurry up dear Apple Bloom! I need you here quick, so please come soon!'\n");

	//play the music
	system("./music | aplay 2> /dev/null 1> /dev/null &");	

	while(alive) {
		system("clear");

		printf("%s", lastMessage);
		
		printMaze(maze, fow);
		
		//Prompt for move, figure out new position
	
		printf("Your move> ");
		
		char move;

		fscanf(stdin, "%c", &move);

		int newX = x;
		int newY = y;
		
		if(move == NORTH || move == 'n') {
			newX = newX - 1;
			fow[newX-1][newY] = true;
		} else if (move == SOUTH || move == 's') {
			newX = newX + 1;
			fow[newX+1][newY] = true;
		} else if (move == EAST || move == 'e') {
			newY = newY + 1;
			fow[newX][newY+1] = true;
		} else if (move == WEST || move == 'w') {
			newY = newY - 1;
			fow[newX][newY-1] = true;
		} else if (move == 'Q' || move == 'q' || move == '\0') {
			printf("\nYou give up. You sister and her friends are stuck all kinds of messed up.\n");
			break;
		} else if (move == '\n') {
			putchar(move);
			continue;
		} else {
			printf("%x: Not a valid move", move);
		}

		printf("\n");
		
		int status = isValidMove(maze, fow, newX, newY);

		if(status != NORMAL) {
			if(status == TREEBLOCK) {
				fprintf(fout, "Moving to %i,%i - Failed, tree blocks path\n", x, y);
			} else if(status == DEAD) {
                        	fprintf(fout, "Encountered Trixie at %i,%i - it was fatal\n", x, y);
				break;
                	} else if(status == VICTORY) {
				fprintf(fout, "Found the exit at %i,%i - victory!\n", x, y);
				break;
			} 
		} else if(status == DEAD) {
			fprintf(fout, "Encountered Trixie at %i,%i - it was fatal\n", x, y);
		} else {
			fprintf(fout, "Moving to %i,%i - Succeeded\n", x, y);
		}
		
		moveHag();
	}
	
	fclose(fout);

	//kill the music process
	system("killall music aplay -s SIGKILL");	

	return 0;
}
コード例 #16
0
ファイル: project3.c プロジェクト: denisdoci/school-projects
int main(int argc, char** argv)
{
    maze m1;
    node * stack=NULL; // stack pointer
    node * temp; //temporary node
    int px, py; // previous x and y positions
    int x, y;  //x and y positions
    int i,j;
    int debugMode = false;
    char *file;

    /* verify the proper number of command line arguments were given */
    if( argc > 3 ) {
        printf("Usage: %s [-d] <maze data file>\n", argv[0]);
        exit(-1);
    }

    if( 2 == argc ) {//2 arguements, no debug
        file = argv[1];
    }

    if( 3 == argc ) { //three arguements provided with debug
        if( argv[1][0] == '-' && argv[1][1] == 'd' ) {
            debugMode = true;  // ./a.out -d mazeInput.txt
            file = argv[2];
        }
        else if(argv[2][0] == '-' && argv[2][1] == 'd') {
            debugMode = true;  // ./a.out mazeInput.txt -d
            file = argv[1];
        }
    }


    m1 = createMaze(file); //initialize maze

    printf("Input Maze\n");
    printf ("size: %d, %d\n", m1.xsize, m1.ysize);
    printf ("start: %d, %d\n", m1.xstart, m1.ystart);
    printf ("end: %d, %d\n", m1.xend, m1.yend);

    printMaze(m1);

    stack = solve(m1, debugMode);

    if(stack == NULL) { //nothing on stack
        printf("\n This maze is unsolvable!!!\n");
    }
    else {
        px= -1; //previous x and y set to -1 as to not be in maze
        py= -1;

        temp = stack;

        while(temp != NULL) {
            x = temp->x;
            y = temp->y;
            if(m1.array[x][y] != 'e' &&  m1.array[x][y] != 's') {
                if(px == x+1)
                    m1.array[x][y] = 'V'; //down
                else if (px == x-1)
                    m1.array[x][y] = '^'; //up
                else if(py == y+1)
                    m1.array[x][y] = '>'; //right
                else if(py == y-1)
                    m1.array[x][y] = '<'; //left
                else {
                    printf("\nValue not available in stack (%d, %d)\n", x,y);
                }
            }
            px = x; //set previous x and y to the node's values
            py = y;
            temp = temp->next; //move along stack
        }
    }
    printMaze(m1); // reprint maze with solution
    printf("\nSolution coordinates: \n");
    printSt( stack);
    printf("\n");

    rmStack(&stack);
    rmMaze(m1);

    return(0);
}
コード例 #17
0
int main(void) {
	const int magic_number = 13017;

	/* test min */
	int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	printf("the smallest of the first 10 natural numbers is: %d\n", minIt(a, 10));
	printf("the smallest of the first 10 natural numbers is: %d\n", minRec1(a, 10));
	printf("the smallest of the first 10 natural numbers is: %d\n", minRec2(a, 10));
	a[3] = -1;
	printf("now the smallest is %d\n", minIt(a, 10));
	printf("now the smallest is %d\n", minRec1(a, 10));
	printf("now the smallest is %d\n", minRec2(a, 10));
	
	/* test sqrt */
	printf("the sqrt of 25 is %g\n", sqrtIt(25.0, 0, 25.0));
	printf("the sqrt of 26 is %g\n", sqrtIt(26.0, 0, 26.0));
	printf("the sqrt of 2 is %g\n", sqrtIt(2.0, 0, 2.0));
	printf("the sqrt of 25 is %g\n", sqrtRec(25.0, 0, 25.0));
	printf("the sqrt of 26 is %g\n", sqrtRec(26.0, 0, 26.0));
	printf("the sqrt of 2 is %g\n", sqrtRec(2.0, 0, 2.0));

	/* test strCompare */
	char* s1; char* s2;
	s1 = "apple"; s2 = "apricot";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}
			
	s1 = "Apple"; s2 = "apple";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "baby boy"; s2 = "banana";
	if (strCompare(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "a rather silly string"; s2 = "a rather silly string";
	if (strCompare(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "12345"; s2 = "12345";
	if (strCompare(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "Numbers: 12345"; s2 = "12345";
	if (strCompare(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	s1 = "Texas"; s2 = "California";
	if (strCompare(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	/* test strCompare2 */
	s1 = "apple"; s2 = "Apricot";
	if (strCompare2(s1, s2) < 0) { 
		printf("\"%s\" is less than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be less than \"%s\"\n", s1, s2);
	}

	s1 = "Batman!"; s2 = "bat man";
	if (strCompare2(s1, s2) == 0) { 
		printf("\"%s\" is equal to \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be equal to \"%s\"\n", s1, s2);
	}

	s1 = "OMG, WTF?"; s2 = "oh my goodness, what the heck?";
	if (strCompare2(s1, s2) > 0) { 
		printf("\"%s\" is greater than \"%s\", very good\n", s1, s2);
	} else {
		printf("oops, \"%s\" should be greater than \"%s\"\n", s1, s2);
	}

	/* test maze */		
	srand(magic_number);
	makeMaze();
	recodeMaze();
	printf("recursive solution to the maze\n");
	printMaze();
	solveMazeRec(0, start_col);	
	printMaze();
	printf("\n\n\n");
	
	printf("iterative solution to the maze\n");
	srand(magic_number);
	makeMaze();
	recodeMaze();
	printMaze();
	solveMazeIt(0, start_col);
	printMaze();


	/* test Martian */
	Martian change1 = changeIt(15);
	printf("change 1 should be 0d, 3n, 0p and is: %dd %dn %dp\n", change1.dodeks, change1.nicks, change1.pennies);

	Martian change2 = changeIt(0);
	printf("change 2 should be 0d, 0n, 0p and is: %dd %dn %dp\n", change2.dodeks, change2.nicks, change2.pennies);

	Martian change3 = changeIt(17);
	printf("change 3 should be 1d, 1n, 0p and is: %dd %dn %dp\n", change3.dodeks, change3.nicks, change3.pennies);

	Martian change4 = changeIt(25);
	printf("change 4 should be 2d, 0n, 1p and is: %dd %dn %dp\n", change4.dodeks, change4.nicks, change4.pennies);

	/* A very simple and obvious test of the general form of Martian
	 * be sure and test your solution more thoroughly!!!! */
	change4 = changeIt(25, 5, 12);
	printf("change 4 should be 2d, 0n, 1p and is: %dd %dn %dp\n", change4.dodeks, change4.nicks, change4.pennies);
}
コード例 #18
0
ファイル: path.c プロジェクト: dillonmabry/Maze-Traversal--C
main()
{
  /* generate user input for displaying maze */
  int rows, cols;
  printf("Enter the row size:\n");
  scanf("%d",&rows);
  printf("Enter the column size:\n");
  scanf("%d",&cols);

  /* generate fixed 2D array size of 200x200 to display maze */
  char field[200][200]={1};

  /* initialize variables for traversing */
  FILE *fptr;
  char c;
  char file_name[20];
  int i,j;
  int start_x, start_y;
  
  /* begin file parsing and input ASCII file */
  printf("Type in the name of the file containing the Field\n");
  scanf("%s",file_name);
  fptr=fopen(file_name,"r");
  for (i=0; i<rows; i++) 
    for (j=0; j<cols; j++){
        c=fgetc(fptr); 
        while ( !((c == '1')||(c =='0')) ) c=fgetc(fptr);
            field[i][j]=c;
    } 

    fclose(fptr);
    
    /* traverse across 2D array left side, bottom, right, then top finding
    the entrance point */
	i=rows-1; 
	for (j=cols-1; i>0; i--){
		if (field[i][j] == '0'){
		 	start_x = i;
		 	start_y = j;         
			break;
		}
	} /* end right side traverse */
		
	j=cols-1; 
	for (i=0; j>0; j--){
		if (field[i][j] == '0'){
			start_x = i;
			start_y = j; 
		 	break;
		}
	} /* end top traverse */
			
	for(j=0; i < rows-1; i++) {
		if(field[i][j] == '0') {    
		 	start_x = i;
		 	start_y =j;
		 	break;
		}
	} /* end left side traverse */
			
	j=1; 
	for (i=rows-1; j<cols-1; j++){
		if (field[i][j] == '0'){
		 	start_x = i;
			start_y = j;        
			break;
		}
	} /* end bottom traverse */
      
    printf("Entrance is at:[%d][%d]\n", start_x, start_y);
      
    /* if pointer can move then print field, otherwise print the
    field anyway to display results */
    if(canMove(field, start_x,start_y)) {
        /* print maze */
        printMaze(field, rows, cols);
      } else {
          /* print maze */
        printMaze(field, rows, cols);
      }
      
	/* create counter to keep track of if the maze has an 
      entry or exit point, if the maze has both an entry and exit return 
      solution found display, else return no solution */
      int count;
      for (i=0; i<rows; i++)
        for (j=0; j<cols; j++)  {
            if ( j == 0 && field[i][j] == 'X') {
                    count+=1;
            } else if (i == rows-1 && field[i][j]=='X') {
                    count+=1;
            } else if (j == cols-1 && field[i][j]=='X') {
                    count+=1;
            } else if( i==0 && field[i][j] == 'X') {
                    count+=1;
            } else {
                    /* do nothing */
            }
        }
    
	/* if the counter is greater than 1 then both the entrance and exit have
	been traversed and displayed by 'X' character, otherwise only 1 has been
	traversed meaning there is no solution */
    if(count>1) {
        printf("Solution found!\n");
    } else {
        printf("No solution!\n");
    }
 
    return 0;
      
} /* end of main function */