varMine=function(){varb=0,f=1,a=2,d=3;functione(g,h){returnnewArray(h+1).join(g)}functionc(g){this.parse(g)}c.ALIVE=b;c.LOST=f;c.ABORTED=a;c.WON=d;c.prototype.parse=function(g){varo,k,h,n,j,m,p;this.orig_map=g;o=g.split(/\r\n?|\r?\n/);h=0;n=o.length;for(k=0;k<o.length;++k){if(0==o[k].length){n=k;o.splice(k,1);break}h=Math.max(h,o[k].length)}this.height=n;this.width=h;this.map=g=o.splice(0,n).reverse();this.lambdas=0;this.found_lambdas=0;this.moves=0;this.score=0;this.moves_below_water=0;this.water={level:0,flooding:0,proof:10};this.lift=this.robot=false;this.trampoline={sources:{},targets:{}};this.beard={growth:25,razors:0};g.splice(n,0,e("#",h));g.splice(0,0,e("#",h),e("#",h));n=n+3;h=h+2;for(k=0;k<n;++k){if(g[k].length<h-2){g[k]+=e(" ",h-g[k].length-2)}g[k]="#"+g[k]+"#";p=g[k]=g[k].split("");for(m=0;m<h;++m){switch(p[m]){case" ":case"*":case"#":case".":case"W":case"!":break;case"\\":this.lambdas++;break;case"L":if(this.lift!==false){throw"Only one lift is allowed"}this.lift={x:m,y:k};break;case"R":if(this.robot!==false){throw"Only one robot is allowed"}this.robot={x:m,y:k};break;default:if(p[m]>="A"&&p[m]<="I"){if(this.trampoline.sources[p[m]]){throw"Can have only one trampoline "+p[m]}this.trampoline.sources[p[m]]={x:m,y:k,target:false};this.trampoline.fromSources}else{if(p[m]>="1"&&p[m]<="9"){if(this.trampoline.targets[p[m]]){throw"Can have only one trampoline target "+p[m]}this.trampoline.targets[p[m]]={x:m,y:k,sources:[]}}else{throw"Invalid character in map: '"+p[m]+"'"+m}}break}}}if(this.robot===false){throw"Need a robot"}this.meta={};for(k=0;k<o.length;++k){if(0==o[k].length){continue}varl=o[k].split(/ +/);switch(l[0]){case"Water":this.water.level=parseInt(l[1]);break;case"Flooding":this.water.flooding=parseInt(l[1]);break;case"Waterproof":this.water.proof=parseInt(l[1]);break;case"Trampoline":if(l.length!==4||l[2]!=="targets"){throw"Invalid trampoline: '"+l.join(" ")+"'"}if(l[1].length!=1||l[1]<"A"||l[1]>"I"){throw"Invalid trampoline source '"+l[1]+"'"}if(l[3].length!=1||l[3]<"1"||l[3]>"9"){throw"Invalid trampoline target '"+l[3]+"'"}if(!this.trampoline.sources[l[1]]){throw"Trampoline "+l[1]+" not defined"}if(!this.trampoline.targets[l[3]]){throw"Trampoline target "+l[3]+" not defined"}if(this.trampoline.sources[l[1]].target){throw"Trampoline "+l[1]+" already has a target"}this.trampoline.sources[l[1]].target=l[3];this.trampoline.targets[l[3]].sources.push(l[1]);break;case"Growth":this.beard.growth=parseInt(l[1]);break;case"Razors":this.beard.razors=parseInt(l[1]);break;default:this.meta[l[0]]=l.splice(1).join(" ");break}}for(kinthis.trampoline.sources){if(this.trampoline.sources.hasOwnProperty(k)){if(!this.trampoline.sources[k].target){throw"Trampoline "+k+" has no target"}}}for(kinthis.trampoline.targets){if(this.trampoline.targets.hasOwnProperty(k)){if(0==this.trampoline.targets[k].sources.length){throw"Trampoline target "+k+" has no sources"}}}this.water_level=this.water.level;this.razors=this.beard.razors;this.beard_growth=this.beard.growth;this.state=b};c.prototype.get=function(g,h){if(g<0||h<0||g>=this.width||h>=this.height){return"#"}returnthis.map[h][g]};c.prototype.validMove=function(g){if(this.state!=b){returnfalse}vari,h;g=g.toUpperCase();switch(g){case"L":case"R":i=(g=="L"?-1:1);h=this.map[this.robot.y][this.robot.x+i];switch(h){case"#":returnfalse;case" ":case".":case"!":case"\\":returntrue;case"L":returnfalse;case"O":returntrue;case"*":if(" "==this.map[this.robot.y][this.robot.x+2*i]){returntrue}default:if(this.trampoline.sources.hasOwnProperty(h)){returntrue}break}break;case"U":case"D":i=(g=="D"?-1:1);h=this.map[this.robot.y+i][this.robot.x];switch(h){case"#":returnfalse;case" ":case".":case"!":case"\\":returntrue;case"L":returnfalse;case"O":returntrue;case"*":returnfalse;default:if(this.trampoline.sources.hasOwnProperty(h)){returntrue}break}break;case"W":case"S":returnthis.razors>0;case"A":returntrue}returnfalse};c.prototype.move=function(l){if(this.state!=b){returnfalse}vark,p,z,w;varg,r,q,o,m,u,h=this.map,v;l=l.toUpperCase();if(this.validMove(l)){switch(l.toUp