Tetris Game -- based on a shell script (new algorithm)

It works for me in RHEL 5, but not in RHEL 4. :confused:

Nonetheless, it's an awesome work.

Edit: These are the versions I'm using:

# Does NOT work here
[verdepollo@atlas ~]$ cat /etc/redhat-release && bash --version
Red Hat Enterprise Linux AS release 4 (Nahant Update 8)
GNU bash, version 3.00.15(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

# Works flawlessly here:
[root@eve tmp]# cat /etc/redhat-release && bash --version
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Edit 2: Also, it seems to work only when using GNU sleep.

Here is a version of maxxy() that dosn't use the xargs or awk externals:

maxxy()
{
    local i a b
    set -- ${box[@]} 
    while [ $# -gt 0 ]
    do
       [ 0${a[$2]} -lt $1 ] && a[$2]=$1
       b[$2]="${a[$2]} $2"
       shift ; shift
    done
    for i in "${b[@]}"
    do
       echo $i
    done
}

Perfect Code!
a better optimization:

maxyx()
{
   local i a b
   set -- ${box[@]} 
   a[$2]=${1} 
   b[$2]="${1} ${2}" && shift 2
   while (( ${#} > 0 ))
   do
        (( a[$2] < ${1} )) && a[$2]=${1}
        b[$2]="${a[$2]} ${2}"
        shift 2
   done
   echo ${b[@]}
}

Thank you!

Nice job. Looks good with bash 3.2.39 under a very out-dated (11.1) SUSE Linux and bash 4.1 under FreeBSD 8.2.

The only bug I've noticed is that a single block (1x1) always seems to go through the pile to the bottom. Maybe it's designed that way, but that seems odd if it is.

That isn't a bug! It's designed that way specially as the feature
Across area moving(ID=0)!

---------- Post updated 01-10-12 at 05:19 AM ---------- Previous update was 01-09-12 at 11:03 PM ----------

Updated the maxxy function to maxyx function!

Yah.. I think the terminal width may not be large enough on my 13" MBA.....

I added runlevel support, now it's so easy to play with, just enjoy it, my friends!

Tetris Game Version 5.0 released!
Added comments!

Where is it? The URL at the top of the thread is version 4.

Also, the pieces leave a trail on the play area: http://t.cfaj.ca/bash-tetris.jpg

The attachment is already available now(the latest version 5.0)!
Please wait a moment for the link
http://bash.webofcrafts.net/Tetris_Game.sh to be updated!(I've mailed Mendel(author of the Advanced Bash-Scripting Guide))

The trail mabye some issues releated with your SSH client tools but not my script as it runs pretty well under Xshell, Gnome Terminal, putty,SecureCRT etc!
Just keep your ssh client tools more newer version!

Very nice! The code is also very well explained too. Would be nice to have time and learn it.

IF u wrote the code from scrap .. I SALUTE YOU!

Of course, the whole algorithms and codes were designed and developed all by myself!
Version 6.0 will be released at 12/12/2012, better architecture, better optimization and new features!
Just waiting for me!

to pause the game just stuck in the wall

Tetris Game Version 6.0 Beta1 is available now

1 Like

Updated 6.0 Beta1

tetris.txt contains 5 version
is it possible to make usual figures?

what do you mean?

i mean

xx
xx

xx
x
x

x
xx
 x

xxxx

 x
xxx

etc

The variable mrx defines the unit of the pieces, the current value of mrx is [] ;
if you replace [] with xx (double x) ; then the [] will become xx , [][][][] will become xxxxxxxx etc, this way, you needn't to change anything else to the code, but if you want to change the code just as you have said that get

[]
[][]
[]

to

x
xx
x

(replace the [] with single x ), you must to change a lot of the source code(the value of the elements of the box arrays and some coordinates transformation functions),
as you can see that, the current subtraction between arbitrary vertical coordinates of the pieces is 2n, in your way ,the value of subtraction is n!