Unnamed Fossil Project

Check-in [d78910d918]
Login

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

Overview
Comment:fixed some boundary problems with the encode line function.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d78910d9182f91355eb3b6656a1c13498e0d02db
User & Date: Derek 2013-02-26 19:01:15
Context
2013-02-27
02:16
i think i finally got everything in the encoding working. check-in: 66d925fa2f user: Derek tags: trunk
2013-02-26
19:01
fixed some boundary problems with the encode line function. check-in: d78910d918 user: Derek tags: trunk
17:38
first version of encode lines seems to be working. check-in: 5f984ad9e3 user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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){
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;++j;}//2 means already encoded
if(k-i>=min){lines[v][0].push([i,k-i]);alert("horizontal: "+i+","+k);for(j=i;j<=k;++j)arr[j]=2;continue;}//k==i means length zero
j=i;k=i;
while(j<l&&(arr[j]==v||arr[j]==2)){if(arr[j]==v)k=j;j+=w;}
if((k-i)/w>=min){lines[v][1].push([i,k/w]);alert("vertical:"+i+","+k);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++]=1;r[i++]=s[0];r[i++]=s[1];
r[i++]=1;r[i++]=e[0];r[i++]=e[1];
r[i++]=0;
alert(JSON.stringify(lines));
var nl=lines[0][0].length+lines[0][1].length,pl=lines[1][0].length+lines[1][1].length;
lines=lines[nl<pl?0:1];//use shorter lineset
var a=lines[0],b=lines[1],lastk=0;
k=0;
function _sort(s,t){return s[0]-t[0];}
a.sort(_sort);b.sort(_sort);
alert(JSON.stringify({a:a,b:b}));
for(j=0;j<a.length;j+=2){
k=a[j];r[i++]=a[j];r[i++]=a[j+1];lastk=k;}
k=0;lastk=0;
for(j=0;j<b.length;j+=2){
k=b[j];r[i++]=(k-lastk)/w;r[i++]=b[j+1];lastk=k;}
return r;}

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

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",function(){});
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(20,20);});
_("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";
}








|
|

|
|













|







 







|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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){
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]);alert("horizontal: "+i+","+k);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]);alert("vertical: "+i+","+k);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++]=1;r[i++]=s[0];r[i++]=s[1];
r[i++]=1;r[i++]=e[0];r[i++]=e[1];
r[i++]=0;
alert(JSON.stringify(lines));
var nl=lines[0][0].length+lines[0][1].length,pl=lines[1][0].length+lines[1][1].length;
lines=lines[nl<pl?0:1];//use shorter lineset
var a=lines[0],b=lines[1],lastk=0;
k=0;
function _sort(s,t){return s[0]-t[0];}
a.sort(_sort);b.sort(_sort);
alert(JSON.stringify({"horizontal":a,"vertical":b}));
for(j=0;j<a.length;j+=2){
k=a[j];r[i++]=a[j];r[i++]=a[j+1];lastk=k;}
k=0;lastk=0;
for(j=0;j<b.length;j+=2){
k=b[j];r[i++]=(k-lastk)/w;r[i++]=b[j+1];lastk=k;}
return r;}

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

var _=addbutton;
_("Start","#cfc",function(){x=startx+0.5,y=starty+0.5;victory=false;testonly=false;playmode();});
_("File","#cbf",function(){});
eb=_("Edit","#fb6",function(){edit?playmode():(editmode(),testonly=true);});
_("Reset","#faa",function(){testonly=false;playmode();reset(5,5);});
_("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";
}