{{{~cpp #include using namespace std; #include int const arsize = 11; void main() { int num,x,y,cnt=0,total=0,end=1,temp; cout << "원하는 칸의 크기를 입력하세요 : "; cin >> num; int square[arsize][arsize] ={0,}; cout << "바퀴벌레의 처음 좌표를 입력하세요 (x,y): "; cin >> x; cin >> y; square[x][y]=1; srand(0); while(end < num*num) { temp = rand()%8; switch (temp) { case 1 : if(x-1>=0 && y-1>=0) { y--; x--; } break; case 2 : if(x-1>=0) x--; break; case 3 : if(x-1>=0 && y+1=0) y--; break; case 5 : if(y+1=0) { x++; y--; } break; case 7 : if(x+1 using namespace std; #include"Board.h" #include"Bug.h" Board::Board() { for (int i = 0; i < MAX_BOARD ; i++) { for (int j = 0; j < MAX_BOARD ; j++) board[i][j]=0; } EndCount=0; } void Board::Show_Board() { for (int i = 0; i < MAX_BOARD ; i++) { for (int j = 0; j < MAX_BOARD ; j++) cout << board[i][j] << "\t" ; cout << endl; } cout << endl; } void Board::Make_Footprint(int a_x, int a_y) { board[a_x][a_y]++; if(board[a_x][a_y]==1) EndCount++; } bool Board::IsNotEnd() { if (EndCount < 25) return true; else return false; } }}} == Bug.cpp == {{{~cpp #include using namespace std; #include"Bug.h" #include Bug::Bug() { x=0; y=0; } void Bug::move() { int way; way = rand()%8; if (x+MOVE_X[way]> -1 && x+MOVE_X[way]<5 && y+MOVE_Y[way] > -1 && y+MOVE_Y[way] < 5) { x+=MOVE_X[way]; y+=MOVE_Y[way]; } } }}} == RandomWalk.cpp == {{{~cpp #include using namespace std; #include "Board.h" #include "Bug.h" #include void main() { srand((unsigned)time(NULL)); Bug bug1; Board board; board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); do{ bug1.move(); board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); }while(board.IsNotEnd()); } }}} == Board.h == {{{~cpp #include using namespace std; #include "Board.h" #include "Bug.h" #include void main() { srand((unsigned)time(NULL)); Bug bug1; Board board; board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); do{ bug1.move(); board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); }while(board.IsNotEnd()); } }}} == Bug.h == {{{~cpp #include using namespace std; #include "Board.h" #include "Bug.h" #include void main() { srand((unsigned)time(NULL)); Bug bug1; Board board; board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); do{ bug1.move(); board.Make_Footprint(bug1.return_x(), bug1.return_y()); board.Show_Board(); }while(board.IsNotEnd()); } }}}