From e7201c4bc50344c4c0fb5ffa5b0bd4baf8e2cdf2 Mon Sep 17 00:00:00 2001 From: Circiter Date: Sat, 6 Jun 2020 04:58:29 +0600 Subject: [PATCH 1/3] Rule 30 PRNG added --- sedtris.internal-prng.sh | 44 ++++++++++++++++++++++++++++++++++++++++ sedtris.sed | 35 +++++++++++++++++++++++++++++++- sedtris.sh | 0 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 sedtris.internal-prng.sh mode change 100644 => 100755 sedtris.sed mode change 100644 => 100755 sedtris.sh diff --git a/sedtris.internal-prng.sh b/sedtris.internal-prng.sh new file mode 100755 index 0000000..1f91557 --- /dev/null +++ b/sedtris.internal-prng.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Bash script to make playing Sedtris more comfortable. +# It presses "enter" automatically once in a second and after +# every player's move. +# +# It also creates a random seed for the internal PRNG to improve gameplay. +# +# Based on playsed.sh by Aurelio Marinho Jargas http://sed.sf.net/grabbag/scripts/playsed.sh.txt + +mytime="`date +%s`" + +IFS='' +CMD='' +TMP='' + +cat /dev/urandom | tr -dc "01" | fold -w 18 | head -1 > seed.txt + +export LC_ALL="C" +(while true; +do + read -s -t 1 -n 1 TMP + RES=$? + CMD="$CMD$TMP" + if [ "$CMD" == '' ] + then + read -s -n 1 TMP; CMD="$CMD$TMP"; + if [ "$CMD" == '[' ] + then + read -s -n 1 TMP; CMD="$CMD$TMP"; + fi + fi + if [ $RES -eq 0 ] + then + echo "$CMD" + fi + CMD='' + TMP='' + mytimenew="`date +%s`" + if [ "$mytimenew" != "$mytime" ] + then + echo + mytime=$mytimenew + fi +done) | cat seed.txt - | sed -nf `dirname $0`/sedtris.sed diff --git a/sedtris.sed b/sedtris.sed old mode 100644 new mode 100755 index 90bb910..b786561 --- a/sedtris.sed +++ b/sedtris.sed @@ -2,7 +2,17 @@ # sedtris.sed - sed tetris # 26th of May, 2008 # Julia Jomantaite + +# Usage examples: +# ./sedtris.sed +# ./sedtris.sh +# ./sedtris.internal-prng.sh +# cat seed.txt - | ./sedtris.sed +# where seed.txt contains a string of 0 and 1, +# e.g., echo 00000110000 > seed.txt +:again 1{ +/./! s/$/0001000/; h # Backup the seed. s/.*/ 2a2a2a2a|3a3a3a3a3a3a3a3a3a3a|2a2a2a2a~/ s/[^~]*~$/&&&/ s/.*/& 2a2a2a2a|0a0a0a0a0a0a0a0a0a0a|2a2a2a2a~/ @@ -18,13 +28,17 @@ s/$/#AAAA EDCA GPJA IMBA~/ s/$/#ACIA EGME BDJB ACIA~/ s/$/#AAAA IKEA FPFA BKCA~/ s/$/#AAAA CGBA MPDA EJIA~/ +G; s/\ +\([01]*\)$/#\1~/ # Place the seed among other "variables." s/$/#NEXTAAAA ANAA LPOA AHAA 5~/ s/$/#SCORE0~/ h b display } -/1/{s/1//;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} +brandom; :return; s/0// # Call the PRNG code. + +/1/{s/1//g;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} /^w/b rotate /^a/b left @@ -342,3 +356,22 @@ i\  p /GAME OVER!/q + +n; bagain + +:random # Rule 30 automaton (see github.com/Circiter/elementary-ca-in-sed). + g; s/^.*#\([01]*\)~.*$/\1/ # Get the old generation. + s/^\(.\)\(.*\)\(.\)$/>\3\1\2\3\1/ + :update # Evolve according to rule 30. + s/$/\n000=0;001=1;010=1;011=1;100=1;101=0;110=0;111=0/ + s/^\([^>]*\)>\(...\)\([^\n]*\n\).*\2=\(.\)/\1\4>\2\3/ + s/\n.*$//; s/>./>/ + />$/! bupdate + s/>// + # Save the new generation. + x; s/$/@/; G; s/#[01]*~\(.*\)@[^01]*\([01]*\)$/#\2~\1/; x + :center # Remove all but the central cell. + s/^.\(.\)/\1/; + s/\(.\).$/\1/ + /../bcenter + breturn diff --git a/sedtris.sh b/sedtris.sh old mode 100644 new mode 100755 From 1d47682a090f0eab99bfa33d01858d835f5fd743 Mon Sep 17 00:00:00 2001 From: Circiter Date: Sat, 6 Jun 2020 05:25:51 +0600 Subject: [PATCH 2/3] messing up with branches --- sedtris.internal-prng.sh | 44 ---------------------------------------- sedtris.sed | 35 +------------------------------- sedtris.sh | 0 3 files changed, 1 insertion(+), 78 deletions(-) delete mode 100755 sedtris.internal-prng.sh mode change 100755 => 100644 sedtris.sed mode change 100755 => 100644 sedtris.sh diff --git a/sedtris.internal-prng.sh b/sedtris.internal-prng.sh deleted file mode 100755 index 1f91557..0000000 --- a/sedtris.internal-prng.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# Bash script to make playing Sedtris more comfortable. -# It presses "enter" automatically once in a second and after -# every player's move. -# -# It also creates a random seed for the internal PRNG to improve gameplay. -# -# Based on playsed.sh by Aurelio Marinho Jargas http://sed.sf.net/grabbag/scripts/playsed.sh.txt - -mytime="`date +%s`" - -IFS='' -CMD='' -TMP='' - -cat /dev/urandom | tr -dc "01" | fold -w 18 | head -1 > seed.txt - -export LC_ALL="C" -(while true; -do - read -s -t 1 -n 1 TMP - RES=$? - CMD="$CMD$TMP" - if [ "$CMD" == '' ] - then - read -s -n 1 TMP; CMD="$CMD$TMP"; - if [ "$CMD" == '[' ] - then - read -s -n 1 TMP; CMD="$CMD$TMP"; - fi - fi - if [ $RES -eq 0 ] - then - echo "$CMD" - fi - CMD='' - TMP='' - mytimenew="`date +%s`" - if [ "$mytimenew" != "$mytime" ] - then - echo - mytime=$mytimenew - fi -done) | cat seed.txt - | sed -nf `dirname $0`/sedtris.sed diff --git a/sedtris.sed b/sedtris.sed old mode 100755 new mode 100644 index b786561..90bb910 --- a/sedtris.sed +++ b/sedtris.sed @@ -2,17 +2,7 @@ # sedtris.sed - sed tetris # 26th of May, 2008 # Julia Jomantaite - -# Usage examples: -# ./sedtris.sed -# ./sedtris.sh -# ./sedtris.internal-prng.sh -# cat seed.txt - | ./sedtris.sed -# where seed.txt contains a string of 0 and 1, -# e.g., echo 00000110000 > seed.txt -:again 1{ -/./! s/$/0001000/; h # Backup the seed. s/.*/ 2a2a2a2a|3a3a3a3a3a3a3a3a3a3a|2a2a2a2a~/ s/[^~]*~$/&&&/ s/.*/& 2a2a2a2a|0a0a0a0a0a0a0a0a0a0a|2a2a2a2a~/ @@ -28,17 +18,13 @@ s/$/#AAAA EDCA GPJA IMBA~/ s/$/#ACIA EGME BDJB ACIA~/ s/$/#AAAA IKEA FPFA BKCA~/ s/$/#AAAA CGBA MPDA EJIA~/ -G; s/\ -\([01]*\)$/#\1~/ # Place the seed among other "variables." s/$/#NEXTAAAA ANAA LPOA AHAA 5~/ s/$/#SCORE0~/ h b display } -brandom; :return; s/0// # Call the PRNG code. - -/1/{s/1//g;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} +/1/{s/1//;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} /^w/b rotate /^a/b left @@ -356,22 +342,3 @@ i\  p /GAME OVER!/q - -n; bagain - -:random # Rule 30 automaton (see github.com/Circiter/elementary-ca-in-sed). - g; s/^.*#\([01]*\)~.*$/\1/ # Get the old generation. - s/^\(.\)\(.*\)\(.\)$/>\3\1\2\3\1/ - :update # Evolve according to rule 30. - s/$/\n000=0;001=1;010=1;011=1;100=1;101=0;110=0;111=0/ - s/^\([^>]*\)>\(...\)\([^\n]*\n\).*\2=\(.\)/\1\4>\2\3/ - s/\n.*$//; s/>./>/ - />$/! bupdate - s/>// - # Save the new generation. - x; s/$/@/; G; s/#[01]*~\(.*\)@[^01]*\([01]*\)$/#\2~\1/; x - :center # Remove all but the central cell. - s/^.\(.\)/\1/; - s/\(.\).$/\1/ - /../bcenter - breturn diff --git a/sedtris.sh b/sedtris.sh old mode 100755 new mode 100644 From 5f172418d08a62633030e68cedc0509847e99407 Mon Sep 17 00:00:00 2001 From: Circiter Date: Sat, 6 Jun 2020 05:33:54 +0600 Subject: [PATCH 3/3] PRNG added --- sedtris.internal-prng.sh | 44 ++++++++++++++++++++++++++++++++++++++++ sedtris.sed | 35 +++++++++++++++++++++++++++++++- sedtris.sh | 3 ++- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100755 sedtris.internal-prng.sh mode change 100644 => 100755 sedtris.sed mode change 100644 => 100755 sedtris.sh diff --git a/sedtris.internal-prng.sh b/sedtris.internal-prng.sh new file mode 100755 index 0000000..1f91557 --- /dev/null +++ b/sedtris.internal-prng.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Bash script to make playing Sedtris more comfortable. +# It presses "enter" automatically once in a second and after +# every player's move. +# +# It also creates a random seed for the internal PRNG to improve gameplay. +# +# Based on playsed.sh by Aurelio Marinho Jargas http://sed.sf.net/grabbag/scripts/playsed.sh.txt + +mytime="`date +%s`" + +IFS='' +CMD='' +TMP='' + +cat /dev/urandom | tr -dc "01" | fold -w 18 | head -1 > seed.txt + +export LC_ALL="C" +(while true; +do + read -s -t 1 -n 1 TMP + RES=$? + CMD="$CMD$TMP" + if [ "$CMD" == '' ] + then + read -s -n 1 TMP; CMD="$CMD$TMP"; + if [ "$CMD" == '[' ] + then + read -s -n 1 TMP; CMD="$CMD$TMP"; + fi + fi + if [ $RES -eq 0 ] + then + echo "$CMD" + fi + CMD='' + TMP='' + mytimenew="`date +%s`" + if [ "$mytimenew" != "$mytime" ] + then + echo + mytime=$mytimenew + fi +done) | cat seed.txt - | sed -nf `dirname $0`/sedtris.sed diff --git a/sedtris.sed b/sedtris.sed old mode 100644 new mode 100755 index 90bb910..b786561 --- a/sedtris.sed +++ b/sedtris.sed @@ -2,7 +2,17 @@ # sedtris.sed - sed tetris # 26th of May, 2008 # Julia Jomantaite + +# Usage examples: +# ./sedtris.sed +# ./sedtris.sh +# ./sedtris.internal-prng.sh +# cat seed.txt - | ./sedtris.sed +# where seed.txt contains a string of 0 and 1, +# e.g., echo 00000110000 > seed.txt +:again 1{ +/./! s/$/0001000/; h # Backup the seed. s/.*/ 2a2a2a2a|3a3a3a3a3a3a3a3a3a3a|2a2a2a2a~/ s/[^~]*~$/&&&/ s/.*/& 2a2a2a2a|0a0a0a0a0a0a0a0a0a0a|2a2a2a2a~/ @@ -18,13 +28,17 @@ s/$/#AAAA EDCA GPJA IMBA~/ s/$/#ACIA EGME BDJB ACIA~/ s/$/#AAAA IKEA FPFA BKCA~/ s/$/#AAAA CGBA MPDA EJIA~/ +G; s/\ +\([01]*\)$/#\1~/ # Place the seed among other "variables." s/$/#NEXTAAAA ANAA LPOA AHAA 5~/ s/$/#SCORE0~/ h b display } -/1/{s/1//;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} +brandom; :return; s/0// # Call the PRNG code. + +/1/{s/1//g;x;s/#\.\.*/&./;s/#\.\{8\}/#./;x;} /^w/b rotate /^a/b left @@ -342,3 +356,22 @@ i\  p /GAME OVER!/q + +n; bagain + +:random # Rule 30 automaton (see github.com/Circiter/elementary-ca-in-sed). + g; s/^.*#\([01]*\)~.*$/\1/ # Get the old generation. + s/^\(.\)\(.*\)\(.\)$/>\3\1\2\3\1/ + :update # Evolve according to rule 30. + s/$/\n000=0;001=1;010=1;011=1;100=1;101=0;110=0;111=0/ + s/^\([^>]*\)>\(...\)\([^\n]*\n\).*\2=\(.\)/\1\4>\2\3/ + s/\n.*$//; s/>./>/ + />$/! bupdate + s/>// + # Save the new generation. + x; s/$/@/; G; s/#[01]*~\(.*\)@[^01]*\([01]*\)$/#\2~\1/; x + :center # Remove all but the central cell. + s/^.\(.\)/\1/; + s/\(.\).$/\1/ + /../bcenter + breturn diff --git a/sedtris.sh b/sedtris.sh old mode 100644 new mode 100755 index 361c0f2..32875ca --- a/sedtris.sh +++ b/sedtris.sh @@ -39,7 +39,8 @@ do let "temp=($RANDOM/10)%7" if [ $temp == 1 ] then - echo $temp + #echo $temp + echo else echo fi