# Work the Shell - End Game

in
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.

## Comment viewing options

### Some improvements

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 "---------------------------------------------------"
<

It's a gaim. It's code. It's been published.

Why not put a licens on it? GPL?

/freefox