BASH games

bash-gaming-script

Get serious about your shell scripting skills and maybe you can pull this one off. It’s a game of snake played in a BASH shell. It seems like a coding nightmare, but the final product turns out to be organized well enough for us to understand and took less than 250 lines of code.

[Martin Bruchanov] started on the project after pining for an old DOS game called Housenka. It’s another version of the classic Snake game which we’ve coded ourselves and seen in several projects including this head-to-head version using musical recorders as controllers. When using a terminal emulator capable of ANSI sequences the game is displayed in color using extended characters.

We give [Martin] bonus points for the way he wrote about his project. It describes the mechanics most would be interested in, like how the user input is captured and what drives the update function and food generation. The rest of the details can be gleaned by reading through the code itself.

Comments

  1. “Lets play: CLI snake over 300 baud serial line”

  2. Papa Smurf says:

    I guess well done… but really it is just another example of bash being used where a compiled application should have been. I wonder how much quicker a Linux machine would be if all it’s start-up scripts were replaced with real applications.

  3. geekmaster says:

    For really bent shell scripts, here are some scripts that draw binary pixels directly to a Kindle eink framebuffer (native eink algorithmic art shell scripting):

    http://www.mobileread.com/forums/showthread.php?t=172182

  4. geekmaster says:

    And here is one that also draws to the eink framebuffer, and also reads the binary input events for the Kindle Touch touchscreen, letting you draw on the screen with your finger (and save the results out to a display list file):

    http://www.mobileread.com/forums/showthread.php?t=178356

    The point is, a number of people had fun contributing to that as a sort of puzzle to see just how much you can bend a shell script to your will, doing things that many thought was limited only to “real” programming languages.

  5. jason says:

    Are you kidding me?? As soon as my score broke 999,999, all hell broke loose. What a waste of six hours :(

  6. jimmy says:

    Check out these games written in sed!

    http://sed.sourceforge.net/#gamez

  7. t&p says:

    this has been done before… I made a hearts game in a CS class using escape codes to change the background and foreground to make the output look like cards….
    there are also ascii demos that kick ass. they use an ascii filter on a bitmap.
    hell, speaking of ascii filters, you can make this kind of stuff in gimp

  8. How is he getting away with $[] in lieu of $(())? I can’t find the $[ ] syntax documented anywhere. If I find that it words without side effects, though, I’m stealing that idea for use in my own code.

    He also reminded me that the “:” nop can take args, so I can hide arithmetic side effects there.

    You learn something new every day.

  9. tilaprimera says:

    enjoyed playing it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 94,499 other followers