【Tetris Game -- based on a shell script】(new algorithm)
1 Attachment(s)
Hi all, i have successfully developed a shell version of the Tetris Game based on a new algorithm yesterday 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! Rename the attachment Tetris_Game.txt to Tetris_Game.sh before you run it! how to play with it? Code:
bash Tetris_Game.sh [runlevel] [previewlevel] [speedlevel] I made a copy of my source code below: Code:
#!/bin/bash |
Your effort is quite impressive. Sadly, after a short period of play, I got a repeated series of error messages, followed by a process termination:
Code:
./tetris.sh: cannot make pipe for process substitution: Too many open files I will find it interesting to study your code, as I've never seen a shell script operate in such an interactive way. --- rod. |
Mad props!
I'm quite pleased with seeing this kind of stuff in bash. I'm too inclined to think about games and other seemingly "unrealizable" things written in it, "for the lulz", because of the challenge, and to bother all those people that always whine "use another laaanguaaaaage" :tisk:. I hope to take some time whenever I can to help enhance the program. One thing that would be cool to add is dual mode playing, you know like the original Tetris where two players had half screen. Was fun hehehe. Didn't look in depth, but more or less how many processes are running while the game is playing? And also, at a glance, I see you use few parameter substitutions, arguably your best chance in bash at minimizing calls to external programs (if that would be absolutely necessary though, I'll probably calling "sed"). Perhaps some tweaking in some of the multi-pipe lines might speed it up a little, and be related to the "many open files" ? Also, can you write a bit on your approaches, and any tricky parts (any amount would be helpful) to speed up grasping the script? |
My script is the shell version of the classic Tetris Game!
It runs pretty well under Fedora15, and you can see the screenshot from the link that i have already given above: http://bbs.chinaunix.net/thread-3614425-1-1.html |
Quote:
Quote:
|
Quote:
bash $0 0 &--the one that running in the background, and getsig $!--the one that running in the current shell, this function takes the $! as the parameter and it sends the input signals to the processes that running in the background, this is the way that the two processes communicate! My laptop is running Fedora15, and this script runs pretty well under it,the multi-pipe lines are most needed and necessary; in fact i have optimized my script as much as possible, as you can see that i have used so many function invocations, that is to say, the matter that result in "many open files" is mainly due to the distro of you Linux, not the multi-pipe lines! For a better way to speed up the script, i know ,and i'm trying! I'll add a detailed comments to the code when i'm free! |
I made some changes to the source code just now!
|
Tetris Game Version 2.0 Beta1 released
|
Hey the code looks so much better this time! Bet that it runs way smoother than version 1. Congrats man! Still haven't found the time to play with the code, but I definitely want to.
|
I have the source code optimized once again just now!
|
Amazing!
I always marveled at what could be done in sh, but this opened my eyes!
I ran Code:
ulimit -n30000 After a while of having my mind blown, I started to get this: Code:
./tetris: line 590: warning: run_pending_traps: bad value in trap_list[26]: (nil) Lyle. |
Just run the script this way:
Code:
bash Tetris_Game.sh Code:
./tetris: line 590: warning: run_pending_traps: bad value in trap_list[26]: (nil) The code below: Code:
concxy() But, it seems nothing wrong with those code, as i have debugged it so much! Any good solutions that can fix the bug will be appreciated! I need all your participation! Join me, why not? |
Quote:
Why don't you make your code friendlier? It won't impact in performance. That way you'll encourage participation. |
Tetris Game Version 2.0 Beta2 is available now!
|
Tetris Game Version 2.0 Beta3 released!
Features: 1.Bomb is enabled(ID=2)! 2.Customization is enabled under the given value range of coordinates! 3.Various kinds of color(64 kinds of color are available for randomly choose)! 4.Support 4-level preview(can preview the next 4 pieces generated randomly)! The final version is coming soon! |
All times are GMT -5. The time now is 11:44 AM. |