Results 1 to 2 of 2
  1. #1
    sasha20 is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Default PLEASE!!!help me to find mistake

    public class KnightsTour {
    Vars locs[];
    private int size, max=1, d=0, board[][];

    public KnightsTour(int x,int y, int newSize)
    {
    size=newSize;
    locs=new Vars[size*size+1];
    for(int n=1;n<=size*size;n++)
    {
    locs[n]=new Vars();
    }
    board=new int[size+1][size+1];
    for(int n=1;n<=size;n++)
    {
    for(int n2=1;n2<=size;n2++)
    {
    board[n][n2]=0;
    }
    }
    locs[max].x=x;
    locs[max].y=y;
    locs[max].d=1;
    board[x][y]=max;
    max++;
    }
    class Vars{
    int x;
    int y;
    int d;
    }
    public void GO()
    {
    int n=0;
    while(max<=size*size)
    {
    n++;
    d++;
    if(d>8)
    {
    max--;
    board[locs[max].x][locs[max].y]=0;
    d=locs[max].d+1;
    }
    move();
    }
    printBoard();
    }

    public void move()
    {
    int x=locs[max-1].x, y=locs[max-1].y;
    switch(d)
    {
    case 1:x--;y-=2;break;
    case 2:x++;y-=2;break;
    case 3:x+=2;y--;break;
    case 4:x+=2;y++;break;
    case 5:x++;y+=2;break;
    case 6:x--;y+=2;break;
    case 7:x-=2;y++;break;
    case 8:x-=2;y--;break;
    }
    //System.out.println(" X: "x" Y: "y" |"+max);
    if((x<1)||(x>size)||(y<1)||(y>size)){}
    else if(board[x][y]!=0){}
    else
    {
    locs[max].x=x;
    locs[max].y=y;
    locs[max].d=d;
    board[x][y]=max;
    max++;
    d=0;
    //printBoard();
    }
    }

    public void printBoard()
    {
    for(int n=1;n<=size;n++)
    {
    for(int n2=1;n2<=size;n2++)
    {
    if(board[n2][n]<10)
    System.out.print(board[n2][n]+" ");
    else
    System.out.print(board[n2][n]+" ");
    }
    System.out.println();
    }
    //System.out.println();
    System.out.println();
    }
    }
    public static void main (String[]args){
    KnightsTour k = new KnightsTour(1,1,8);
    }

  2. #2
    Sreejesh is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

Similar Threads

  1. how to find files in given directory
    By cecily in forum New To Java
    Replies: 7
    Last Post: 07-04-2014, 01:03 PM
  2. Where to find wsimport
    By javaplus in forum Web Frameworks
    Replies: 1
    Last Post: 11-26-2007, 10:59 AM
  3. Newbie can't spot his mistake :(
    By naxalyte in forum New To Java
    Replies: 4
    Last Post: 11-21-2007, 08:31 PM
  4. My JSP can't find the servlet
    By gabriel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-29-2007, 10:01 PM
  5. cannot find a JVM installed
    By tommy in forum New To Java
    Replies: 2
    Last Post: 07-29-2007, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •