- 벽 부딪면 과 반대로 나는 것 라 그냥 그리 는 로 놨다.
- 따라 나 래 모든 리 고 래를 러개로 리다.
Class main--메
래
~cpp
import java.util.*;
public class main{
public static void main(String[] args)
{
//Board aboard=new Board();
Bug bug1=new Bug();
System.out.println("RandomWalk");
//aboard.board[0][0]++;
bug1.move();
}
}
Class Bug--
동
는 벌
~cpp
import java.util.*;
public class Bug{
public int x=0;
public int y=0;
public int way;
public int count=0;
public void move()
{
Board aboard=new Board();
aboard.board[0][0]++;
while(count<24)
{
Random rand=new Random();
way=rand.nextInt()%8;
if(way==0)//북
{
if(x>0)
{
x=x-1;
}
}
else if(way==1)//북동
{
if(x>0 && y<4)
{
x=x-1;
y=y+1;
}
}
else if(way==2)//동
{
if(y<4)
{
y=y+1;
}
}
else if(way==3)//남동
{
if(y<4 && x<4)
{
x=x+1;
y=y+1;
}
}
else if(way==4)//남
{
if(x<4)
{
x=x+1;
}
}
else if(way==5)//남
{
if(y>0 && x<4)
{
x=x+1;
y=y-1;
}
}
else if(way==6)//
{
if(y>0)
{
y=y-1;
}
}
else if(way==7)//북
{
if(y>0 && x>0)
{
x=x-1;
y=y-1;
}
}
if(aboard.board[x][y]==0)
{
count++;
}
aboard.board[x][y]++;
aboard.exhibit();
System.out.print("\n");
}
}
}
Class Board--벌
발
국
남는
. 발
국
바
벌
동
보고
다.
~cpp
import java.util.*;
public class Board{
public int board[][]={
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
};
public void exhibit(){
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++){
System.out.print(board[i][j]);
System.out.print("\t");
}
System.out.print("\n");
}
}
}
- 동 while 문 복 다. 만 고민보면 복 꺼...^^ --동
---> 빨리 배로 블(?) 만들 놓는 봐겠다. --동
- 데블 때 런 결는 나던 같데. LookUpTable라고.. --