Created
May 21, 2013 05:23
-
-
Save mutoo/5617638 to your computer and use it in GitHub Desktop.
a javascript program to solve the tacoyaki+ game - http://www.gamedesign.jp/flash/tacoyaki_p/tacoyaki_p.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var row,column; | |
row = column = 7; // setup the size of game | |
var map = [1,1,1,0,0,1,1]; // setup first column | |
for(i=row;i<row*column;i++) | |
map[i] = 0; // insure others tile are ZERO | |
display(map); | |
function tapByCoor(map,r,c){ | |
index = r*column+c; | |
reverse(map,index); | |
reverse(map,index+column); | |
reverse(map,index-column); | |
if(c<column-1) | |
reverse(map,index+1); | |
if(c>0) | |
reverse(map,index-1); | |
} | |
function tapByIndex(map, index) { | |
if(index<0||index>column*row-1) | |
return; | |
tapByCoor(map, Math.floor(index/column), index%column); | |
} | |
function reverse(map, index) { | |
if(index<0||index>row*column-1) | |
return; | |
map[index] = 1- map[index]; | |
} | |
function display(map) { | |
for(var r=0; r<row; r++) | |
document.writeln(map.slice(r*column, (r+1)*column)+"<br/>"); | |
} | |
for(var i=1;i<Math.pow(2,column)-1;i++){ | |
map_clone = map.slice(); | |
taps = i.toString(2).split("").reverse(); | |
for(index in taps){ | |
if(taps[index]==1) | |
tapByIndex(map_clone, index); | |
} | |
solved = false; | |
for(var r=1;r<row;r++){ | |
for(var c=0;c<column;c++){ | |
if(map_clone[(r-1)*column+c]==1) | |
tapByCoor(map_clone,r,c); | |
} | |
} | |
if(!Number(map_clone.slice((row-1)*column,row*column).join(""))) | |
solved = true; | |
if(solved) | |
alert(taps); // shows the answer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment