public void diTuan() { int nd = 2; int size = N * N; while (nd <= size) { List <ToaDo> ncMoi = sinhNuocDi(t); if (ncMoi.Count == 0 && nd <= size) { Console.WriteLine("Khong thay loi giai"); break; } int min = 10; ToaDo t2 = new ToaDo(0, 0); for (int i = 0; i < ncMoi.Count; i++) { List <ToaDo> tmpdsNuocdi = sinhNuocDi(ncMoi[i]); if (tmpdsNuocdi.Count < min) { min = tmpdsNuocdi.Count; t2 = ncMoi[i]; } } t = t2; banCo[t.dong, t.cot] = nd; nd++; } if (nd >= size) { inBanCo(); } }
public maDiTuan(int n, int yy, int xx) //Constructor { banCo = new int[n, n]; N = n; t = new ToaDo(yy, xx); banCo[t.dong, t.cot] = 1; //banCo[y, x] = 1; }
public List <ToaDo> sinhNuocDi(ToaDo k) { int[] dy = { -2, -1, 1, 2, 2, 1, -1, -2 }; int[] dx = { 1, 2, 2, 1, -1, -2, -2, -1 }; List <ToaDo> dsNuocdi = new List <ToaDo>(); for (int i = 0; i < 8; i++) { int ty = k.dong + dy[i]; int tx = k.cot + dx[i]; if (tx >= 0 && ty >= 0 && tx < N && ty < N && banCo[ty, tx] == 0) { dsNuocdi.Add(new ToaDo(ty, tx)); } } return(dsNuocdi); }