Arrow keys to move a number of spaces equal to the adjacent number in that direction. You can't cross your path. Try to clear the board.
b.style='display:table;margin:1em auto;background:#000;color:#fff;font:16px monospace';R=(z)=>~~(Math.random(L=localStorage)*z)+1;Z=[];X=80;Y=22;W=T=U=100/(X*Y);A=(x,y)=>{for(x=X;x--;){Z[x]=[];for(y=Y;y--;)Z[x][y]=R(9)}W={x:R(X)-1,y:R(Y)-1};Z[W.x][W.y]=0};C=(z)=>'xa5aa86aa8af'.substr(z,3);B=(z,y)=>'<n style="color:#'+C(y)+'">'+z+'</n>';D=(h)=>{h='';for(y=Y;y--;){for(x=X;x--;)h+=x==W.x&&y==W.y?B('@',X):B(Z[x][y]||' ',Z[x][y]);h+='<br/>'}b.innerHTML=h+((T/U)|0)+'/'+(X*Y)+' '+T.toFixed(4)+'%'};M=(x,y,z,u,v,r)=>{if(W.x-x<0||W.y-y<0||W.x-x>=X||W.y-y>=Y)return 0;r=z=Z[W.x-x][W.y-y];u=W.x+0;v=W.y+0;while(z--)if(u-x<0||v-y<0||u-x>=X||v-y>=Y||!Z[u-=x][v-=y])return 0;return r};d.onkeydown=(e,k,x,y,z)=>{k=e.which;if(k<37||k>40)return 0;e.preventDefault();x=k%2*(k-38);y=(1-k%2)*(k-39);if(k=z=M(x,y))while(z--)Z[W.x-=x][W.y-=y]=0;D(T+=U*k);if(!(M(0,-1)|M(0,1)|M(1,0)|M(-1,0))){if(!(k=L.getItem(0)|0)||k<=T){L.setItem(0,T);b.innerHTML+=' HIGH SCORE';}b.innerHTML+='<n style="float:right">GAME OVER</n>'}};D(A());
Yi5zdHlsZT0nZGlzcGxheTp0YWJsZTttYXJnaW46MWVtIGF1dG87YmFja2dyb3VuZDojMDAwO2NvbG9yOiNmZmY7Zm9udDoxNnB4IG1vbm9zcGFjZSc7Uj0oeik9Pn5+KE1hdGgucmFuZG9tKEw9bG9jYWxTdG9yYWdlKSp6KSsxO1o9W107WD04MDtZPTIyO1c9VD1VPTEwMC8oWCpZKTtBPSh4LHkp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CI+R0FNRSBPVkVSPC9uPid9fTtEKEEoKSk7
b.style='display:table;margin:1em auto;background:#000;color:#fff;font:16px monospace'; // dat style
R=(z)=>~~(Math.random(L=localStorage)*z)+1; // Random number from 1 to z
Z=[]; // field of numbers
X=80; // columns
Y=22; // rows
W=T=U=100/(X*Y); // W will be player, T is score and U is score per number (start with 1 for starting position)
// Initialize
A=( x,y)=>{
for(x=X;x--;) { // fill board
Z[x]=[];
for(y=Y;y--;)
Z[x][y]=R(9)
}
W={ x:R(X)-1, y:R(Y)-1 }; // pick player location
Z[W.x][W.y]=0; // clear spot under player
};
C=(z)=>'xa5aa86aa8af'.substr(z,3); // color by number (sliced by number)
B=(z,y)=>'<n style="color:#'+C(y)+'">'+z+'</n>'; // create element for number styling
// Draw board and score
D=(h)=>{
h='';
for(y=Y;y--;){
for(x=X;x--;)
h += x==W.x&&y==W.y
? B('@',X) // default is white, so this invalid color (#) becomes white
: B( Z[x][y] || ' ', Z[x][y] ); // color 0 (#xa5) doesn't matter since we're drawing a space
h+='<br/>'
}
b.innerHTML = h + ((T/U)|0) + '/' + (X*Y) + ' ' + T.toFixed(4) + '%' // score
};
// Detect if a move by x,y is valid; return how far to move
M=(x,y , z,u,v,r)=>{
if(W.x-x<0||W.y-y<0||W.x-x>=X||W.y-y>=Y) return 0; // check inbounds
r=z=Z[W.x-x][W.y-y]; // r to return how far to move, z for the loop
u=W.x + 0;
v=W.y + 0;
while (z--)
if (u-x<0 || v-y<0 || u-x>=X || v-y>=Y || !Z[u-=x][v-=y]) return 0; // if we go off the board or cross a 0, cancel move
return r
};
d.onkeydown=(e , k,x,y,z)=>{
k=e.which;
if(k<37 || k>40) return 0; // only arrow keys
e.preventDefault(); // no page scrolling
x = k%2 * (k-38); // fancy math to get 1 for left and -1 for right
y = (1-k%2) * (k-39); // ^^ ^^ 1 for down and -1 for up
if(k=z=M(x,y)) // if the move is valid...
while(z--) // actually move
Z[W.x-=x][W.y-=y]=0;
D( T+=U*k ); // draw and update score
if (!(M(0,-1)|M(0,1)|M(1,0)|M(-1,0))) { // If no future move is valid, game over
if (!(k=L.getItem(0)|0)||k<=T) { // Check high score from localStorage
L.setItem(0,T);
b.innerHTML+=' HIGH SCORE';
}
b.innerHTML+='<n style="float:right">GAME OVER</n>'
}
};
D(A()); // let's go!