@a=0..63;g(o(\$_),a(\$_)?\$_<24?"w":\$_>39?"b":0:0)for@a;\$w=\$b=12;while(\$w&&\$b) {\$z=!\$z if!\$r;\$i=" 01234567\n";print\$i,(join"",map{(\$x,\$y)=o(\$_);(\$x?"":\$y) .(a(\$_)?`tput smso`:`tput rmso`).(g(o(\$_))||" ").`tput rmso`.(\$x==7?"\$y\n": "")}@a),\$i;\$z?&n:&c;g(\$f,\$g,(\$g==7&&\$z)||!(\$z||\$g)?uc&w:g(\$d,\$e));g(\$d,\$e,0 );t(1)}sub n{print"\$_[0]xyxy?\n";(\$d,\$e,\$f,\$g)=split"",;&v||&n}sub t{ @t=(\$f>\$d?\$d+1:\$d-1,\$g>\$e?\$e+1:\$e-1);if(\$s==4&&g(@t)&&lc(g(@t))ne&w){if( @_){g(@t,0);\$z?--\$b:--\$w;&b}1}else{0}}sub v{\$s=(\$d-\$f)**2;(lc(g(\$d,\$e))ne&w ||\$s!=(\$e-\$g)**2||g(\$f,\$g)||\$f>7||\$f<0||\$g>7||\$g<0||((\$z?\$e-\$g:\$g-\$e)>0)&&! (g(\$d,\$e)eq uc&w)||!(\$s==1||t())||(\$r?\$d!=\$c||\$e!=\$h:0))?0:1}sub c{for(@a){ (\$d,\$e)=o(\$_);if(lc(g(o(\$_)))eq&w){for(@a){(\$f,\$g)=o(\$_);&t?return:push@q,[ \$d,\$e,\$f,\$g]if&v}}}(\$d,\$e,\$f,\$g)=@{\$q[\$#q]}}sub w{\$z?"w":"b"}sub o{(\$_[0]%8,int(\$_[0]/8))}sub a{(\$_[0]%8+int(\$_[0]/8))%2}sub g{\$n=\$_[0]+8*\$_[1];defined\$_[2]?\$j[\$n]=\$_[2]:\$j[\$n]}sub b{\$d=\$c=\$f;\$e=\$h=\$g ;\$r=(grep{(\$f,\$g)=o(\$_);&v&&t()}@a)?1:0}die\$w?"win":"lose"."\n"