Speffz BLD tools: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
Created page with "A program to generate a BLD memo sequence in speffz from a standard WCA scramble. <div style ="height:200px;overflow-x:hidden;overflow-y:auto;border: 4px solid green;"> <synt..."
 
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
A program to generate a BLD memo sequence in speffz from a standard WCA scramble.
A program to generate a BLD memo sequence in speffz from a standard WCA scramble.
A work-in-progress: needs scramble parser and performer


<div style ="height:200px;overflow-x:hidden;overflow-y:auto;border: 4px solid green;">
<div style ="height:200px;overflow-x:hidden;overflow-y:auto;border: 4px solid green;">
Line 6: Line 8:
#!perl -w
#!perl -w
use strict;
use strict;
use Data::Dumper::Simple;
use tmstub;
=for docs
 
This is in perl for brevity but could be any language - it's just a vehicle
for the programming concepts.
 
https://www.speedsolving.com/wiki/index.php/Speffz
 
TODO: -
apply given scramble
unit tests
generic abstract canvas style GUI
port it to various other languages
Transforms for each face turn move
Words for letter pairs!
 
=cut
t "Yo, let's speffz it up...";


print "yo, let's speffz it up...\n";
my $scr = shift || "R U R' U'";
my $scr = shift || "R U R' U'";
my $debug = 1;
my $debug = 1;
Line 14: Line 32:
#~ print $cs;
#~ print $cs;
#~ print "\n";
#~ print "\n";
my $p = draw($cs);
my $p = draw($cs, 1);
print $p;
t $p;
print "\n";
$p = draw($cs, 0);
t $p;


## Unscrambled 3x3 cube state in speffz format
## Unscrambled 3x3 cube state in speffz format - clockwise lettering of stickers
sub fresh_cube {
sub fresh_cube {
     my $s = "";
     my $s = "";
Line 31: Line 50:
     return ($1, $2, $3, $4, $5, $6);  
     return ($1, $2, $3, $4, $5, $6);  
}
}
## Draw the given cube state as a human-friendly net
## Draw the given cube state as a human-friendly net
# here we can support different face orders
# here we can support different face orders
Line 75: Line 95:
sub draw {
sub draw {
     my $s = shift;
     my $s = shift;
     my $boxes = 1;
     my $boxes = shift;
     my @a = faces($s);
     my @a = faces($s);
     #~ print Dumper(\@a);
     #~ print Dumper(\@a);
Line 110: Line 130:
}
}


## Convert a face into 3 rows of 3 stickers - top to bottom, left to right
sub facerows {
sub facerows {
     local $_ = shift;
     local $_ = shift;
Line 115: Line 136:
     return [[$c[0], $c[1], $c[2]], [$c[7], '*', $c[3]], [$c[6], $c[5], $c[4]]];
     return [[$c[0], $c[1], $c[2]], [$c[7], '*', $c[3]], [$c[6], $c[5], $c[4]]];
}
}


</syntaxhighlight>
</syntaxhighlight>
</div>
</div>

Latest revision as of 23:31, 2 July 2018

A program to generate a BLD memo sequence in speffz from a standard WCA scramble.

A work-in-progress: needs scramble parser and performer

#!perl -w
use strict;
use tmstub;
=for docs

This is in perl for brevity but could be any language - it's just a vehicle 
for the programming concepts.

https://www.speedsolving.com/wiki/index.php/Speffz

TODO: -
apply given scramble
unit tests
generic abstract canvas style GUI
port it to various other languages
Transforms for each face turn move
Words for letter pairs!

=cut
t "Yo, let's speffz it up...";

my $scr = shift || "R U R' U'";
my $debug = 1;
my $cs = fresh_cube();
#~ print $cs;
#~ print "\n";
my $p = draw($cs, 1);
t $p;
$p = draw($cs, 0);
t $p;

## Unscrambled 3x3 cube state in speffz format - clockwise lettering of stickers
sub fresh_cube {
    my $s = "";
    foreach('A'..'X') { $s .= $_ . lc($_); }
    return $s;	
}

## Split speffz cube state into 6 faces
sub faces {
    local $_ = shift;
    die unless /^(.{8})(.{8})(.{8})(.{8})(.{8})(.{8})$/;
    return ($1, $2, $3, $4, $5, $6); 
}

## Draw the given cube state as a human-friendly net
# here we can support different face orders
# ULFRBD is the speffz standard though
#
#     +-+
#     |U|
#   +-+-+-+-+
#   |L|F|R|B|
#   +-+-+-+-+
#     |D|
#     +-+
# 
#       AaB
#       d*b
#       DcC
#    EeFIiJMmNQqR
#    h*fl*jp*nt*r
#    HgGLkKPoOTsS
#       UuV
#       x*v
#       XwW
#   
#           +-+-+-+
#           |A|a|B|
#           +-+-+-+
#           |d|*|b|
#           +-+-+-+
#           |D|c|C|
#     +-+-+-+-+-+-+-+-+-+-+-+-+
#     |E|e|F|I|i|J|M|m|N|Q|q|R|
#     +-+-+-+-+-+-+-+-+-+-+-+-+
#     |h|*|f|l|*|j|p|*|n|t|*|r|
#     +-+-+-+-+-+-+-+-+-+-+-+-+
#     |H|g|G|L|k|K|P|o|O|T|s|S|
#     +-+-+-+-+-+-+-+-+-+-+-+-+
#           |U|u|V|
#           +-+-+-+
#           |x|*|v|
#           +-+-+-+
#           |X|w|W|
#           +-+-+-+
#     
sub draw {
    my $s = shift;
    my $boxes = shift;
    my @a = faces($s);
    #~ print Dumper(\@a);
    #~ print "\n";
    my @rd = map{ facerows($_) }@a;
    #~ print Dumper(\@rd);
    #~ print "\n";
    my @rows;
    # here we can set up the drawing style to use - raw or boxes
    my $dent = $boxes ? ' 'x6 : ' 'x3;
    my $v = $boxes ? "|" : "";
    # U
    my ($u, $l, $f, $r, $b, $d) = @rd;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$u->[0]}).$v;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$u->[1]}).$v;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$u->[2]}).$v;
    if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
    push @rows, $v.join($v, @{$l->[0]}).$v.join($v, @{$f->[0]}).$v.join($v, @{$r->[0]}).$v.join($v, @{$b->[0]}).$v;
    if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
    push @rows, $v.join($v, @{$l->[1]}).$v.join($v, @{$f->[1]}).$v.join($v, @{$r->[1]}).$v.join($v, @{$b->[1]}).$v;
    if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
    push @rows, $v.join($v, @{$l->[2]}).$v.join($v, @{$f->[2]}).$v.join($v, @{$r->[2]}).$v.join($v, @{$b->[2]}).$v;
    if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$d->[0]}).$v;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$d->[1]}).$v;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    push @rows, $dent.$v.join($v, @{$d->[2]}).$v;
    if($boxes) { push @rows, $dent."+-+-+-+"; }
    return join("\n", @rows);
}

## Convert a face into 3 rows of 3 stickers - top to bottom, left to right
sub facerows {
    local $_ = shift;
    my @c = split //;
    return [[$c[0], $c[1], $c[2]], [$c[7], '*', $c[3]], [$c[6], $c[5], $c[4]]];
}