domenica 4 marzo 2012

Rock-Paper-Scissors Game for Bash Terminals

Maybe the Rock-Paper-Scissors is the most knew hand game of the world, specially by kids, used to toss up or as pastime. The name goes up from the three gestures used in the game: two players keep a hand closed; they count aloud to three and each time raising one hand in a fist and swinging it down on the count. At the third time (when they say "Scissors!") the players change their hands into one of three gestures:

  • Rock: expressed as a clenched fist
  • Scissors: represented by two fingers separated
  • Paper: expressed ad an open hand with all finger extended
The winner is determined by these simple rules:

  • Rock beats scissors
  • Scissors beats paper
  • Paper beats rock
  • Rock versus rock, scissors versus scissors, paper versus paper results in a draw
You often (or not xD) doesn't have a friend to play with. So, for me, I've write a simple bash/C application to play Rock-Paper-Scissors with your PC. It is so rough, but funny too!
Download the .tar.gz package (by link below) and extract it; after you have to compile the whowins.c file (you can do this simply launching gcc -O3 -o whowins whowins.c on your terminal). Now you can execute rps.sh as script specifying rock (or 1), paper (or 2), scissor (or 3) or random to play versus PC.
Eventually I'll develop a Java porting for all non-unix like platform (maybe with a GUI).



The package contains:

  • align.sh, center.sh and rps.sh: bash scripts  to prepare the environment and align the text
  • whowins.c: a C dummy program that establishes who player wins
  • strings: contains a "raw" configuration strings (be careful to change it, let the lines into the original ordering)


Enjoy

Download Rock-Paper-Scissor Game for Bash terminal