Speffz BLD tools
From Nottinghack Wiki
A program to generate a BLD memo sequence in speffz from a standard WCA scramble.
A work-in-progress: needs scramble parser and performer
1 #!perl -w
2 use strict;
3 use Data::Dumper::Simple;
4
5 print "yo, let's speffz it up...\n";
6 my $scr = shift || "R U R' U'";
7 my $debug = 1;
8 my $cs = fresh_cube();
9 #~ print $cs;
10 #~ print "\n";
11 my $p = draw($cs);
12 print $p;
13 print "\n";
14
15 ## Unscrambled 3x3 cube state in speffz format
16 sub fresh_cube {
17 my $s = "";
18 foreach('A'..'X') { $s .= $_ . lc($_); }
19 return $s;
20 }
21
22 ## Split speffz cube state into 6 faces
23 sub faces {
24 local $_ = shift;
25 die unless /^(.{8})(.{8})(.{8})(.{8})(.{8})(.{8})$/;
26 return ($1, $2, $3, $4, $5, $6);
27 }
28 ## Draw the given cube state as a human-friendly net
29 # here we can support different face orders
30 # ULFRBD is the speffz standard though
31 #
32 # +-+
33 # |U|
34 # +-+-+-+-+
35 # |L|F|R|B|
36 # +-+-+-+-+
37 # |D|
38 # +-+
39 #
40 # AaB
41 # d*b
42 # DcC
43 # EeFIiJMmNQqR
44 # h*fl*jp*nt*r
45 # HgGLkKPoOTsS
46 # UuV
47 # x*v
48 # XwW
49 #
50 # +-+-+-+
51 # |A|a|B|
52 # +-+-+-+
53 # |d|*|b|
54 # +-+-+-+
55 # |D|c|C|
56 # +-+-+-+-+-+-+-+-+-+-+-+-+
57 # |E|e|F|I|i|J|M|m|N|Q|q|R|
58 # +-+-+-+-+-+-+-+-+-+-+-+-+
59 # |h|*|f|l|*|j|p|*|n|t|*|r|
60 # +-+-+-+-+-+-+-+-+-+-+-+-+
61 # |H|g|G|L|k|K|P|o|O|T|s|S|
62 # +-+-+-+-+-+-+-+-+-+-+-+-+
63 # |U|u|V|
64 # +-+-+-+
65 # |x|*|v|
66 # +-+-+-+
67 # |X|w|W|
68 # +-+-+-+
69 #
70 sub draw {
71 my $s = shift;
72 my $boxes = 1;
73 my @a = faces($s);
74 #~ print Dumper(\@a);
75 #~ print "\n";
76 my @rd = map{ facerows($_) }@a;
77 #~ print Dumper(\@rd);
78 #~ print "\n";
79 my @rows;
80 # here we can set up the drawing style to use - raw or boxes
81 my $dent = $boxes ? ' 'x6 : ' 'x3;
82 my $v = $boxes ? "|" : "";
83 # U
84 my ($u, $l, $f, $r, $b, $d) = @rd;
85 if($boxes) { push @rows, $dent."+-+-+-+"; }
86 push @rows, $dent.$v.join($v, @{$u->[0]}).$v;
87 if($boxes) { push @rows, $dent."+-+-+-+"; }
88 push @rows, $dent.$v.join($v, @{$u->[1]}).$v;
89 if($boxes) { push @rows, $dent."+-+-+-+"; }
90 push @rows, $dent.$v.join($v, @{$u->[2]}).$v;
91 if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
92 push @rows, $v.join($v, @{$l->[0]}).$v.join($v, @{$f->[0]}).$v.join($v, @{$r->[0]}).$v.join($v, @{$b->[0]}).$v;
93 if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
94 push @rows, $v.join($v, @{$l->[1]}).$v.join($v, @{$f->[1]}).$v.join($v, @{$r->[1]}).$v.join($v, @{$b->[1]}).$v;
95 if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
96 push @rows, $v.join($v, @{$l->[2]}).$v.join($v, @{$f->[2]}).$v.join($v, @{$r->[2]}).$v.join($v, @{$b->[2]}).$v;
97 if($boxes) { push @rows, "+-+-+-+-+-+-+-+-+-+-+-+-+"; }
98 push @rows, $dent.$v.join($v, @{$d->[0]}).$v;
99 if($boxes) { push @rows, $dent."+-+-+-+"; }
100 push @rows, $dent.$v.join($v, @{$d->[1]}).$v;
101 if($boxes) { push @rows, $dent."+-+-+-+"; }
102 push @rows, $dent.$v.join($v, @{$d->[2]}).$v;
103 if($boxes) { push @rows, $dent."+-+-+-+"; }
104 return join("\n", @rows);
105 }
106
107 sub facerows {
108 local $_ = shift;
109 my @c = split //;
110 return [[$c[0], $c[1], $c[2]], [$c[7], '*', $c[3]], [$c[6], $c[5], $c[4]]];
111 }