U E D R , A S I H C RSS

Java Study2002/영동-2주차

  • .
  • .
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.. --

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:30
Processing time 0.0109 sec