/* http://www.mrwadlo.com */ #include #include #include #include void calc_time(); void count_100ths(int hund); int random(int max); void displayscreen(); int block(); int deblock(); void depath(); void makepath(); void deloop(); void displaypercent(int value, int total); void addwall(); void closepath(); void hidepath(); int deislandizing(); int checkisland(int i, int j); long one_sec = 0; char screen[80][24]; int main() { int tenth; int i,j; clrscr(); gotoxy(29,13); printf("Loading Maze Creator..."); calc_time(); clrscr(); gotoxy(2,25); for ( i=2 ; i<80 ; i++ ) { if ( i<24 || i>55 ) printf("%c",219); else printf(" "); } for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<80 ; i++ ) screen[ i ][ j ] = ' '; } makepath(); depath(); deloop(); depath(); addwall(); while ( block() || deblock() ) ; closepath(); while ( deislandizing() ) ; while ( deblock() ) ; closepath(); hidepath(); closepath(); displayscreen(); gotoxy(25,25); printf("Done. "); count_100ths(100); gotoxy(24,25); for ( i=24 ; i<56 ; i++ ) { printf("%c",219); } getch(); return 0; } void calc_time() { time_t time1; time1 = time(NULL); while( time(NULL) == time1 ) ; time1 = time(NULL); while( time(NULL) < (time1 + 2) ) { one_sec++; printf(" \b"); } one_sec /= 2; } void count_100ths(int hund) { long i = 0; time_t time1; gotoxy (1,25); while ( i < ( one_sec / 100 * hund ) ) { printf(" \b"); time1 = time(NULL); i++; } } void addwall() { char direction = '?'; int i, j; int posx, posy; int rnd; int stu, stux, stuy; gotoxy(25,25); printf("adding walls... "); for ( j=1 ; j<22 ; j++ ) for ( i=1 ; i<79 ; i++ ) { displaypercent(j*79+i,22*79); if ( screen[i][j] == -59 ) { posx = i; posy = j; if ( ( screen[i][j-1] == ' ' ) && (screen[i+1][j-1] == ' ' || screen[i-1][j-1] == ' ') ) { direction = 'u'; posy--; screen[posx][posy] = 219; } else if ( ( screen[i][j+1] == ' ' ) && (screen[i+1][j+1] == ' ' || screen[i-1][j+1] == ' ') ) { direction = 'd'; posy++; screen[posx][posy] = 219; } else if ( ( screen[i-1][j] == ' ' ) && (screen[i-1][j+1] == ' ' || screen[i-1][j-1] == ' ') ) { direction = 'l'; posx--; screen[posx][posy] = 219; } else if ( ( screen[i+1][j] == ' ' ) && (screen[i+1][j-1] == ' ' || screen[i+1][j+1] == ' ') ) { direction = 'r'; posx++; screen[posx][posy] = 219; } gotoxy(posx+1,posy+1); printf("%c",176); while ( posx > 0 && posx < 79 && posy > 0 && posy < 23 && screen[posx][posy] != -59 ) { rnd = random(3); if ( direction == 'u' ) { if ( rnd == 0 ) { if ( screen[posx-2][posy] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx-2][posy-1] == ' ' && screen[posx-2][posy+1] == ' ' ) { posx--; direction = 'l'; screen[posx][posy] = 219; } } else if ( rnd == 1 ) { if ( screen[posx][posy-2] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx-1][posy-2] == ' ' && screen[posx+1][posy-2] == ' ' ) { posy--; direction = 'u'; screen[posx][posy] = 219; } } else if ( rnd == 2 ) { if ( screen[posx+2][posy] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx+2][posy-1] == ' ' && screen[posx+2][posy+1] == ' ' ) { posx++; direction = 'r'; screen[posx][posy] = 219; } } } else if ( direction == 'd' ) { if ( rnd == 0 ) { if ( screen[posx+2][posy] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx+2][posy-1] == ' ' && screen[posx+2][posy+1] == ' ' ) { posx++; direction = 'r'; screen[posx][posy] = 219; } } else if ( rnd == 1 ) { if ( screen[posx][posy+2] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx-1][posy+2] == ' ' && screen[posx+1][posy+2] == ' ' ) { posy++; direction = 'd'; screen[posx][posy] = 219; } } else if ( rnd == 2 ) { if ( screen[posx-2][posy] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx-2][posy-1] == ' ' && screen[posx-2][posy+1] == ' ' ) { posx--; direction = 'l'; screen[posx][posy] = 219; } } } else if ( direction == 'l' ) { if ( rnd == 0 ) { if ( screen[posx][posy-2] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx-1][posy-2] == ' ' && screen[posx+1][posy-2] == ' ' ) { posy--; direction = 'u'; screen[posx][posy] = 219; } } else if ( rnd == 1 ) { if ( screen[posx-2][posy] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx-2][posy-1] == ' ' && screen[posx-2][posy+1] == ' ' ) { posx--; direction = 'l'; screen[posx][posy] = 219; } } else if ( rnd == 2 ) { if ( screen[posx][posy+2] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx-1][posy+2] == ' ' && screen[posx+1][posy+2] == ' ' ) { posy++; direction = 'd'; screen[posx][posy] = 219; } } } else if ( direction == 'r' ) { if ( rnd == 0 ) { if ( screen[posx][posy-2] == ' ' && screen[posx-1][posy-1] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx-1][posy-2] == ' ' && screen[posx+1][posy-2] == ' ' ) { posy--; direction = 'u'; screen[posx][posy] = 219; } } else if ( rnd == 1 ) { if ( screen[posx+2][posy] == ' ' && screen[posx+1][posy-1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx+2][posy-1] == ' ' && screen[posx+2][posy+1] == ' ' ) { posx++; direction = 'r'; screen[posx][posy] = 219; } } else if ( rnd == 2 ) { if ( screen[posx][posy+2] == ' ' && screen[posx-1][posy+1] == ' ' && screen[posx+1][posy+1] == ' ' && screen[posx-1][posy+2] == ' ' && screen[posx+1][posy+2] == ' ' ) { posy++; direction = 'd'; screen[posx][posy] = 219; } } } count_100ths(1); if ( stux == posx && stuy == posy ) { stu++; if ( stu > 10 ) break; } else { stux = posx; stuy = posy; stu = 0; } } } } } void displayscreen() { int i, j; gotoxy(1,1); for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<80 ; i++ ) printf("%c", screen[ i ][ j ] ); } } int random(int max) { int rnd; time_t time1; time1 = time(NULL); rnd = ( rand() + time1 ) % max; return rnd; } int block() { int i,j; int cor; int change = 0; gotoxy(25,25); printf("Blocking... "); for ( j=0 ; j<23 ; j++ ) { for ( i=0 ; i<79 ; i++ ) { displaypercent(j*79+i,23*79); if ( screen[i][j] == ' ' && screen[i+1][j] == ' ' && screen[i][j+1] == ' ' && screen[i+1][j+1] == ' ' ) { change = 1; cor = random(4); if ( cor == 0 ) screen[i][j] = 219; else if ( cor == 1) screen[i+1][j] = 219; else if ( cor == 2) screen[i][j+1] = 219; else screen[i+1][j+1] = 219; } } } displayscreen(); return change; } int deblock() { int i,j; int cor; int change = 0; gotoxy(25,25); printf("Deblocking... "); for ( j=0 ; j<23 ; j++ ) { for ( i=0 ; i<79 ; i++ ) { displaypercent(j*79+i,23*79); if ( screen[i][j] == -37 && screen[i+1][j] == -37 && screen[i][j+1] == -37 && screen[i+1][j+1] == -37 ) { change = 1; cor = random(4); if ( cor == 0 ) screen[i][j] = ' '; else if ( cor == 1) screen[i+1][j] = ' '; else if ( cor == 2) screen[i][j+1] = ' '; else screen[i+1][j+1] = ' '; } } } displayscreen(); return change; } void depath() { int i,j; int cor; int change; int sides; gotoxy(25,25); printf("Depathing... "); do { change = 0; for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<79 ; i++ ) { displaypercent(j*79+i,24*79); sides = 0; if ( screen[i][j] == -59 ) { if ( i==0 || screen[i-1][j] == ' ') sides++; if ( screen[i+1][j] == ' ') sides++; if ( j==0 || screen[i][j-1] == ' ') sides++; if ( j==23 || screen[i][j+1] == ' ') sides++; if ( ( i>0 && j>0 && i<79 && j<23) && ( ( screen[i-1][j] == ' ' && screen[i][j-1] == ' ' && screen[i+1][j] == -59 && screen[i][j+1] == -59 && screen[i+1][j+1] == -59 ) || ( screen[i+1][j] == ' ' && screen[i][j-1] == ' ' && screen[i-1][j] == -59 && screen[i][j+1] == -59 && screen[i-1][j+1] == -59 ) || ( screen[i+1][j] == ' ' && screen[i][j+1] == ' ' && screen[i-1][j] == -59 && screen[i][j-1] == -59 && screen[i-1][j-1] == -59 ) || ( screen[i-1][j] == ' ' && screen[i][j+1] == ' ' && screen[i+1][j] == -59 && screen[i][j-1] == -59 && screen[i+1][j-1] == -59 ) || ( screen[i-1][j] == -59 && screen[i-1][j+1] == -59 && screen[i][j+1] == -59 && screen[i+1][j] == -59 && screen[i+1][j+1] == -59 && screen[i][j-1] == ' ' ) || ( screen[i+1][j] == -59 && screen[i+1][j+1] == -59 && screen[i][j+1] == -59 && screen[i][j-1] == -59 && screen[i+1][j-1] == -59 && screen[i-1][j] == ' ' ) || ( screen[i-1][j] == -59 && screen[i-1][j+1] == -59 && screen[i][j+1] == -59 && screen[i][j-1] == -59 && screen[i-1][j-1] == -59 && screen[i+1][j] == ' ' ) || ( screen[i-1][j] == -59 && screen[i-1][j-1] == -59 && screen[i][j-1] == -59 && screen[i+1][j] == -59 && screen[i+1][j-1] == -59 && screen[i][j+1] == ' ' ) ) || ( sides > 2 ) ) { screen[i][j] = ' '; change = 1; gotoxy(i+1,j+1); printf("%c",206); count_100ths(5); } } } } } while ( change == 1 ); displayscreen(); } void makepath() { int posx = 0; int posy = 0; int movement; screen[posx][posy] = 'S'; gotoxy(25,25); printf("Pathing... "); while ( posx != 79 ) { displaypercent(posx,79); movement = random(4); if ( movement == 0 && screen[posx][posy-1] == ' ' && posy>0 ) { posy--; screen[posx][posy] = 197; } else if ( movement == 1 && screen[posx+1][posy] == ' ' && posx<79 ) { posx++; screen[posx][posy] = 197; } else if ( movement == 2 && screen[posx][posy+1] == ' ' && posy<23 ) { posy++; screen[posx][posy] = 197; } else if ( movement == 3 && screen[posx-1][posy] == ' ' && posx>0 ) { posx--; screen[posx][posy] = 197; } else if ( ( screen[posx-1][posy] != ' ' || posx == 0 ) && ( screen[posx][posy-1] != ' ' || posy == 0 ) && ( screen[posx+1][posy] != ' ' || posx == 79 ) && ( screen[posx][posy+1] != ' ' || posy == 23 ) ) { posx++; } gotoxy(posx+1,posy+1); printf("%c",197); count_100ths(1); } screen[posx][posy] = 'E'; displayscreen(); } void deloop() { int i, j; int t_x, t_y; int tempx, tempy; char direction; int turns; int counter; gotoxy(25,25); printf("Delooping... "); for ( j=0 ; j<23 ; j++ ) { for ( i=0 ; i<79 ; i++ ) { displaypercent(j*79+i,23*79); turns = 0; t_x = i; t_y = j; counter = 0; if ( screen[t_x][t_y] == ' ' ) { gotoxy(t_x+1,t_y+1); printf("."); count_100ths(1); while ( screen[t_x][t_y-1] == ' ' && t_y > 0 ) { t_y--; } tempx=t_x; tempy=t_y; t_x++; direction = 'l'; while ( t_x>0 && t_x<79 && t_y>0 && t_y<23 ) { if( direction == 'l' ) { t_x--; if ( screen[t_x][t_y-1] == ' ' ) direction = 'u'; else if ( screen[t_x-1][t_y] == ' ' ) direction = 'l'; else if ( screen[t_x][t_y+1] == ' ' ) direction = 'd'; else if ( screen[t_x+1][t_y] == ' ' ) direction = 'r'; else { screen[t_x][t_y] = 197; gotoxy(t_x+1,t_y+1); printf("%c", 174); } } else if( direction == 'u' ) { t_y--; if ( screen[t_x+1][t_y] == ' ' ) direction = 'r'; else if ( screen[t_x][t_y-1] == ' ' ) direction = 'u'; else if ( screen[t_x-1][t_y] == ' ' ) direction = 'l'; else if ( screen[t_x][t_y+1] == ' ' ) direction = 'd'; else { screen[t_x][t_y] = 197; gotoxy(t_x+1,t_y+1); printf("%c", 174); } } else if( direction == 'r' ) { t_x++; if ( screen[t_x][t_y+1] == ' ' ) direction = 'd'; else if ( screen[t_x+1][t_y] == ' ' ) direction = 'r'; else if ( screen[t_x][t_y-1] == ' ' ) direction = 'u'; else if ( screen[t_x-1][t_y] == ' ' ) direction = 'l'; else { screen[t_x][t_y] = 197; gotoxy(t_x+1,t_y+1); printf("%c", 174); } } else if( direction == 'd' ) { t_y++; if ( screen[t_x-1][t_y] == ' ' ) direction = 'l'; else if ( screen[t_x][t_y+1] == ' ' ) direction = 'd'; else if ( screen[t_x+1][t_y] == ' ' ) direction = 'r'; else if ( screen[t_x][t_y-1] == ' ' ) direction = 'u'; else { screen[t_x][t_y] = 197; gotoxy(t_x+1,t_y+1); printf("%c", 174); } } if ( counter > 1000 ) { t_x = 0; gotoxy(28,28); printf("ERROR FOUND"); getch(); } else counter++; if ( t_x == tempx && t_y == tempy ) { turns++; if ( turns > 2 ) { if ( screen[tempx][tempy-2] == ' ' ) { screen[tempx][tempy-1] = ' '; gotoxy(t_x+1,t_y); printf("%c", 174); } else { screen[tempx+1][tempy-1] = ' '; gotoxy(t_x+2,t_y); printf("%c", 174); } break; } } } } } } } void displaypercent(int value, int total) { float percent = 1.0*value/total*100; gotoxy(42,25); printf("%3.0f%% Complete", percent); if ( percent > 100 ) getch(); } void hidepath() { int i, j; gotoxy(25,25); printf("Hiding Path... "); for ( j=0 ; j<24 ; j++ ) for ( i=0 ; i<80 ; i++ ) { displaypercent((j-1)*79+i,23*79); if ( screen[i][j] == -59 ) screen[i][j] = ' '; } } void closepath() { int i, j; int change; do { change = 0; gotoxy(25,25); printf("Increase Tabs..."); for ( j=0 ; j<24 ; j++ ) for ( i=0 ; i<80 ; i++ ) { displaypercent(j*80+i,24*80); if ( ( ( screen[i-1][j] == ' ' || screen[i-1][j] == -59 ) && ( screen[i+1][j] == ' ' || screen[i+1][j] == -59 ) && screen[i][j] == ' ' && screen[i][j+1] == -37 && ( screen[i-1][j-1] == ' ' || screen[i-1][j-1] == -59 ) && ( screen[i][j-1] == ' ' || screen[i+1][j] == -59 ) && ( screen[i+1][j-1] == ' ' || screen[i+1][j-1] == -59 ) ) || ( ( screen[i-1][j] == ' ' || screen[i-1][j] == -59 ) && ( screen[i+1][j] == ' ' || screen[i+1][j] == -59 ) && screen[i][j] == ' ' && screen[i][j-1] == -37 && ( screen[i-1][j+1] == ' ' || screen[i-1][j+1] == -59 ) && ( screen[i][j+1] == ' ' || screen[i][j+1] == -59 ) && (screen[i+1][j+1] == ' ' || screen[i+1][j+1] == -59 ) ) || ( ( screen[i][j-1] == ' ' || screen[i][j-1] == -59 ) && ( screen[i][j+1] == ' ' || screen[i][j+1] == -59 ) && screen[i][j] == ' ' && screen[i+1][j] == -37 && ( screen[i-1][j-1] == ' ' || screen[i-1][j-1] == -59 ) && ( screen[i-1][j] == ' ' || screen[i-1][j] == -59) && ( screen[i-1][j+1] == ' ' || screen[i-1][j+1] == -59 ) ) || ( ( screen[i][j-1] == ' ' || screen[i][j-1] == -59 ) && ( screen[i][j+1] == ' ' || screen[i][j+1] == -59 ) && screen[i][j] == ' ' && screen[i-1][j] == -37 && ( screen[i+1][j-1] == ' ' || screen[i+1][j-1] == -59 ) && ( screen[i+1][j] == ' ' || screen[i+1][j] == -59 ) && ( screen[i+1][j+1] == ' ' || screen[i+1][j+1] == -59 ) ) ) { screen[i][j] = 219; change = 1; gotoxy(i+1,j+1); printf("%c", 241); count_100ths(10); } } displayscreen(); gotoxy(25,25); printf("Removing Dots..."); for ( j=1 ; j<23 ; j++ ) for ( i=1 ; i<79 ; i++ ) { displaypercent((j-1)*78+i,22*78); if ( ( screen[i-1][j+1] == ' ' || screen[i-1][j+1] == -59 ) && ( screen[i][j+1] == ' ' || screen[i][j+1] == -59 ) && ( screen[i+1][j+1] == ' ' || screen[i+1][j+1] == -59 ) && ( screen[i-1][j] == ' ' || screen[i-1][j] == -59 ) && screen[i][j] == -37 && ( screen[i+1][j] == ' ' || screen[i+1][j] == -59 ) && ( screen[i-1][j-1] == ' ' || screen[i-1][j-1] == -59 ) && ( screen[i][j-1] == ' ' || screen[i][j-1] == -59 ) && ( screen[i+1][j-1] == ' ' || screen[i+1][j-1] == ' ' ) ) { if ( screen[i][j-2] == -37 && screen[i][j-1] == ' ' ) { screen[i][j-1] = 219; change = 1; count_100ths(10); } else if ( screen[i-2][j] == -37 && screen[i-1][j] == ' ' ) { screen[i-1][j] = 219; change = 1; count_100ths(10); } else if ( screen[i][j+2] == -37 && screen[i][j+1] == ' ' ) { screen[i][j+1] = 219; change = 1; count_100ths(10); } else if ( screen[i+2][j] == -37 && screen[i+1][j] == ' ' ) { screen[i+1][j] = 219; change = 1; count_100ths(10); } gotoxy(i+1,j+1); printf("%c", 232); } } displayscreen(); gotoxy(25,25); printf("Removing Zags..."); for ( j=1 ; j<23 ; j++ ) for ( i=1 ; i<79 ; i++ ) { displaypercent((j-1)*78+i,22*78); if ( ( screen[i][j] == ' ' && screen[i-1][j] == -37 && screen[i][j-1] == -37 && ( screen[i-1][j-1] == ' ' || screen[i-1][j-1] == -59 ) && screen[i][j+1] == -37 && ( screen[i-1][j+1] == ' ' || screen[i-1][j+1] == -59 ) ) || ( screen[i][j] == ' ' && screen[i+1][j] == -37 && screen[i][j-1] == -37 && ( screen[i+1][j-1] == ' ' || screen[i+1][j-1] == -59 ) && screen[i][j+1] == -37 && ( screen[i+1][j+1] == ' ' || screen[i+1][j+1] == -59 ) ) || ( screen[i][j] == ' ' && screen[i][j+1] == -37 && screen[i-1][j] == -37 && ( screen[i-1][j+1] == ' ' || screen[i-1][j+1] == -59 ) && screen[i+1][j] == -37 && ( screen[i+1][j+1] == ' ' || screen[i+1][j+1] == -59 ) ) || ( screen[i][j] == ' ' && screen[i][j-1] == -37 && screen[i-1][j] == -37 && ( screen[i-1][j-1] == ' ' || screen[i-1][j-1] == -59 ) && screen[i+1][j] == -37 && ( screen[i+1][j-1] == ' ' || screen[i+1][j-1] == -59 ) ) ) { gotoxy(i,j+1); printf("%c",16); screen[i][j] = 219; screen[i-1][j] = ' '; change = 1; count_100ths(10); } } } while ( change == 1 ); } int deislandizing() { int i, j; int done; int change = 0; for ( j=1 ; j<23 ; j++ ) for ( i=1 ; i<79 ; i++ ) { displaypercent((j-1)*78+i,22*78); done = 0; if ( checkisland(i,j) == 0 ) { done = 1; } else { if ( done == 0 && screen[i-1][j] == ' ' && screen[i-2][j] == -37 ) { screen[i-1][j] = 219; if ( checkisland(i,j) == 1 ) screen[i-1][j] = ' '; else done = 1; } if ( done == 0 && screen[i+1][j] == ' ' && screen[i+2][j] == -37 ) { screen[i+1][j] = 219; if ( checkisland(i,j) == 1 ) screen[i-1][j] = ' '; else done = 1; } if ( done == 0 && screen[i][j-1] == ' ' && screen[i][j-2] == -37 ) { screen[i][j-1] = 219; if ( checkisland(i,j) == 1 ) screen[i-1][j] = ' '; else done = 1; } if ( done == 0 && screen[i][j+1] == ' ' && screen[i][j+2] == -37 ) { screen[i][j+1] = 219; if ( checkisland(i,j) == 1 ) screen[i-1][j] = ' '; else done = 1; } if ( done == 1 ) { deblock(); gotoxy(i+1,j+1); printf("%c",177); change = 1; count_100ths(1); } } } return change; } int checkisland(int i, int j) { int posx, posy; int loops; char direction; int loops_total = 0; int true_false = 0; int counter; gotoxy(25,25); printf("Deislandizing..."); if ( screen[i][j] == -37 ) { loops = 0; posx = i; posy = j; if ( screen[i-1][j] == -37 ) { direction = 'l'; } else if ( screen[i+1][j] == -37 ) { direction = 'r'; } else if ( screen[i][j-1] == -37 ) { direction = 'u'; } else if ( screen[i][j+1] == -37 ) { direction = 'd'; } else posx = -1; counter = 0; while ( posx > 0 && posx < 79 && posy > 0 && posy < 23 ) { if( direction == 'l' ) { posx--; if ( screen[posx][posy-1] == -37 ) direction = 'u'; else if ( screen[posx-1][posy] == -37 ) direction = 'l'; else if ( screen[posx-1][posy-1] == -37 ) direction = '1'; else if ( screen[posx][posy+1] == -37 ) direction = 'd'; else if ( screen[posx-1][posy+1] == -37 ) direction = '3'; else if ( screen[posx+1][posy] == -37 ) direction = 'r'; else { } } else if( direction == 'u' ) { posy--; if ( screen[posx+1][posy] == -37 ) direction = 'r'; else if ( screen[posx][posy-1] == -37 ) direction = 'u'; else if ( screen[posx+1][posy-1] == -37 ) direction = '2'; else if ( screen[posx-1][posy] == -37 ) direction = 'l'; else if ( screen[posx-1][posy-1] == -37 ) direction = '1'; else if ( screen[posx][posy+1] == -37 ) direction = 'd'; else { } } else if( direction == 'r' ) { posx++; if ( screen[posx][posy+1] == -37 ) direction = 'd'; else if ( screen[posx+1][posy] == -37 ) direction = 'r'; else if ( screen[posx+1][posy+1] == -37 ) direction = '4'; else if ( screen[posx][posy-1] == -37 ) direction = 'u'; else if ( screen[posx+1][posy-1] == -37 ) direction = '2'; else if ( screen[posx-1][posy] == -37 ) direction = 'l'; else { } } else if( direction == 'd' ) { posy++; if ( screen[posx-1][posy] == -37 ) direction = 'l'; else if ( screen[posx][posy+1] == -37 ) direction = 'd'; else if ( screen[posx-1][posy+1] == -37 ) direction = '3'; else if ( screen[posx+1][posy] == -37 ) direction = 'r'; else if ( screen[posx+1][posy+1] == -37 ) direction = '4'; else if ( screen[posx][posy-1] == -37 ) direction = 'u'; else { } } if ( direction == '1' ) { posy--; direction = 'l'; } else if ( direction == '2' ) { posx++; direction = 'u'; } else if ( direction == '3' ) { posx--; direction = 'd'; } else if ( direction == '4' ) { posy++; direction = 'r'; } counter++; if ( counter > 77*21 ) { if ( loops > 10 ) { true_false = 1; loops_total++; } break; } if ( posx == i && posy == j ) { loops++; } } } return true_false; }