I'm trying to create a maze with a mouse inside moving up down left right in 200 moves. I've got everything working besides the fact that it duplicates the heart on the other side(If it exits on the left, it'll be duplicated at the right end) when the heart shape(mouse) when it escapes the maze via the left/right exit.
Can anyone point out what i'm doing wrong?
#include <stdio.h>
#include <time.h>
int main(void){
int y[12][12] = {{0},{0}};
int x;
int i;
int j;
int a;
int b;
int c;
int d;
int roll;
int move;
srand(time(NULL));
a=5;
b=5;
y[5][5]=003;
{
for(i=1; i<=10;i++){
y[1][i] = 2;
if(i==5 || i==6)
y[1][i] = 0;}
for(i=1; i<=10;i++){
y[10][i] = 2;
if(i==5 || i==6)
y[10][i] = 0;}
for(i=4; i<=7;i++){
y[7][i] = 2;}
for(j=1; j<=10;j++){
y[j][1] = 2;
if(j==5 || j==6)
y[j][1] = 0;}
for(j=1; j<=10;j++){
y[j][10] = 2;
if(j==5 || j==6)
y[j][10] = 0;}
for(j=1; j<=4;j++){
y[j][4] = 2;}
for(j=4; j<=5;j++){
y[j][8] = 2;}}
for(roll=1;roll<=200;roll++){
move = 1+rand()%4;
if (move==1){
if(y[a-1][b] !=2){
y[a][b] = 0;
y[a-1][b] = 003;
a= a-1;}}
if (move==2){
if(y[a+1][b] !=2){
y[a][b] = 0;
y[a+1][b] = 003;
a=a+1;}}
if (move==3){
if(y[a][b-1] !=2){
y[a][b] = 0;
y[a][b-1] = 003;
b=b-1;}}
if (move==4){
if(y[a][b+1] !=2){
y[a][b] = 0;
y[a][b+1] = 003;
b=b+1;}}
if(a>11 || b>11 || a<0 || b<0){
printf("The Mouse Escaped");
break;}
else{
printf("%d\t%d\n",roll,move);}
for(i=0; i<=12; i++){
for(j=0; j<=12; j++){
if (y[i][j]==003)
printf("%c",003);
else if (y[i][j]==2)
printf("%c",254);
else
printf(" ");}
printf("\n");
}
}
printf("\n");
return 0;
}
Any help is greatly appreciated, thanks first. :)