Unnamed Fossil Project

Check-in [bd7e1086e7]
Login

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

Overview
Comment:decode written and tested.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:bd7e1086e72c6527b80dc82a93858ab5bd0afb1c
User & Date: Derek 2013-02-27 16:46:16
Context
2013-02-27
17:51
e64 and d64 for encoding and decoding base64 check-in: 89d84d5d86 user: Derek tags: trunk
16:46
decode written and tested. check-in: bd7e1086e7 user: Derek tags: trunk
02:16
i think i finally got everything in the encoding working. check-in: 66d925fa2f user: Derek tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to maze.html.

26
27
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
61
62

63



64
65














66
67
68
69
70
71
72
73
74
75
76
77
78
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//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){
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++]=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){
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(r.join(","));
return r;}

//alert()

setTimeout(function(){alert('here');encodelines({w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr});}, 1000);




function decodelines(str){














}

function encodearrayhex(arr){
}

function decodearrayhex(hexstr){
}


function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
................................................................................
if(!edit&&!victory&&Math.floor(x)==goalx&&Math.floor(y)==goaly){victory=true;alert(testonly?"Maze End.":"You Won");keys=[];}
draw();}

function convert(scrx,scry){ //convert screen coordinates
var cw=canvas.width,ch=canvas.height,cs=Math.min(cw,ch),sb=screenblocks,f=sb/cs;
return [x+f*(scrx-cw*0.5),y+f*(scry-ch*0.5)];}

function crElem(tag,parent,csscls,id){ //dom convenience function
var e=document.createElement(tag);
if(parent) parent.appendChild(e);
if(csscls) e.className=csscls;
if(id) e.id=id;
return e;}

function getElem(id){return document.getElementById(id);}

// make user menus







|









|
|

<






<





<



>
|
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

|


|







 







|

|







26
27
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//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;

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

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

//alert()
setTimeout(function(){
var q=encodelines({w:width,h:height,start:[startx,starty],end:[goalx,goaly],arr:arr});
alert(q.join(','));
alert(JSON.stringify(decodelines(q)));
}, 1000);

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
c=r[i++];i+=c;//ignore destinations
alert(r.slice(i).join(','));
while(i<r.length)lines.push(r[i++]);
var d=1,a=0,b;
for(i=0;i<lines.length;i+=2){
a+=lines[i];b=lines[i+1];
if(a>l)if(d==1)a-=l,d=w;else break;
for(j=0;j<b;++j)arr[a+d*j]=1;}
if(arr[s[0]+s[1]*w])for(j=0;j<l;++j)arr[j]=arr[j]?0:1;//negate, start must be empty
return{w:w,h:h,start:s,end:e,arr:arr};}


function e64(arr){
}

function d64(str){
}


function save(){
localStorage.saved=false;
localStorage.mazestate=JSON.stringify(
{x:x,y:y,w:width,h:height,startx:startx,starty:starty,goalx:goalx,goaly:goaly,arr:arr});
................................................................................
if(!edit&&!victory&&Math.floor(x)==goalx&&Math.floor(y)==goaly){victory=true;alert(testonly?"Maze End.":"You Won");keys=[];}
draw();}

function convert(scrx,scry){ //convert screen coordinates
var cw=canvas.width,ch=canvas.height,cs=Math.min(cw,ch),sb=screenblocks,f=sb/cs;
return [x+f*(scrx-cw*0.5),y+f*(scry-ch*0.5)];}

function crElem(tag,parnt,csscls,id){ //dom convenience function
var e=document.createElement(tag);
if(parnt) parnt.appendChild(e);
if(csscls) e.className=csscls;
if(id) e.id=id;
return e;}

function getElem(id){return document.getElementById(id);}

// make user menus