Unnamed Fossil Project

Check-in [58704e8a71]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixed a problem with a string getting stored in the width instead of a float bad dimensions in reset fail earlier
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:58704e8a716dd0249059d190cba2adf87938fb3d
User & Date: Derek 2013-02-27 22:25:04
Context
2013-02-27
22:25
fixed a problem with a string getting stored in the width instead of a float bad dimensions in reset fail earlier Leaf check-in: 58704e8a71 user: Derek tags: trunk
21:36
added resetting playmode to reset function check-in: e97605d164 user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


39
40
41
42
43
44
45
..
50
51
52
53
54
55
56

57
58
59
60
61
62
63
..
78
79
80
81
82
83
84

85
86
87
88
89
90
91
...
117
118
119
120
121
122
123
124

125
126

127
128
129
130
131
132
133
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226




227
228
229
230
231
232
233
savetime=10000,
helpmsg="Help Message goes here.";

//pos or neg encodes maze in lines, depending on which is shorter.
//goes through and encodes all lines at least a certain length, then repeats with half that length
//till all points are encoded without unnecessary redundancy.
function encodelines(o){
var w=o.w,h=o.h,s=o.start,e=o.end,arr=o.arr.slice(0),i=0,j,k,v,min,l=w*h,r=[],//retval
lines=[[[],[]],[[],[]]];//pos,neg*horiz,vert
arr[s[0]+w*s[1]]=0;//assure start empty
for(v=0;v<2;++v){//pos,neg
for(min=(w+h)/4;min>0;min/=2){//min line length
for(i=0;i<l;++i){if(arr[i]==2)continue;j=i;k=i;
while((i==j||j%w)&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j+1;++j;}//2 means already encoded
if(k-i>=min){lines[v][0].push([i,k-i]);for(j=i;j<k;++j)arr[j]=2;continue;}
j=i;k=i;
while(j<l&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j+w;j+=w;}


if((k-i)/w>=min){lines[v][1].push([i,(k-i)/w]);for(j=i;j<k;j+=w)arr[j]=2;}}}
for(j=0;j<l;++j)if(arr[j]==2)arr[j]=v;}//reset 2s
i=0;
r[i++]=w;r[i++]=h;
r[i++]=2;r[i++]=s[0];r[i++]=s[1];
r[i++]=2;r[i++]=e[0];r[i++]=e[1];
r[i++]=0;
................................................................................
function _sort(s,t){return s[0]-t[0];}
a.sort(_sort);b.sort(_sort);
for(j=0;j<a.length;++j){
k=a[j][0];r[i++]=k-lastk;r[i++]=a[j][1];lastk=k;}
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}

return r;}

function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
................................................................................
//lower half of charset has built in delimiter
function e64(arr){
var i,j,s="",x,a=[];
for(i=0;i<arr.length;++i){
x=arr[i];a.length=0;while(x>0){a.push(x%32);x=Math.floor(x/32);}
if(!a.length)a.push(0);
for(j=a.length-1;j>0;--j)s+=ch64[a[j]+32];

s+=ch64[a[0]];}
return s;}

function d64(str){
var i,x,y=0,a=[],arr=[];
for(i=0;i<str.length;++i){
x=ch64rev[str[i]];if(x===undefined)break;y=32*y+x-32;
................................................................................
if(!localStorage.saved){return 0;}
var o=JSON.parse(localStorage.mazestate);
x=o.x;y=o.y;width=o.w;height=o.h;arr=o.arr;startx=o.startx;starty=o.starty;goalx=o.goalx;goaly=o.goaly;dx=0;dy=0;
pxsize=Math.max(Math.floor(maxpxdimsum/(width+height)),1);
return 1;}

function reset(w,h){
if(w&&h)width=w,height=h;

if(w+h>maxdimsum)return 0;
w=width,h=height;

pxsize=Math.max(Math.floor(maxpxdimsum/(w+h)),1);
goalx=w-1,goaly=h-1,startx=0,starty=0,
arr=new Array(w*h);
for(var i=0;i<w*h;++i)arr[i]=0;
x=0.5,y=0.5,dx=0,dy=0;
testonly=false;
if(playmode)playmode();
................................................................................
crElem("br",menudiv);return b;}

var eb,zi,zo;//undo;//editbutton,zoomin,zoomout
playmode=function(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
editmode=function(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}

function file(){
if(confirm("\nExport maze?\n"))prompt("\nMaze Data\nCopy this:\n",_export());
else if(confirm("\nImport maze?\n"))_import(prompt("\nPaste Maze Data here:\n"));
else if(confirm("\nReset maze?\n")){
var dim=/([0-9]*)[^0-9]*([0-9]*)/.exec(prompt("\nEnter new dimensions\n(Current maze will be cleared):\n"));
reset(dim[1],dim[2]);}}

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",file);
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});




_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";
}








|









>
>







 







>







 







>







 







|
>

<
>







 







|
<
<
<
<



<

>
>
>
>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
...
215
216
217
218
219
220
221
222




223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
savetime=10000,
helpmsg="Help Message goes here.";

