리펙토링이 필요함
~cpp
#include <iostream>
using namespace std;
int map [17][17]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1}
,{1,1,0,0,0,1,1,0,1,1,1,0,0,1,1,1,1},
{1,0,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1},
{1,1,1,0,1,1,1,1,0,1,1,0,1,1,0,0,1},
{1,1,1,0,1,0,0,1,0,1,1,1,1,1,1,1,1},
{1,0,0,1,1,0,1,1,1,0,1,0,0,1,0,1,1},
{1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1},
{1,0,0,1,1,0,1,1,0,1,1,1,1,1,0,1,1},
{1,1,1,0,0,0,1,1,0,1,1,0,0,0,0,0,1},
{1,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,0,1,1,1,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
int x;
int y;
int look;
void go2(int x_1, int y_1, int x_2, int y_2, int x_3, int y_3)//1앞, 2앞오른쪽, 3오른쪽
{
if (1==map[x_3][y_3])
{
if (1==map[x_2][y_2])
{
if (1==map[x_1][y_1])
{
look=look-2;
look+=8;
look=look%8;
}
else
{
map[x_1][y_1]=2;
x=x_1;
y=y_1;
}
}
else
{
map[x_2][y_2]=2;
x=x_2;
y=y_2;
look+=1;
look=look%8;
}
}
else
{
map[x_3][y_3]=2;
x=x_3;
y=y_3;
look+=2;
look=look%8;
}
}
int main()
{
int i=0;
int j=0;
x=1;
y=1;
look=4;//12시를 0으로 간주합니다.
while (1)
{
if (x==11 && y==15)
{
break;
}
else
{
switch(look)
{
case 0:
go2(x-1,y,x-1,y+1,x,y+1);
break;
case 1:
go2(x-1,y+1,x,y+1,x+1,y+1);
break;
case 2:
go2(x,y+1,x+1,y+1,x+1,y);
break;
case 3:
go2(x+1,y+1,x+1,y,x+1,y-1);
break;
case 4:
go2(x+1,y,x+1,y-1,x,y-1);
break;
case 5:
go2(x+1,y-1,x,y-1,x-1,y-1);
break;
case 6:
go2(x,y-1,x-1,y-1,x-1,y);
break;
case 7:
go2(x-1,y-1,x-1,y,x-1,y+1);
break;
}
}
}
for (i=0; i<17; i++)
{
for (j=0; j<17; j++)
{
if (2==map[i][j])
{
cout << "*";
}
else
{
cout << map[i][j];
}
}
cout << "\n";
}
}