void permute(List <int> per, int n, int l, bool d, List <int> toadd, int x, int y, int z, int dir) { int temp; if (l != n) { for (int i = l; i < n; i++) { temp = per [l]; per [l] = per [i]; per [i] = temp; permute(per, n, l + 1, d, toadd, x, y, z, dir); permute(per, n, l + 1, false, toadd, x, y, z, dir); temp = per [l]; per [l] = per [i]; per [i] = temp; } } else { if (d) { List <int> tosearch = new List <int>(); if (dir == 1 || dir == 3) { tosearch = new List <int>(toadd); for (int i = 0; i < per.Count; i++) { if (per[i] < 2325 && per[i] >= 2310) { tosearch.Add(per[i] + 56); } else if (per[i] == 2309) { tosearch.Add(2381); } else { tosearch.Add(per[i]); } } } else if (dir == 2 || dir == 4) { tosearch = new List <int>(); for (int i = 0; i < per.Count; i++) { if (per[i] < 2325 && per[i] >= 2310) { tosearch.Add(per[i] + 56); } else if (per[i] == 2309) { tosearch.Add(2381); } else { tosearch.Add(per[i]); } } for (int i = 0; i < toadd.Count; i++) { tosearch.Add(toadd[i]); } } valid = Dictionary.Search(tosearch); for (int i = 1; i < tosearch.Count; i++) { if (tosearch[i - 1] >= 2366 && tosearch[i] < 2325) { valid = 0; } } if (valid == 1) { if (dir == 1 || dir == 2) { up = y; dn = y; if (dir == 1) { lt = x - toadd.Count; rt = x; for (int i = 1; i < per.Count; i++) { if (per[i] > 2324) { rt++; } } } else if (dir == 2) { rt = x + toadd.Count; lt = x; for (int i = 1; i < per.Count; i++) { if (per[i] > 2324) { lt--; } } } } else if (dir == 3 || dir == 4) { lt = x; rt = x; if (dir == 3) { up = y - toadd.Count; dn = y; for (int i = 1; i < per.Count; i++) { if (per[i] > 2324) { dn++; } } } else if (dir == 4) { dn = y + toadd.Count; up = y; for (int i = 1; i < per.Count; i++) { if (per[i] > 2324) { up--; } } } } int p = scorecal(per); if (dir == 1) { for (int i = 1; i <= z; i++) { p += Board.matrix[x - i, y] * Board.multiples[x - i, y]; } for (int i = 1; i <= z; i++) { p *= Board.powers[x - i, y]; } } else if (dir == 2) { for (int i = 1; i <= z; i++) { p += Board.matrix[x + i, y] * Board.multiples[x + i, y]; } for (int i = 1; i <= z; i++) { p *= Board.powers[x + i, y]; } } else if (dir == 3) { for (int i = 1; i <= z; i++) { p += Board.matrix[x, y - i] * Board.multiples[x, y - i]; } for (int i = 1; i <= z; i++) { p *= Board.powers[x, y - i]; } } else if (dir == 4) { for (int i = 1; i <= z; i++) { p += Board.matrix[x, y + i] * Board.multiples[x, y + i]; } for (int i = 1; i <= z; i++) { p *= Board.powers[x, y + i]; } } int s = p; double f = Penalty.penalty(lt, rt, up, dn); p -= (int)f; tosearch.Add(s); per.Add(s); tosearch.Add(p); per.Add(p); List <int> templist = new List <int>(); templist.Clear(); printlist(tosearch, tosearch.Count); for (int i = 0; i < per.Count; i++) { templist.Add(per[i]); } templist.Add(x); templist.Add(y); templist.Add(dir); //printlist(templist,templist.Count); if (!((dir == 1 || dir == 3) && per[0] < 2325)) { listlist.Add(templist); } } } } }