Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

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

Shell Programming and Scripting


Tags
tetris game shell algorithm yongye

Reply    
 
Thread Tools Search this Thread Display Modes
    #22  
Old Unix and Linux 01-09-2012
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 19 January 2017, 8:48 PM EST
Posts: 3,332
Thanks: 135
Thanked 1,137 Times in 1,058 Posts
Here is a version of maxxy() that dosn't use the xargs or awk externals:


Code:
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
}


Last edited by Chubler_XL; 01-09-2012 at 11:02 PM.. Reason: Make i a local var to
Sponsored Links
    #23  
Old Unix and Linux 01-09-2012
complex.invoke's Unix or Linux Image
complex.invoke complex.invoke is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 30 December 2015, 11:56 PM EST
Location: BeiJing China
Posts: 236
Thanks: 6
Thanked 29 Times in 8 Posts
Quote:
Originally Posted by Chubler_XL View Post
Here is a version of maxxy() that dosn't use the xargs or awk externals:
Perfect Code!
a better optimization:

Code:
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!

Last edited by complex.invoke; 01-10-2012 at 03:49 AM..
Sponsored Links
    #24  
Old Unix and Linux 01-09-2012
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Last Activity: 7 April 2014, 3:02 PM EDT
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 511 Times in 490 Posts
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.
    #25  
Old Unix and Linux 01-10-2012
complex.invoke's Unix or Linux Image
complex.invoke complex.invoke is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 30 December 2015, 11:56 PM EST
Location: BeiJing China
Posts: 236
Thanks: 6
Thanked 29 Times in 8 Posts
Quote:
Originally Posted by agama View Post
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!
Sponsored Links
    #26  
Old Unix and Linux 01-10-2012
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 22 January 2017, 1:51 AM EST
Location: Asia pacific region
Posts: 13,466
Thanks: 821
Thanked 1,079 Times in 508 Posts
Quote:
Originally Posted by vbe View Post
Neo,
I got it working on my powerbook (G4 1.67Ghz..) with bash and macOSX10.5.6 though a bit buggy.. but display quite some funny figures! Look to me it will be hard work to debug because of the figures produced...
Yah.. I think the terminal width may not be large enough on my 13" MBA.....
Sponsored Links
    #27  
Old Unix and Linux 01-10-2012
complex.invoke's Unix or Linux Image
complex.invoke complex.invoke is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 30 December 2015, 11:56 PM EST
Location: BeiJing China
Posts: 236
Thanks: 6
Thanked 29 Times in 8 Posts
I added runlevel support, now it's so easy to play with, just enjoy it, my friends!

Last edited by vbe; 01-10-2012 at 02:34 PM.. Reason: added word support,so to rm dupl message
Sponsored Links
    #28  
Old Unix and Linux 01-21-2012
complex.invoke's Unix or Linux Image
complex.invoke complex.invoke is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 30 December 2015, 11:56 PM EST
Location: BeiJing China
Posts: 236
Thanks: 6
Thanked 29 Times in 8 Posts
Tetris Game Version 5.0 released!
Added comments!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Is there picture based game under linux terminal? vistastar UNIX for Dummies Questions & Answers 18 09-02-2011 01:57 AM
text based football game? dadoprso UNIX for Dummies Questions & Answers 1 04-22-2010 01:32 PM
calling 'n' number of shell scripts based on dependency in one shell script. shashi369 Shell Programming and Scripting 1 11-03-2009 05:31 PM
Need to Write Shell Script based off of this shell command Rally_Point Shell Programming and Scripting 3 06-10-2009 06:19 PM
Shell Script Poker Game earnstaf Shell Programming and Scripting 8 03-11-2008 12:46 PM



All times are GMT -4. The time now is 12:24 PM.