scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

practice (4814B)


      1 #!/bin/sh
      2 
      3 # Script based on nissy (see https://nissy.tronto.net) to practice FMC
      4 
      5 # Usage: practice [eo|dr|htr|slice]
      6 
      7 nissy="nissy"
      8 prompt="Press enter for a new scramble, Ctr+C (or Ctrl+Z) to quit:"
      9 
     10 usage() {
     11 	echo "Usage: practice [eo|dr|htr|fin]"
     12 	exit 1
     13 }
     14 
     15 practice_eo() {
     16 	nextscr="$(${nissy} scramble fmc)"
     17 	while true; do
     18 		scr="$nextscr"
     19 		echo "Scramble: $scr"
     20 		nextscr="$(${nissy} scramble fmc)"
     21 		eofb="$(${nissy} solve -N -M 4 eofb -p "$scr")"
     22 		eorl="$(${nissy} solve -N -M 4 eorl -p "$scr")"
     23 		eoud="$(${nissy} solve -N -M 4 eoud -p "$scr")"
     24 		nfbn="$(echo "$eofb" | grep -v '^$' | grep -Fv '(' | wc -l)"
     25 		nrln="$(echo "$eorl" | grep -v '^$' | grep -Fv '(' | wc -l)"
     26 		nudn="$(echo "$eoud" | grep -v '^$' | grep -Fv '(' | wc -l)"
     27 		nfbi="$(echo "$eofb" | grep '^(' | wc -l)"
     28 		nrli="$(echo "$eorl" | grep '^(' | wc -l)"
     29 		nudi="$(echo "$eoud" | grep '^(' | wc -l)"
     30 		nfbniss="$(echo "$eofb" | grep -v '^(' | grep '(' | wc -l)"
     31 		nrlniss="$(echo "$eorl" | grep -v '^(' | grep '(' | wc -l)"
     32 		nudniss="$(echo "$eoud" | grep -v '^(' | grep '(' | wc -l)"
     33 		nfb="$((nfbn + nfbi + nfbniss))"
     34 		nrl="$((nrln + nrli + nrlniss))"
     35 		nud="$((nudn + nudi + nudniss))"
     36 		n5linear="$(${nissy} solve -L -m 5 -M 5 eo -c "$scr")"
     37 		n5niss="$(${nissy} solve -N -m 5 -M 5 eo -c "$scr")"
     38 		n5nonlinear="$((n5niss - n5linear))"
     39 		read -r x
     40 		echo "FB: $nfb ($nfbn normal, $nfbi inverse, $nfbniss niss)"
     41 		echo "RL: $nrl ($nrln normal, $nrli inverse, $nrlniss niss)"
     42 		echo "UD: $nud ($nudn normal, $nudi inverse, $nudniss niss)"
     43 		echo "5 movers: $n5linear linear, $n5nonlinear NISS'd"
     44 		read -r x
     45 		echo "$eofb"
     46 		echo "---"
     47 		echo "$eorl"
     48 		echo "---"
     49 		echo "$eoud"
     50 		printf '\n%s' "$prompt"
     51 		read -r x
     52 	done
     53 }
     54 
     55 practice_dr() {
     56 	nextscr="$(${nissy} scramble eo)"
     57 	while true; do
     58 		scr="$nextscr"
     59 		echo "Scramble: $scr"
     60 		nextscr="$(${nissy} scramble eo)"
     61 		soleo="$(${nissy} solve -o -p drud-eofb "$scr")"
     62 		neo="$(echo "$soleo" | grep -v '^$' | wc -l)"
     63 		leo="$(echo "$soleo" | head -n 1 | wc -w)"
     64 		solht="$(${nissy} solve -o -p drud "$scr")"
     65 		nht="$(echo "$solht" | grep -v '^$' | wc -l)"
     66 		lht="$(echo "$solht" | head -n 1 | wc -w)"
     67 		soleolr="$(${nissy} solve -o -p drrl-eofb "$scr")"
     68 		neolr="$(echo "$soleolr" | grep -v '^$' | wc -l)"
     69 		leolr="$(echo "$soleolr" | head -n 1 | wc -w)"
     70 		solhtlr="$(${nissy} solve -o -p drrl "$scr")"
     71 		nhtlr="$(echo "$solhtlr" | grep -v '^$' | wc -l)"
     72 		lhtlr="$(echo "$solhtlr" | head -n 1 | wc -w)"
     73 		read -r x
     74 		echo "DR on U/D: $leo moves ($neo solutions)"
     75 		if [ "$nht" != "$neo" ]; then
     76 			echo "Breaking EO: $lht moves ($nht solutions)"
     77 		fi
     78 		echo "DR on R/L: $leolr moves ($neolr solutions)"
     79 		if [ "$nhtlr" != "$neolr" ]; then
     80 			echo "Breaking EO: $lhtlr moves ($nhtlr solutions)"
     81 		fi
     82 		read -r x
     83 		echo "On U/D:"
     84 		echo "$soleo"
     85 		echo ""
     86 		if [ "$nht" != "$neo" ] || [ "$lht" != "$leo" ]; then
     87 			echo "Breaking EO:"
     88 			echo "$solht"
     89 			echo ""
     90 		fi
     91 		echo "On R/L:"
     92 		echo "$soleolr"
     93 		echo ""
     94 		if [ "$nhtlr" != "$neolr" ] || [ "$lhtlr" != "$leolr" ]; then
     95 			echo "Breaking EO:"
     96 			echo "$solhtlr"
     97 			echo ""
     98 		fi
     99 		printf '\n%s' "$prompt"
    100 		read -r x
    101 	done
    102 }
    103 
    104 practice_htr() {
    105 	nextscr="$(${nissy} scramble dr)"
    106 	while true; do
    107 		scr="$nextscr"
    108 		echo "Scramble: $scr"
    109 		nextscr="$(${nissy} scramble dr)"
    110 		sol="$(${nissy} solve -o -p htr "$scr")"
    111 		nsol="$(echo "$sol" | grep -v '^$' | wc -l)"
    112 		len="$(echo "$sol" | head -n 1 | wc -w)"
    113 		fin="$(${nissy} solve -o -p drfin "$scr")"
    114 		lenf="$(echo "$fin" | head -n 1 | wc -w)"
    115 		slice="$(${nissy} solve -o -p drslice "$scr")"
    116 		lens="$(echo "$slice" | head -n 1 | wc -w)"
    117 		read -r x
    118 		echo "$len moves ($nsol solutions)"
    119 		read -r x
    120 		echo "$sol"
    121 		if [ "$lenf" != "$lens" ]; then
    122 			echo ""
    123 			echo "Optimal leave slice ($lens):"
    124 			echo "$slice"
    125 		fi
    126 		echo ""
    127 		echo "Optimal DR finish ($lenf):"
    128 		echo "$fin"
    129 		printf '\n%s' "$prompt"
    130 		read -r x
    131 	done
    132 }
    133 
    134 practice_fin() {
    135 	nextscr="$(${nissy} scramble htr)"
    136 	while true; do
    137 		scr="$nextscr"
    138 		echo "Scramble: $scr"
    139 		nextscr="$(${nissy} scramble htr)"
    140 		sol="$(${nissy} solve -o -p drudslice "$scr")"
    141 		nsol="$(echo "$sol" | grep -v '^$' | wc -l)"
    142 		len="$(echo "$sol" | head -n 1 | wc -w)"
    143 		fin="$(${nissy} solve -o -p drudfin "$scr")"
    144 		nfin="$(echo "$fin" | grep -v '^$' | wc -l)"
    145 		lenf="$(echo "$fin" | head -n 1 | wc -w)"
    146 		opt="$(${nissy} solve -o -p "$scr")"
    147 		leno="$(echo "$opt" | head -n 1 | wc -w)"
    148 		read -r x
    149 		echo "Leave slice: $len moves ($nsol solutions)"
    150 		if [ "$lenf" != "$len" ]; then
    151 			echo "DR finish: $lenf moves"
    152 		fi
    153 		read -r x
    154 		echo "$sol"
    155 		if [ "$lenf" != "$len" ]; then
    156 			echo ""
    157 			echo "Optimal DR finish ($lenf):"
    158 			echo "$fin"
    159 		fi
    160 		if [ "$leno" != "$lenf" ]; then
    161 			echo ""
    162 			echo "Optimal DR-breaking ($leno):"
    163 			echo "$opt"
    164 		fi
    165 		printf '\n%s' "$prompt"
    166 		read -r x
    167 	done
    168 }
    169 
    170 "practice_$1" || usage