Slot Machine

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

Problem Description

This program displays a simple 3-dial slot machine with a button instead of a handle to "spin" the dials.  It also includes a button to "pull the handle" a million times to measure the win/lose results.  (Not to worry, a million spins take much less than a second to run.)   A separate text section describes the analytical solution for comparison with experimental results.
 

Background & Techniques

Browsing through my "Future Project" folders the other day, one named "Slot machine" caught my eye.  it included this email:
 

From: Shane  [********@charter.net]
Sent: Saturday, March 13, 2004 1:44 PM
To: feedback@delphiforfun.org

Gary,

While helping someone out with a Delphi issue on the Experts-Exchange website,
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20916719.html

I threw this little app together. Instead of letting it fall through the cracks on my next hard drive cleanup, I thought maybe I would pass it on to you to see if you would like to make something out of it.  The question was: "I would like some code to mimic three spinning reels like a poker machine with some images of cherries etc etc, and with all 3 reels spinning reel one stops and reel 2 and 3 continue spinning then reel 2 stops and reel 3 continue spinning then reel 3 stops and pays 2 credits if there are 3 matching images.."

Although my app doesn't have cherries, it does give a visual presentation. My app also pays 5 credits to two matches & ten credits for three matches.  Maybe you can clean it up, make it into something much nicer.... I added the Beeper unit to it to make it have some sound.

Its all yours, do as you like, if you do anything at all. Congrats on the new Grand Child!

Shane

Nine years later, grandson Nathan is doing fine and I decided to post the program nearly the way that Shane sent to to me.   I'm interested  in random processes and simulations and this program provides the opportunity to play with both.   I added a  a text section deriving the theoretical result probabilities. Since each of the dial images are made up of 3 shapes with 6 colors for each, the problem is  the equivalent of drawing three balls with replacement after each draw from a bag of balls numbered 1 through 18 and computing to chances of drawing 2 or 3 with the same number.  I like solving this kind of problem, but always like to check the reasoning that I used in the  process.  For problems from books, the back of the book provide an easy check.  For this and other simulations of real world events, I calculate the probabilities by running many cases and comparing the  simulation results to my analytical results.  In the case there is a  button which runs a million "spins"  and the results support the observed results. 

The world doesn't always arrange itself into a nice tree format.  This program crosses boundaries between Delphi Techniques and Math Topics so I'm posting it as an Intermediate level program in the Projects section but also flagging it with the other categories.     

Notes for Programmers

It defines a TSpinThread control  derived from TThread and TTimers to operate the dials independently which is cool.  ammers    The program uses a TImagelist  control to hold the dial images  which, like TThread controls, is one I haven't used much so I thought it worth while to post this. 

December 2, 2012:  A viewer reported, (and sent a screenshot) of a case which awarded credits for a color and shape match between dials 2 and 3, but the visuals didn't show that.  I could not reproduce the problem but decided that it was possible because when the third timer pops, the thread for that dial is terminated, but if that dial happens to be "spinning" it may update the dial image with results different from what the timer exit code is seeing.  The third timer exit now gives the thread "spin" procedure a chance to finish before checking dial status.   While at it I also added a second slot machine type which pays on three states: 
bulletSingle shape showing (2 or 3 colors),
bulletSingle color showing (2 or 3 shapes)
bulletAll 3 match in color and and shape   

Version 2, posted today, implements these changes.

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source 

Suggestions for Further Explorations

Sound effects for spinning and jackpot
Multiple Play lines
Pay for tow or three of same color/different shape or same shape/different color.
Adjust payoffs to give the house a smaller margin.

 

Original:  October 30, 2012

Modified:  May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.