00:00
00:00
Newgrounds Background Image Theme

JustAndrew just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss: Empty Board Solver

2,008 Views | 13 Replies
New Topic Respond to this Topic

Foss: Empty Board Solver 2005-07-27 09:37:12


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);

Response to Foss: Empty Board Solver 2005-07-27 09:51:29


Response to Foss: Empty Board Solver 2005-07-27 10:27:59


At 7/27/05 09:37 AM, Inglor wrote: This is a simple solver I've made for liam's game, naturally , it doesn't work.

Ha ha ha..

If you can get this to work then I'll salute you as a king. Lol.


Sup, bitches :)

BBS Signature

Response to Foss: Empty Board Solver 2005-07-27 12:09:37


Well, one problem that might clear up some errors is having the correct number of '}'s.

function fuckLiam(a:Array, path:Array, lx, ly) { //1st one
path.push("("+lx+"/"+ly+")");
trace(path.length<_global.currentSolution)
;
if ((!solved(a)) && (path.length<_global.currentSolution)) { //2nd one
trace("w00p");
for (i=0; i<_global.size; i++) { // 3rd one
for (j=0; j<_global.size; j++) { // 4th one
b = copyBoard(a);
action(b, i, j);
printBoard(b);
fuckLiam(b, path, i, j);
} // Crosses out the 4th one
} // Crosses out the 3rd one
} // Crosses out the scond one
} // *New* Crosses out the fuckLiam function

Response to Foss: Empty Board Solver 2005-07-27 12:10:43


Nvm, it looks like you've covered that. I should have finishedproofreading the whole thing...

Response to Foss: Empty Board Solver 2005-07-27 13:24:37


Ok, I can solve your looping problems, but I still haven't got it to do what you want it to do.

First problem: the copyBoard function is missing a return statement. Adding this will take care of you looping problem.

Second problem: the printBoard function uses the statement:
trace("[" + board[i] + "]" + (i + 1));
it should read:
trace("[" + a[i] + "]" + (i + 1));
otherwise it will always output 0's.

Third problem: you used _global.size. 'size' is a reserved word in Flash. While it won't effect this program much, it is still bad coding practice.

These changes, specifically the copyBoard, will make your computer happily give up after 256 iterations. So you may need to find a more efficient way to do this.

Good luck and best wishes.

Response to Foss: Empty Board Solver 2005-07-28 08:09:03


At 7/27/05 10:27 AM, -liam- wrote:
At 7/27/05 09:37 AM, Inglor wrote: This is a simple solver I've made for liam's game, naturally , it doesn't work.
Ha ha ha..

If you can get this to work then I'll salute you as a king. Lol.

Thats a sucky way of doing it you can just do it with hitTests and stuff and a few loops

http://img135.images..age=untitled36dd.swf


- Matt, Rustyarcade.com

Response to Foss: Empty Board Solver 2005-07-28 10:32:32


At 7/28/05 08:09 AM, Ninja-Chicken wrote: Thats a sucky way of doing it you can just do it with hitTests and stuff and a few loops

http://img135.images..age=untitled36dd.swf

You have no idea what he was doing do you..

Inglor is trying to make something that finds the solution to my lights out game.


Sup, bitches :)

BBS Signature

Response to Foss: Empty Board Solver 2005-07-28 11:09:03


At 7/28/05 10:32 AM, -liam- wrote:
At 7/28/05 08:09 AM, Ninja-Chicken wrote: Thats a sucky way of doing it you can just do it with hitTests and stuff and a few loops

http://img135.images..age=untitled36dd.swf


You have no idea what he was doing do you..

Inglor is trying to make something that finds the solution to my lights out game.

Well shut me up. Sorry about that yes now I get it
That is actualy good
Hmmmm this foot tastes funny


- Matt, Rustyarcade.com

Response to Foss: Empty Board Solver 2005-07-28 11:14:29


it only takes 5 one the first one and 4 on the second. the game(referring to ninja chickens because i havent played liams)

Response to Foss: Empty Board Solver 2005-07-28 11:15:35


wow i totally screwed up that post..... i cant even read it. D:

Response to Foss: Empty Board Solver 2005-07-28 11:17:45


http://www.putfile.c..ia.php?n=LightsOut79

Thats 'my version' (the original), three levels in that.. it's only a demo by the way.


Sup, bitches :)

BBS Signature

Response to Foss: Empty Board Solver 2005-07-28 11:19:36


I just solved them all, me and delta figured out an algorithem, give us an hour :P

Response to Foss: Empty Board Solver 2005-10-28 21:58:44


I could make the game, but im not sure how to make a single code to do the hole thing


2b r not2b lawl

BBS Signature