Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: ImJustAnotherOkie
There are a lot of Unix/Lunix scripting tools out in the wild. Microsoft is trying to bring some sanity to the world.

Sanity? I'd call it hegemony. If they'd simply port the commands to Linux, bash would be all we'd need. You can pretty much do anything with Bash.

Here's a bash script that will play a round of Bunco...

#!/bin/bash

rolldie()
{
   local result=$1
   rolled=$(( ( $RANDOM % 6 ) + 1 ))
   eval $result=$rolled
}

BuncoRound()
{
   # roll, display, and score a round of bunco!
   # round is specified when invoked, score added to totalscore
 
   local score=0 ; local round=$1 ; local hidescore=0
 
   rolldie die1 ; rolldie die2 ; rolldie die3
   echo Round $round. You rolled: $die1 $die2 $die3
 
   if [ $die1 -eq $die2 ] && [ $die2 -eq $die3 ] ; then
     if [ $die1 -eq $round ] ; then
       echo "  BUNCO! You score 21!"
       score=21
       hidescore=1
     else
       echo "  Mini Bunco! You score 5!"
       score=5
       hidescore=1
     fi
   else
     if [ $die1 -eq $round ] ; then
       score=1
     fi
     if [ $die2 -eq $round ] ; then
       score=$(( $score + 1 ))
     fi
     if [ $die3 -eq $round ] ; then
       score=$(( $score + 1 ))
     fi
   fi
 
   if [ $hidescore -eq 0 ] ; then
     echo "  score this round: $score"
   fi
 
   totalscore=$(( $totalscore + $score ))
}

for round in {1..6} ; do
  BuncoRound $round
done
  echo "Total Score: $totalscore"

For example:

$ bunco
Round 1. You rolled: 2 4 1
  score this round: 1
Round 2. You rolled: 6 1 6
  score this round: 0
Round 3. You rolled: 2 3 2
  score this round: 1
Round 4. You rolled: 4 1 5
  score this round: 1
Round 5. You rolled: 3 3 3
  Mini Bunco! You score 5!
Round 6. You rolled: 1 5 3
  score this round: 0
Total Score: 8

10 posted on 01/12/2018 7:08:35 AM PST by zeugma (I always wear my lucky red shirt on away missions!)
[ Post Reply | Private Reply | To 4 | View Replies ]


To: zeugma
You can pretty much do anything with Bash.

I have increased the productivity of my entire team using just bash and expect. In the range of several hundred percent. I've written scripts that have reduced our time on task from several days down to 15 minutes. As a result, we get a lot more done with a LOT less worries/frustration/stress in our jobs.

13 posted on 01/12/2018 7:19:29 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 10 | View Replies ]

To: zeugma

Not to bash Bash but PowerShell let’s you access just about the all of the .Net functionality directly without having a bunch of little quirky little utilities.


17 posted on 01/12/2018 7:23:53 AM PST by ImJustAnotherOkie
[ Post Reply | Private Reply | To 10 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson