Fedora Linux Support Community & Resources Center
  #16  
Old 25th December 2011, 01:29 PM
smr54 Online
Registered User
 
Join Date: Jan 2010
Posts: 5,499
linuxchrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Thanks for adding the attachment--honestly, I think it's a good idea. It works for me, so I'm guessing something went wrong with trying to copy it from the web link.

(I should add, it works with bash Tetris_Game.sh, but does NOT work with sh Tetris_Game.sh. Nothing wrong with that of course, it's a bash script, not a /bin/sh script).

Thanks for your efforts, and thank you for creating it as an attachment.
Reply With Quote
  #17  
Old 26th December 2011, 01:21 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

I added some New code!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #18  
Old 2nd January 2012, 12:10 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 4.0 ---Final Version released!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #19  
Old 7th January 2012, 05:00 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

new updates!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #20  
Old 7th January 2012, 06:14 PM
stevea Online
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,798
linuxfedorafirefox
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Quote:
Originally Posted by huaihaizi3 View Post
Hi all, i have successfully developed a shell version of the Tetris Game based on a new algorithm few days ago all by myself, below is the link of the source code that i posted at a Linux/Unix forum the first in China:
http://bbs.chinaunix.net/thread-3614425-1-1.html
I'd love to know that someone can be able to optimize my source code and enhance it!

Nice game.

The bash coding style is good. Good clear names and a good attempt to decompose the task into utility functions. I might have made a different decomposition - but that's a matter of the specifics of the goal.

Criticism: Are sed & awk needed ? Have you looked for a bash feature instead ? For example this sort of thing is very awkward ..
echo -e "$(sed 's/\[\]/ /g' <(echo ${oldbox}))\e[0m";
might be replaced with the bash pattern substitution ${parameter/pattern/string}.

The screen codes are non-portable. Things like this ....
echo -e "\e[?25h\e[36;4H"
only apply to VT100 terminals and xterms that emulate these. Better to use the 'tput' function to access curses. tput can give you the portable strings to position the cursor, set color foreground and background ,set bold, normal etc. like tput cup 35 3 .




--------

Quote:
When the thought has been dominated by a scientific sense, is influenced by a rational concept, the fate of the result will change the trajectory of life will also be moving in the direction of extension of the successful
I imagine that made a lot more sense before translation
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #21  
Old 8th January 2012, 04:15 AM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Quote:
Originally Posted by stevea View Post
Criticism: Are sed & awk needed ? Have you looked for a bash feature instead ? For example this sort of thing is very awkward ..
echo -e "$(sed 's/\[\]/ /g' <(echo ${oldbox}))\e[0m";
might be replaced with the bash pattern substitution ${parameter/pattern/string}.

The screen codes are non-portable. Things like this ....
echo -e "\e[?25h\e[36;4H"
only apply to VT100 terminals and xterms that emulate these. Better to use the 'tput' function to access curses. tput can give you the portable strings to position the cursor, set color foreground and background ,set bold, normal etc. like tput cup 35 3 .
Thank you!
Good advices!
There is a better solution that can replace the maxxy function
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[@]}
}
I also replaced the sed with the bash pattern substitution, just as you said ,it's better to use the shell builtin features!
For the issue of portable, i'm sorry ,i have no much time to deal with it!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}

Last edited by huaihaizi3; 10th January 2012 at 08:06 AM.
Reply With Quote
  #22  
Old 10th January 2012, 03:28 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

I added runlevel support!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #23  
Old 21st January 2012, 06:18 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 5.0 released!
Added comments!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #24  
Old 6th February 2012, 03:21 AM
GoinEasy9 Offline
Registered User
 
Join Date: May 2009
Location: Manorville, New York, USA
Posts: 1,674
linuxfirefox
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Just got a chance to look at it again. Even better now with runlevel support. Thanks.
__________________
Registered Linux User #348347
Have you been seduced by siduction? http://siduction.org/index.php
Running Fedora 19/20, siduction and openSUSE 13.1 with KDE
Reply With Quote
  #25  
Old 5th March 2012, 01:49 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_8chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 6.0 Beta1 is available now: https://github.com/yongye/shell
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #26  
Old 8th March 2012, 06:39 AM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_8chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Updated 6.0 Beta1
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #27  
Old 14th March 2012, 02:14 AM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_8chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 6.0 Beta2 released!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #28  
Old 19th March 2012, 01:50 AM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_8chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 6.0 Beta3 released!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #29  
Old 1st April 2012, 05:26 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_8chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 6.0 Beta5 released!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
  #30  
Old 17th April 2012, 06:24 PM
huaihaizi3 Offline
Registered User
 
Join Date: Nov 2009
Location: BeiJing China
Age: 27
Posts: 27
windows_7chrome
Re: 【Tetris Game -- based on a shell script】(new algorithm)

Tetris Game Version 6.0 released!
__________________
Fibonacci(){ m=${1}; n=m; { { (( ${!n} == 1 )) && echo 0; } || { (( ${!n} == 2 )) && echo 1; }; } || echo $(($(Fibonacci $((${!n}-1)))+$(Fibonacci $((${!n}-2))))); }; Fibonacci ${1}
Reply With Quote
Reply

Tags
&#tetris, &#tetris, algorithm, based, game, script&#new, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script - actions based on file type MichaelS-R Programming & Packaging 3 5th December 2008 11:38 AM
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 10:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 09:30 PM
Shell game CrystalCowboy Using Fedora 0 4th April 2006 04:42 PM


Current GMT-time: 16:18 (Friday, 29-08-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat