[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
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 & TechniquesBrowsing through my "Future Project" folders the other day, one named "Slot
machine" caught my eye. it included this email: From: Shane [********@charter.net] 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 ProgrammersIt 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:
Version 2, posted today, implements these changes. Running/Exploring the Program
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |