I popped up some code. It's wastes a few moves somewhere.. and I havent tried it on even values, as the center has more cases. So non optimal code, but the runtime is very predictable, and near optimal for odd sized boards. And yes the Iso stabilization is a bit cheap. but it's a proof o'concept.
#!/usr/bin/perl # $max=44; $moves=0; %boardx; $boardx{'A'}=0;$boardy{'A'}=0; $boardx{'B'}=$max;$boardy{'B'}=0; $boardx{'C'}=$max;$boardy{'C'}=$max; $boardx{'Z'}=$max;$boardy{'Z'}=$max; sub collide{ if ($boardx{'Z'} <0){ return 1;} if ($boardy{'Z'} <0) {return 1;} if ($boardx{'Z'} >$max){ return 1;} if ($boardy{'Z'} >$max){ return 1;} if (($boardx{'Z'}==$boardx{'A'}) && ($boardy{'Z'}==$boardy{' +A'})) {return 1;} if (($boardx{'Z'}==$boardx{'B'}) && ($boardy{'Z'}==$boardy{' +B'})) { return 1;} if (($boardx{'Z'}==$boardx{'C'}) && ($boardy{'Z'}==$boardy{' +C'})) { return 1;} return(0); } sub printBoard{ print "\n"; for($i=0;$i<=$max;$i++){ for($j=0;$j<=$max;$j++){ $zed=1; foreach ('A','B','C'){ if (($boardx{$_}==$j) && ($boardy{$_}= +=$i)){ print $_; $zed=0; } } if ($zed){ print '.';} } print "\n"; } } sub move{ $block=shift(@_); $dir=shift(@_);# 0-3 nesw or urdl $boardx{'Z'}=$boardx{$block}; $boardy{'Z'}=$boardy{$block}; if ($dir==0){$boardy{'Z'}--;} if ($dir==1){$boardx{'Z'}++;} if ($dir==2){$boardy{'Z'}++;} if ($dir==3){$boardx{'Z'}--;} if (&collide){$moves++; return;} $boardx{$block}=$boardx{'Z'}; $boardy{$block}=$boardy{'Z'}; &move($block,$dir); } sub dinkUp{ #assumes An A-left B left, C right Low &move('A',1); &move('B',0); &move('A',3); &move('B',2); &move('B',1); &move('A',0); &move('B',3); &move('A',2); } sub dinkSide{ #assumes An A-left , C right , b RIGHT LOW &move('C',3); &move('A',0); &move('A',1); &move('A',2); &move('A',3); if ($boardx{'A'}==$max/2){return;} &move('C',0); &move('C',1); &move('C',2); } &printBoard; &move('B',2); &move('B',3); &move('A',2); &printBoard; while ($boardy{'A'} > $max/2+1){ &dinkUp; } if ($boardy{'A'}==$max/2){ &move('C',0); &move('B',1); &move('C',2); } if ($boardy{'A'}>$max/2){ &move('C',0); &move('A',1); &move('C',2); &move('B',0); &move('A',3); &move('B',2); } ## ISO-STABILIZATION &printBoard; print "Isoform:\n"; $boardx{'A'}=0;$boardy{'A'}=$max/2; $boardx{'B'}=$max;$boardy{'B'}=$max/2+1; $boardx{'C'}=$max;$boardy{'C'}=$max/2; &printBoard; while ($boardx{'A'} < $max/2-1){ &dinkSide; } if ($boardx{'A'}<$max/2){ &move('C',3); } &printBoard; print "moves: $moves\n";

In reply to Re^4: Block-sliding puzzle by tempest69
in thread Block-sliding puzzle by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.