//pos or neg encodes maze in lines, depending on which is shorter.
//goes through and encodes all lines at least a certain length, then repeats with half that length
//till all points are encoded without unnecessary redundancy.
function encodelines(o){
var w=parseInt(o.w),h=parseInt(o.h),s=o.start,e=o.end,arr=o.arr.slice(0),i=0,j,k,v,min,l=w*h,r=[],//retval
lines=[[[],[]],[[],[]]];//pos,neg*horiz,vert
arr[s[0]+w*s[1]]=0;//assure start empty
for(v=0;v<2;++v){//pos,neg
for(min=(w+h)/4;min>0;min/=2){//min line length
for(i=0;i<l;++i){if(arr[i]==2)continue;j=i;k=i;
while((i==j||j%w)&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j+1;++j;}//2 means already encoded
if(k-i>=min){lines[v][0].push([i,k-i]);for(j=i;j<k;++j)arr[j]=2;continue;}
j=i;k=i;
while(j<l&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j+w;j+=w;}
if((k-i)%w!=0)alert("encode lines error: "+JSON.stringify({k:k,i:i,w:w}))
if(w!=Math.floor(w))alert("encode lines error: "+JSON.stringify({k:k,i:i,w:w}));
if((k-i)/w>=min){lines[v][1].push([i,(k-i)/w]);for(j=i;j<k;j+=w)arr[j]=2;}}}
for(j=0;j<l;++j)if(arr[j]==2)arr[j]=v;}//reset 2s
i=0;
r[i++]=w;r[i++]=h;
r[i++]=2;r[i++]=s[0];r[i++]=s[1];
r[i++]=2;r[i++]=e[0];r[i++]=e[1];
r[i++]=0;
................................................................................
function _sort(s,t){return s[0]-t[0];}
a.sort(_sort);b.sort(_sort);
for(j=0;j<a.length;++j){
k=a[j][0];r[i++]=k-lastk;r[i++]=a[j][1];lastk=k;}
lastk=lastk-l;k=0;
for(j=0;j<b.length;++j){
k=b[j][0];r[i++]=k-lastk;r[i++]=b[j][1];lastk=k;}
//alert(JSON.stringify(r));
return r;}

function decodelines(r){
var w,h,s=[],e=[],arr=[],i=0,j,c,lines=[];
w=r[i++];h=r[i++];l=w*h;for(j=0;j<l;++j)arr[j]=0;
c=r[i++];for(j=0;j<c;++j)s.push(r[i++]);//start
c=r[i++];for(j=0;j<c;++j)e.push(r[i++]);//end
................................................................................
//lower half of charset has built in delimiter
function e64(arr){
var i,j,s="",x,a=[];
for(i=0;i<arr.length;++i){
x=arr[i];a.length=0;while(x>0){a.push(x%32);x=Math.floor(x/32);}
if(!a.length)a.push(0);
for(j=a.length-1;j>0;--j)s+=ch64[a[j]+32];
if(ch64[a[0]]===undefined)alert("encode error\na:"+a.join(',')+"\narr.slice(i): " + arr.slice(i).join(','));
s+=ch64[a[0]];}
return s;}

function d64(str){
var i,x,y=0,a=[],arr=[];
for(i=0;i<str.length;++i){
x=ch64rev[str[i]];if(x===undefined)break;y=32*y+x-32;
................................................................................
if(!localStorage.saved){return 0;}
var o=JSON.parse(localStorage.mazestate);
x=o.x;y=o.y;width=o.w;height=o.h;arr=o.arr;startx=o.startx;starty=o.starty;goalx=o.goalx;goaly=o.goaly;dx=0;dy=0;
pxsize=Math.max(Math.floor(maxpxdimsum/(width+height)),1);
return 1;}

function reset(w,h){
if(!w||!h)return;
w=parseInt(w);h=parseInt(h);
if(w+h>maxdimsum)return 0;

width=w,height=h;
pxsize=Math.max(Math.floor(maxpxdimsum/(w+h)),1);
goalx=w-1,goaly=h-1,startx=0,starty=0,
arr=new Array(w*h);
for(var i=0;i<w*h;++i)arr[i]=0;
x=0.5,y=0.5,dx=0,dy=0;
testonly=false;
if(playmode)playmode();
................................................................................
crElem("br",menudiv);return b;}

var eb,zi,zo;//undo;//editbutton,zoomin,zoomout
playmode=function(){edit=false,eb.value="Edit";eb.style.backgroundColor="#fb6";pcolor=testonly?"#fe4":"#2b2";}
editmode=function(){edit=true,eb.value="Test";eb.style.backgroundColor="#fea";pcolor="#f82";victory=false;}

function file(){
_import(prompt("\nImport/Export Maze Data:",_export()));}





var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});

eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Share","#cbf",file);
_("Reset","#faa",function(){
var dim=/([0-9]*)[^0-9]*([0-9]*)/.exec(prompt("\nEnter  New  Dimensions:\n"));
reset(dim[1],dim[2]);});
_("Help","#acf",function(){alert(helpmsg);});
zi=_("+",0,function(){screenblocks*=0.8;});
zo=_("-",0,function(){screenblocks/=0.8;});
//undo=_("<",0,function(){alert('undo stuff goes here.');}
zi.className+=" bigtxt";zo.className+=" bigtxt";//undo.className+=" bigtxt";
}