Work the Shell - End Game

Want to bet you can find a problem in our final Blackjack script?
There's Still a Bug

There's also one outstanding bug in the code, and I invite you to dig around and figure it out. If the dealer is dealt an Ace in play, it's automatically counted as 11 points, not one or 11, as it should be. Your challenge: figure out where that problem arises and how to fix it. If you think you know, e-mail me your proposed solution (perhaps a diff of your version versus the version on the Linux Journal FTP site), and we'll see how you did.

Next month, we'll crack open a completely different shell script task and see what we can do to help your day-to-day Linux administrative tasks, because we've probably wasted plenty enough ink on a casino game for this year! See ya then.

Dave Taylor is a 26-year veteran of UNIX, creator of The Elm Mail System, and most recently author of both the best-selling Wicked Cool Shell Scripts and Teach Yourself Unix in 24 Hours, among his 16 technical books. His main Web site is at www.intuitive.com.

______________________

Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Some improvements

freefox's picture

Here is one solution for the Ace problem. Note that it increases the probability to exceed the hard coded value of 5 cards in a hand.

The other stuff are just to make the program run smoother.

/freefox

> aces=0 # number of Ace in the hand
107,108c108,110
< 0|11|12 ) rankvalue=10 ;;
< 1 ) rankvalue=11 ;;
---
> 0|11|12 ) rankvalue=10 ;;
> 1 ) rankvalue=11
> aces=$(( $aces + 1 )) ;;
111a114,118
>
> if [ $handvalue -gt 21 ] && [ $aces -gt 0 ] ; then
> handvalue=$(( $handvalue - 10 ))
> aces=$(( $aces - 1 ))
> fi
123a131,133
> echo ""
> echo "------ $dealerwin <-- dealer -- player --> $playerwin ------"
>
156c166,167
< exit 0
---
> dealerwin=$(( $dealerwin + 1 ))
> continue
162c173,174
< exit 0
---
> dealerwin=$(( $dealerwin + 1 ))
> continue
166c178,179
< exit 0
---
> playerwin=$(( $playerwin + 1 ))
> continue
197,198c210,215
< if [ "$answer" = "stand" -o "$answer" = "s" ] ; then
< break
---
> ## To go for the obious choice, when no answer,
> ## the recommended value are analysed ones more.
> if [ "$answer" = "" ] && [ $handvalue -gt 15 ] ; then
> break
> elif [ "$answer" = "stand" -o "$answer" = "s" ] ; then
> break
222c239
< break
---
> continue
271,273d287
< echo ""
< echo "---------------------------------------------------"
<

What about a licens?

freefox's picture

It's a gaim. It's code. It's been published.
You encourage downloads. You ask for updates.

Why not put a licens on it? GPL?

/freefox

Free Dummies Books
Continuous Engineering

Learn:

  • What continuous engineering is
  • How to continuously improve complex product designs
  • How to anticipate and respond to markets and clients
  • How to get the most out of your engineering resources

Get your free book now

Sponsored by IBM

Free Dummies Books
Service Virtualization

Learn to:

  • Define service virtualization
  • Select the most beneficial services to virtualize
  • Improve your traditional approach to testing
  • Deliver higher-quality software faster

Get your free book now

Sponsored by IBM