/* XLightOff solver * by Chupcko : * chupcko@galeb.etf.bg.ac.yu * http://alas.matf.bg.ac.yu/~chupcko/ */ #include "solve.h" #include #include "interface.h" static int copytab[5][5]; static int copymoves[5][5]; /* this function will choose between the current solution * and the one we just calculated and take the shortest * (in number of steps) */ void helpit(interface *it) { int s=0, t=0; int i; int *p = &it->sol[0][0]; for (i=0; i<25; i++) s += *p++; p = ©moves[0][0]; for (i=0; i<25; i++) t += *p++; if (t < s) memcpy(it->sol, copymoves, 25*sizeof(int)); } static void solve_action(interface *it, int x, int y) { copytab[x][y] ^= 1; copymoves[x][y] ^= 1; if (y>0) copytab[x][y-1] ^= 1; if (x>0) copytab[x-1][y] ^= 1; if (ysol, t, 25*sizeof(int)); } memcpy(copytab, it->tab, N*N*sizeof(int)); for (x=0; xtab, N*N*sizeof(int)); bzero(copymoves, N*N*sizeof(int)); for (y=0; y