No older revisions available
No older revisions available
랜덤 워크...완성은 했는데 단점이 보이네요..ㅡㅡ^
~cpp #include <iostream> #include <ctime> using namespace std; int end(int aBoard[][5]); void output(int aBoard[][5]); void main() { int board[5][5]; srand(time(0)); int setX = rand() %5; int setY = rand() %5; int answer,go,x,y; for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) board[i][j]=0; board[setX][setY] += 1; x = setX; y = setY; do { go = rand() % 8; switch(go) { case 0 : x--; y++; if(x == -1) x += 2; if(y == 5) y -= 2; break; case 1 : y++; if(y == 5) y -= 2; break; case 2 : x++; y++; if(x == 5) x -= 2; if(y == 5) y -= 2; case 3 : x--; if(x == -1) x += 2; break; case 4 : x++; if(x == 5) x -= 2; break; case 5 : x--; y--; if(x == -1) x += 2; if(y == -1) y += 2; break; case 6 : y--; if(y == -1) y += 2; break; case 7 : x++; y--; if(x == 5) x -= 2; if(y == -1) y += 2; } board[y][x] += 1; answer = end(board); }while(answer == 1); output(board); } int end(int aBoard[][5]) { int find = 0; find = 0; int aAnswer; for(int m = 0 ; m < 5 ; m++) for(int n = 0 ; n < 5 ;n++) if (aBoard[m][n] == 0) find++; //0이 있으면 카운트 if (find != 0) aAnswer = 1; //0이 있으면 1 리턴 else aAnswer = 0; return aAnswer; } void output(int aBoard[][5]) { for(int s = 0 ; s < 5 ; s++) { for(int t = 0 ; t < 5 ;t++) { cout << aBoard[s][t] << "\t"; } cout << endl; } cout << endl; }