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

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState