/**
* Copyright 12346 ( http://wonderfl.net/user/12346 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/u5u0
*/
package{import flash.display.*;import flash.events.*;import flash.text.TextField;
[SWF(frameRate=180)]
public class Main extends Sprite{
public var A:Vector.<Vector.<int>>=new Vector.<Vector.<int>>(24)
public var B:Vector.<Vector.<o>>=new Vector.<Vector.<o>>(24)
public var C:Vector.<int>=new Vector.<int>
public var D:Vector.<int>=new Vector.<int>
public var k:int=0
public var a:int=4,i:int,j:int
public function Main(){
for(i=24;i--;)for(A[i]=new Vector.<int>(j=24),B[i]=new Vector.<o>(j);j--;)
addChild(B[i][j]=i&&i<23&&j&&j<23?new b(i,j):new o),A[i][j]=3
for(i=24;i--;)A[0][i]=A[23][i]=A[i][0]=A[i][23]=15
with((addChild(new Shape)as Shape).graphics){
lineStyle(0);moveTo(24,360);lineTo(24,24);lineTo(376,24)}
B[22][1].R(!1);A[22][1]=2;A[0][22]=6;A[23][1]=7
var t:TextField=new TextField;t.text="make";t.x=32;t.y=384
t.border=true;t.width=40;t.height=20;t.selectable=false;t.addEventListener("click",M)
addChild(t)
t=new TextField;t.text="solve";t.x=128;t.y=384
t.border=true;t.width=40;t.height=20;t.selectable=false;t.addEventListener("click",S)
addChild(t)
t=new TextField;t.text="walk";t.x=224;t.y=384
t.border=true;t.width=40;t.height=20;t.selectable=false;t.addEventListener("click",P)
addChild(t)
}
public function I():void{for(i=23;--i;)for(j=23;--j;)
A[i][j]=3,B[i][j].D(!0),B[i][j].R(!0),B[i][j].g.visible=B[i][j].p.visible=!1
B[22][1].R(!1);A[22][1]=2}
public function M(e:MouseEvent):void{if(a&4)a=1,I(),aE(m),A[i=1][j=22]=7}
public function S(e:MouseEvent):void{if(a==5)a=2,aE(s),i=j=1}
public function P(e:MouseEvent):void{if(a==6)a=3,aE(p),i=1,j=22}
public function m(e:Event):void{
var _:int=(Math.random()*4)|0,c:int=i,d:int=j;_&1?d+=_&2?1:-1:c+=_&2?1:-1
if(A[c][d]&4)return m(e)
A[c][d]|=4;C[k]=c;D[k]=d;
if(_&2)A[i][j]&=8-_;else A[i=c][j=d]&=6-_//_&2?A[i][j]=8-_:typeof(A[(i=c)][(j=d)]=6-_);
_&1?B[i][j].D(false):B[i][j].R(false)
while(4&A[1+(i=C[k])][j=D[k]]&A[i-1][j]&A[i][j-1]&A[i][j+1])if(k--<1){rE(m),a=5;A[22][1]&=6;break}k++
}
public function s(e:Event):void{var _:int=0
if(~A[i][j]&8){
_=(A[i][j]&2?1:A[i][j+1]&8?1:0)+(A[i][j]&1?1:A[i+1][j]&8?1:0)+
(A[i][j-1]&2?1:A[i][j-1]&8?1:0)+(A[i-1][j]&1?1:A[i-1][j]&8?1:0)
if(_>2)k=0,A[i][j]|=8,B[i][j].g.visible=true}
if(j++>21)j=1,i=i%22+1
if(k++>484){rE(s),a=6,k=0;return}
if(_<3)return s(e)
}
public function p(e:Event):void{var r:int=0,c:int=i,d:int=j
if(~A[i][j]&2&&~A[i][j+1]&8)d++,r=90;else
if(~A[i][j]&1&&~A[i+1][j]&8)c++,r=0;else
if(~A[i][j-1]&2&&~A[i][j-1]&8)d--,r=-90;else
if(~A[i-1][j]&1&&~A[i-1][j]&8)c--,r=180
A[i][j]|=8
B[i][j].p.visible=true;B[i][j].p.rotation=r
i=c;j=d
if(c==23&&d==1)rE(p),a=7
}
public function aE(f:Function):void{addEventListener("enterFrame",f)}
public function rE(f:Function):void{removeEventListener("enterFrame",f)}
}}
import flash.display.*;
class o extends Sprite{
public var d:Shape,r:Shape,g:Shape,p:Shape
function o(){}
public function D(v:Boolean):void{}
public function R(v:Boolean):void{}
}
class b extends o{
function b(X:int,Y:int){x=X*16+16;y=Y*16+16
addChild(g=new Shape).visible=false;addChild(d=new Shape);addChild(r=new Shape);addChild(p=new Shape).visible=false;
with(g.graphics){beginFill(0xcccccc);drawRect(-8,-8,16,16)}
with(d.graphics){lineStyle(0);moveTo(-8,8);lineTo(8,8)}
with(r.graphics){lineStyle(0);moveTo(8,-8);lineTo(8,8)}
with(p.graphics){lineStyle(0,0xff0000);lineTo(14,0);lineTo(11,3);moveTo(14,0);lineTo(11,-3)}
}
override public function D(v:Boolean):void{d.visible=v}
override public function R(v:Boolean):void{r.visible=v}
}