okay first let me post the code...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROW 15
#define COL 50
void creatmaze (int [][COL]);
void printarea(int [][COL]);
int main(void)
{
int maze[ROW][COL]={0};
srand(time(0));
creatmaze(maze);
printarea(maze);
system("PAUSE");
return 0;
}
void creatmaze ( int maze[][COL] )
{
int cnt_main, cnt_sub, cnt;
int row, col, movement,cnt_stop;
for ( cnt_main = 0; cnt_main <= COL-1; cnt_main+=COL-1 ){
for ( cnt_sub = 0; cnt_sub <= ROW-1; cnt_sub++ )
maze[cnt_sub][cnt_main] = 3;
}
for ( cnt_main = 0; cnt_main <= ROW-1; cnt_main+=ROW-1 ){
for ( cnt_sub = 0; cnt_sub <= COL-1; cnt_sub++ )
maze[cnt_main][cnt_sub] = 3;
}
maze[3][0] = -2; /*starting point*/
maze[8][49] = -1; /*Exit point */
cnt_main = 0;
while ( ++cnt_main != 400 ){
col = rand() / (RAND_MAX /COL-1)+1;
row = rand() / (RAND_MAX / ROW-1)+1;
if ( maze[row][col] < 0 || maze[row][col] == 3)
;
else
maze[row][col] = 1;
}
/* My Fake AI **** */
/*Gotta fin out how to make it work ;) */
}
void printarea(int maze[][COL])
{
int cnt_main, cnt_sub;
for ( cnt_main = 0; cnt_main < ROW; cnt_main++ ){
for ( cnt_sub = 0; cnt_sub < COL; cnt_sub++ ){
if ( maze[cnt_main][cnt_sub] == 3 )
putchar(178);
else if ( maze[cnt_main][cnt_sub] == 1 )
putchar(177);
else if ( maze[cnt_main][cnt_sub] == -2 )
putchar(2);
else if ( maze[cnt_main][cnt_sub] == 0 )
putchar(255);
else
putchar(6);
}
printf("\n");
}
}
Okay the first problem is the one that is important well exactly it isnt a problem in the code ...what i wanna try is after randomly puts the walls in the area ...i want to simulate the path like creat a path that starts from the begenning and ends at the exit point...i have tried doing it but i cant get the right code to apply
2) I execute the same stuff on a linux box and instead of giving me the oem character like the walls smilly face and the spade it gave me ansi characters but on a windows it gives me a oem character ...why and how can i change that ???
3) The programm some times crashes in the middle of the program or after pressing enter .In linux the gcc compiler produces an error like segementation fault ,....in windows yeah it gives the same stuff ....
4) Help me