Writing an algorithm to have a robot solve a maze. I know the algorithm well and have implemented it some time ago using php. In GE, however, it does not seem to work and I have no idea why the robots behaves that way.
Here is the code:
- Code: Select all
short int choice=0;//rand(4)
switch(choice){
case 0:
if(CollisionFree("Event Actor",x,y+1)==1
&& (in_array(memorx, 100, x)==-1 || in_array(memory, 100, (y+1))==-1) ){
//memorizing
memorx[memorx_index]=x;
memory[memory_index]=y+1;
//updating memory index
if(memorx_index+1==100){memorx_index=0;memory_index=0;}
else {memorx_index++;memory_index++;}
y+=1;
break;
}
case 1:
if(CollisionFree("Event Actor",x,y-1)==1
&& (in_array(memorx, 100, x)==-1 || in_array(memory, 100, (y-1))==-1) ){
//memorizing
memorx[memorx_index]=x;
memory[memory_index]=y-1;
//updating memory index
if(memorx_index+1==100){memorx_index=0;memory_index=0;}
else {memorx_index++;memory_index++;}
y-=1;
break;
}
case 2:
if(CollisionFree("Event Actor",x-1,y)==1
&& (in_array(memorx, 100, (x-1))==-1 || in_array(memory, 100, y)==-1) ){
//memorizing
memorx[memorx_index]=x-1;
memory[memory_index]=y;
//updating memory index
if(memorx_index+1==100){memorx_index=0;memory_index=0;}
else {memorx_index++;memory_index++;}
x-=1;
break;
}
case 3:
if(CollisionFree("Event Actor",x+1,y)==1
&& (in_array(memorx, 100, (x+1))==-1 || in_array(memory, 100, y)==-1) ){
//memorizing
memorx[memorx_index]=x+1;
memory[memory_index]=y;
//updating memory index
if(memorx_index+1==100){memorx_index=0;memory_index=0;}
else {memorx_index++;memory_index++;}
x+=1;
break;
}
}
I am not asking to review the code, for now just want to know: am I right in assuming that if condition in case:0 does not work, the code should go to case 2?