Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions sedtris.internal-prng.sh
Original file line number Diff line number Diff line change
@@ -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
35 changes: 34 additions & 1 deletion sedtris.sed
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
# sedtris.sed - sed tetris
# 26th of May, 2008
# Julia Jomantaite <[email protected]>

# 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~/
Expand All @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion sedtris.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ do
let "temp=($RANDOM/10)%7"
if [ $temp == 1 ]
then
echo $temp
#echo $temp
echo
else
echo
fi
Expand Down