This is a simple solver I've made for liam's game, naturally , it doesn't work.
Please someone go over the code and try to mod it to work or at least tell my my problam ;)
Mods and changes are more then welcome the problematic function is fuckLiam, it exits itself too soon, please help :)
The rules of liam's game:
you get a board the size of N*N all set to dark, when you click on something, it flips it and any of it's neighbors (excluding diagonals) to lightt from dark or from dark to light and your goal is to set anything to dark.
//yay! n^5 runtime! :P
var board = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
_global.size = 4;
_global.currentSolution = 1000000;
_global.currentSol = new Array();
function solved(a:Array) {
for (i=0; i<_global.size; i++) {
for (j=0; j<_global.size; j++) {
if (a[i][j] == 0) {
return false;
}
}
}
return true;
}
function printBoard(a:Array) {
for (i=0; i<_global.size; i++) {
trace("["+board[i]+"] : "+(i+1));
}
}
function action(a:Array, x:Number, y:Number) {
y--;
x--;
a[x][y] = Number(!a[x][y]);
a[x+1][y] = Number(!a[x+1][y]);
a[x-1][y] = Number(!a[x-1][y]);
a[x][y-1] = Number(!a[x][y-1]);
a[x][y+1] = Number(!a[x][y+1]);
}
function copyBoard(a:Array) {
b = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
for (i=0; i<_global.size; i++) {
for (j=0; j<_global.size; j++) {
b[i][j] = a[i][j];
}
}
}
function fuckLiam(a:Array, path:Array, lx, ly) {
path.push("("+lx+"/"+ly+")");
trace(path.length<_global.currentSolution)
;
if ((!solved(a)) && (path.length<_global.currentSolution)) {
trace("w00p");
for (i=0; i<_global.size; i++) {
for (j=0; j<_global.size; j++) {
b = copyBoard(a);
action(b, i, j);
printBoard(b);
fuckLiam(b, path, i, j);
}
}
} else {
if (path.length<_global.currentSolution) {
trace("Found New Solution:"+path);
_global.currentSolution = path.length;
_global.currentSol = path;
}
}
}
trace("Initializing... Board Initialized to: ");
printBoard(board);
fuckLiam(board, new Array(), -1, -1);
trace("OMGZORS the fastest way to haxxor liam is in "+_global.currentSolution+" moves");
trace("This way : "+_global.currentSol);