 |
 |
 |
 |
| Gamers' Lounge Talk about gaming on Fedora and linux. |

25th December 2011, 01:29 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 4,979

|
|
|
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.
|

26th December 2011, 01:21 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

2nd January 2012, 12:10 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

7th January 2012, 05:00 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

7th January 2012, 06:14 PM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300

|
|
|
Re: 【Tetris Game -- based on a shell script】(new algorithm)
Quote:
Originally Posted by huaihaizi3
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
|

8th January 2012, 04:15 AM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

|
|
|
Re: 【Tetris Game -- based on a shell script】(new algorithm)
Quote:
Originally Posted by stevea
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.
|

10th January 2012, 03:28 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

21st January 2012, 06:18 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

6th February 2012, 03:21 AM
|
 |
Registered User
|
|
Join Date: May 2009
Location: Manorville, New York, USA
Posts: 1,579

|
|
|
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 17/18, siduction and openSUSE Tumbleweed with KDE
|

5th March 2012, 01:49 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

8th March 2012, 06:39 AM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

14th March 2012, 02:14 AM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

19th March 2012, 01:50 AM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

1st April 2012, 05:26 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

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

17th April 2012, 06:24 PM
|
 |
Registered User
|
|
Join Date: Nov 2009
Location: BeiJing China
Age: 26
Posts: 27

|
|
|
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}
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 14:53 (Wednesday, 22-05-2013)
|
|
 |
 |
 |
 |
|
|