I tried to use backtracking for Knight’s tour but it is taking too long

Here is the entire structure of the program ,it is written in java
Main class -stats the program by calling Knight

   public class Main {
   public static void main(String[] args) {
   Knight knight=new Knight( 33,6);
   knight.controller(false);
  // knight.possiblemoves();

}

}

Then knight class controls knight moves and initiates other method and classes

import java.util.ArrayList;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Set;

public class Knight {
Board boarde;
static ArrayList<Integer> possiblity;
static ArrayList<Integer> boarder;
public static int MaxCOl;
public static int MaxRow;
static int position;
int h;
guiframe frame;
backtracklogic logic;
int fposition;
Knight(int fposition, int size) {
    MaxCOl = MaxRow = size;
    this.fposition = fposition;
    logic = new backtracklogic(fposition);
    frame = new guiframe(MaxCOl, fposition);
    boarde = new Board(MaxCOl, MaxRow);

    boarder = new ArrayList<>();

    for (int i = 0; i < MaxCOl; i++) {
        for (int j = 0; j < MaxRow; j++) {
            boarder.add(Board.board[i][j]);

        }
    }

    possiblity = new ArrayList<>();
    Knight.position = fposition;
    // Board.used.add(fposition);
    knightmove(fposition);
}

public void knightmove(int tomove) {
    position = tomove;
    Board.used.add(tomove);
    frame.knightposition(tomove);

}

public void controller(Boolean random) {
    boolean n = true;
    if (random) {
        while (n) {
            for (int a = 0; a < MaxCOl * MaxCOl; a++) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
                possiblemoves(position, Board.used);
                if (possiblity.size() < 1)
                    break;
                knightmove(randommove());
                h = a;
                if (h >= MaxCOl * MaxCOl) {
                    n = false;
                }

            }

        }

    } else if (!random)

    {
        ArrayList<Integer> used = new ArrayList<>();
        used.add(fposition);

        long startTime = new Date().getTime();

        logic.move(fposition, new ArrayList<>(used), new ArrayList<Integer>(), 1);
        knightmover(logic.toplay);
        long endTime = new Date().getTime();
        long executionTime = endTime - startTime;
        System.out.println("Execution time: " + executionTime + " milliseconds");
    }
}

public void knightmover(ArrayList<Integer> list) {
    for (int i : list)

    {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
        knightmove(i);
        System.out.println(i + " " + list.indexOf(i));
    }
    System.out.println(list);
}

public static ArrayList<Integer> possiblemoves(int pos, ArrayList<Integer> used) {
    possiblity.clear();
    int x[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
    int y[] = { 1, 2, 2, 1, -1, -2, -2, -1 };

    for (int j = 0, k = 0; j < x.length || k < y.length; j++, k++) {
        int a = x[j];
        int d = y[k];
        if (check(pos + (a * 10) + d) == 1 && !used.contains(pos + (a * 10) + d))
            possiblity.add(pos + (a * 10) + d);
    }

    // remove duplicate fix it in the future if possible
    Set<Integer> p = new LinkedHashSet<>(possiblity);

    possiblity.addAll(p);

    return possiblity;

}

public static int check(int a) {
    if (boarder.contains(a)) {
        return 1;
    } else
        return 0;
}

public int randommove() {
    Random random = new Random();
    int a = random.nextInt(possiblity.size());

    return possiblity.get(a);
}

}

then the backtract logic class

import java.util.ArrayList;

public class backtracklogic {

ArrayList<Integer> toplay;

backtracklogic(int fposition) {

    toplay = new ArrayList<>();

}

public void move(int position, ArrayList<Integer> used, ArrayList<Integer> movetoplay, int depth) {
    if (depth == Knight.MaxCOl * Knight.MaxCOl) {
        toplay = movetoplay;
        return;
    }
    // System.out.println(depth);
    int move;

    ArrayList<Integer> possible = new ArrayList<>(Knight.possiblemoves(position, used));

    if (possible.size() <= 0 && depth != Knight.MaxCOl * Knight.MaxCOl) {

        return;
    } else if (depth == Knight.MaxCOl * Knight.MaxCOl) {

        return;
    }
    for (int i = 0; i < possible.size(); i++) {

        move = possible.get(i);
        used.add(move);

        movetoplay.add(move);

        move(move, new ArrayList<>(used), new ArrayList<>(movetoplay), depth + 1);

        movetoplay.removeLast();
        used.removeLast();

    }

}

 }

then the class which creates the board

import java.util.ArrayList;

public class Board {
public static int Max_row;
public static int Max_col;
public static int[][] board;
static ArrayList<Integer> used;
Board(int maxcol,int maxrow){
    Max_col=maxcol;
    Max_row=maxrow;
    board=new int[Max_row][Max_col];
    used=new ArrayList<>();

    for(int y =1;y<=Max_row;y++){
        int f=1;
        for(int x=Max_col;x>0;x--)
        {
            board[x-1][y-1]=y*10+f;
            f++;
        }
    
    }

for(int i = 0;i<Max_col;i++)
{
    for (int j = 0; j < Max_col; j++) {
        System.out.print(board[i][j] + " ");

    }
    System.out.println();



}

}}

Sorry i am new to programming and i just cant find a solution to this upto 5 X5 it takes 4 sec after that it just doesnt give a solution

i tried to change the way i intitiate the board from a4 ,a5 notation to standard cordinat sstem 11 12 but it didnt do any good

New contributor

Sourav Tripathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật