Slot Machine Project Statistics 3 Bars

I was bored and that can be a dangerous thing. Like doodling on the phone book while you are talking on the phone, I doodle code while answering questions on DIC. Yeah, it means I have no life and yes it means I was born a coder. During this little doodle I decided to make a slot machine. But not your standard slot machine per say, but one designed a little bit more like the real thing. Sure it could have been done a little more simpler and not even using a Wheel class at all, but what fun is that? In this entry I show the creation of a slot machine from a bit more of a mechanical aspect than a purely computerized one. It should provide a small sampling of classes and how they can represent real life machines. We cover it all right here on the Programming Underground!

So as I have already said, this little project was just something to play around with. It turned out kinda nice, so I thought I would share it. But what did I mean about it being mechanical in nature? Well, if you have ever played a real slot machine, not the digital ones they have in casinos now, you would see a metal case with a series of wheels. Typically it would be three wheels with pictures on them. When you put your money in and pull the handle the wheels would be set into motion. They would spin and then the first wheel would stop, followed by the second and then the third. After they have all stopped, the winnings are determined and you are paid out in coinage or credits.

The bar symbol has also survived the test of time and nowadays is often modified to double bars, triple bars, and so on. Despite the preservation of many classic symbols, plenty more have been birthed by the imagination of slot-machine developers, ranging from fruits, numbers, cars, logos, letters, animals, and many more. Most people look at the vast array of casino slot machines and assume they are all alike. They see a handle, a coin slot, flashing lights and figure one is as good as another. However, in making this assumption, they fail to see a lot of valuable information to help determine if they should play a particular slot machine. This large scale replica slot machine comes with casino sounds, flashing jackpot light and chrome trim. It also doubles as a bank with separate savings section. Overall Dimensions: 15' H x 8.75' W x 6' D; Overall Product Weight: 6lb. This was a birthday gift for my husband.

I thought, why not be a bit mechanical in this slot machine design and create the wheels as a class called “Wheel” and give it the ability to spin independently of the other wheels? Have the wheel keep track of which picture (or in our case number) is flying by and report the results to the actual slot machine class. I could have done this mechanism without the need of a wheel at all and instead load up an array and have it randomly pick a number from the wheel. Little slimmer, little more efficient but wouldn’t show much programming theory.

What do we gain by recreating these Wheel classes and spinning them independently? Well, you gain a slight bit of flexibility. Independently we are able to control the speed of the spinning if we wanted to, we are able to grasp the idea of the wheel as a concept in our mind and manipulate it. We could easily built in features like if the wheel lands on a certain number it will adjust itself. Like some slots in Vegas, if you land on lets say a rocket in the center line, the machine would see the rocket and correct the wheel to spin backwards 1 spot (in the direction of the rocket as if the rocket was controlling the wheel). We could spin one wheel one way and another wheel another. We could inherit from that wheel and create a specialized wheel that does a slew of new different behaviors. All encapsulated into one solid object making the actual Machine class oblivious to the trickery of the wheel itself… encapsulation at its finest!

The machine class we create will contain 3 pointers. Each to one of the wheels. The machine itself will be in charge of a few different tasks. Taking money, issuing and removing credits, determining when to spin, telling each of the wheels to spin and checking our winnings based on some chart we create. It has enough on its plate than worrying about the wheels and reading their values.

So lets start with our Wheel class and its declaration/implementation…

wheel.h

As you can see the wheel itself is not a difficult concept to envision. The bulk of the work is in the read() method. Here we simply read the values from our internal array of integers (the values on the wheel) and return those values as an array of the three integers… representing the visible column. This column will then be loaded into our 2-Dimensional Array back in the Machine class. The 2D array represents the view or screen by which the user sees the results. Remember that the user never gets to see the entire wheel. Only the 3 consecutive values on the face of the wheel.

Here is how it may look in the real world. We have our machine with the three wheels and our 2D array called “Screen” which acts as our viewing window. Each wheel will report its values and those values will be put into the screen…

Below is our machine class…

machine.h

This looks like a lot of code but really it is not if you look at each function. Most of them are very very simple to understand. We have a spin method which essentially spins each of the wheels, reads their values back from the Wheel class into a pointer (representing each column), then they are loaded into the 2D array one column at a time (our view screen), printed for the user to see the results and lastly the winnings are checked. The checkwinnings() method determines which rows to check based on the amount of the bet. If they chose 1 line, it checks for winning combinations on the middle row only. If they choose 2 lines, it checks the middle and top lines, 3 line bet checks all three horizontal rows, 4 line bet checks the first diagonal as well and 5 line bet checks both diagonals in addition to the lines.

How does it check the lines? Well each line is given to the checkline() helper function which compares the 3 values of the line against an enumerated type of various symbols. Here we are just assigning a symbol against each numbered value to help the programmer determine which numbers correspond to which winning combos. For instance, luckyseven represents the number 3 in the enumeration. So if it runs across a line with 3 number 3s, then it knows it hit the grand jackpot and credits the player 1000. This method makes things easy because if we ever wanted to change the win patterns later, we could change the enum and checkline method to do so. We could also build in multiple types of symbols and even let the user choose what slot machine game they want to go by. It becomes very flexible and is a testament to great design!

Lastly we can put some tests together just to show some the various aspects of how this thing works and how the programmer can use the classes…

slotmachine.cpp

This simply inserts a 5 dollar bill and a coin for good luck. Then bets 5 lines and spins. Despite the outcome we go and bet five lines again and spin once more. Hopefully we win something this time around! But either way, those are the classes for you and I hope you like them. As always, all code here on the Programming Underground is in the public domain and free for the taking (just don’t cause a mess in isle 3, I am tired of running out there for cleanup). Thanks for stopping by and reading my blog. 🙂

Yi Zhang
with
Susan Finger
Stephannie Behrens

Table of Contents

1. Linkage mechanisms

1.1 Four bar linkages

Linkage are composed of links andlower pairs. The simplestclosed-loop linkage is the four-bar linkage, which has three movinglinks, one fixed link and four pin joints. A linkage with one linkfixed is a mechanism. You can load the following four-barlinkage into SimDesign from the file mechanisms/fourbar.sim.

This mechanism has three moving links. Two of them are pinned tothe frame, which is not shown in this picture. In SimDesign, you cannail these two links to the background.

How many degrees of freedom(DOF) does this mechanism have? If it has one, you can impose oneconstraint on the mechanism for it to have definite motion. Forexample, you can pull the nailed link on the left (making it theinput link) and it will turn around the nail. The right link(now the output link) will make an oscillating motion. Supposeyou put a pen on the top of the triangle-shaped link. (The triangleis also called a link. A link is not necessarily a simple line-shapedbody). The pen will trace its path. The triangle-shaped link connectsthe two moving pivots and couples the input and the output motion;hence, it is called coupler.

Linkages have different functions. The functions are classifieddepending on the primary goal of the mechanism:

  • Function generation: the relative motion between the linksconnected to the frame,
  • Path generation: the path of a tracer point, or
  • Motion generation: the motion of the coupler link.

1.1.1 Crane

An application of path generation is a crane in which an approximatehorizontal trace is needed.

1.1.2 Hood

An example of motion generation is a hood which opens and closes.

1.1.3 Parallelogram mechanism

In a parallelogram four-bar linkage,the orientation of the coupler does not change during the motion.The figure illustrates a loader.

1.2 Slider-crank mechanisms

The four-bar mechanism has some special configurations created bymaking one or more links infinite in length. The slider-crank (or crank andslider) mechanism shown below is a four-bar linkage with a slider replacingan infinitely long output link.

Pull the crank of this mechanism and you will see that it transfersrotary motion into translation. Most mechanisms are driven by motors,and slider-cranks are often used to transform rotary motion intolinear motion.

1.2.1 Crank and piston

You can also use the slider as the input link and the crank asthe output link. In this case, the mechanism transfers translational motion into rotary motion. The pistons and crank in an internalcombustion engine are an example of this type of mechanism. The correspondingSimDesign file ismechanisms/combustion.sim.

You might wonder why there is another slider and a link on theleft. This mechanism has twodead points. Theslider and link on the left help the mechanism to overcome these deadpoints.

1.2.2 Block feeder

One interesting application of slider-crank is the blockfeeder. The SimDesign file can be found inmechanisms/block.feeder.sim

2. Cam mechanisms

Linkages, while useful, cannot achieve all possible motions. Forexample, if the output link must remain stationary for acertain period of time while the input link keeps turning, linkagescannot be used. Cam mechanisms can realize any required outputmotion. The composition of a cam mechanisms is simple: a cam, afollower and a frame. (You may find springs used in a cam mechanism tokeep the follower and the cam in contact, but it is not part of thecam mechanism.)

2.1 Rotating cam/Translating follower

If you turn the cam, the follower will move. The weight of thefollower keeps them in contact. This is called a gravityconstraintcam.

2.2 Rotating cam/Rotating follower

The SimDesign file is mechanisms/cam.oscillating.sim. Noticethat aroller is used at the end of the follower. In addition, a spring isused to maintain the contact of the cam and the roller.

Slot

If you try to calculate the degrees offreedom (DOF) of the mechanism, you must imagine that the rolleris welded onto the follower because turning the roller does notinfluence the motion of the follower.

3. Gears

There are many kinds of gears. Thefollowing examples are involute spur gears. We use the wordinvolute because the contour of gear teeth curves inward.There are many terminologies, parameters and principles for gears.One of the important concept is the velocity ratio, which isthe ratio of the rotary velocity of the driver gear to that of thedriven gears.

The number of teeth in these gearsare 15 and 30, respectively. If the 15-tooth gear is the driving gearand the 30-teeth gear is the driven gear, their velocity ratio is 2.

An example of a set of gears is in mechanisms/gear10.30.sim.

3.1 Rack and pinion

When the number of teeth of a gear becomes infinite, the center ofthe gear goes to infinity. The gear becomes a rack. The followingpicture shows a rack and pinion. The corresponding SimDesign file ismechanisms/gear.rack.sim.

Slot Machine Project Statistics 3 Bars Using

You can pull the pinion so that it turns and drives the rack. Youcan also pull the rack along the guide and drive the pinion.

3.2 Ordinary gear trains

Gear trains consist of two or more gears that transmit motion fromone axis to another. Ordinary gear trains have axes, relative to theframe, for all gears comprising the train.

3.3 Planetary gear train

The SimDesign file is mechanisms/gear.planet.sim. Since the sungear(the largest gear) is fixed, the DOF of the above mechanism is one.When you pull the arm or the planet, the mechanism has a definitemotion. If the sun gear isn't frozen, the relative motion isdifficult to control.

4. Miscellaneous mechanisms

4.1 Ratchet mechanism

Free Bar Slot Machine

A wheel with suitably shaped teeth, receiving an intermittent circularmotion from an oscillating member, is aratchet wheel. The figure below shows a simple ratchetmechanism.

A is the ratchet wheel, and B is an oscillating link. Attached to Bis a pawl which is a link designed to engage with the ratchetteeth to prevent the wheel from moving in one direction. Thismechanism has a supplementary pawl at D. When the link B moves in acounterclockwise direction, the pawl C pushes the wheel through apartial rotation. When the link B moves clockwise, the pawl C slides over the points ofthe teeth while the wheel remains at rest because of the fixed pawl D.The amount of backward motion possible varies with the pitch of theteeth. The smaller the teeth, the smaller the backward motion. Thecontact surfaces of wheel and pawl should be inclined so theydon't disengage under pressure.

Free bar slot machine

The corresponding SimDesign file is mechanisms/ratchet.sim. Thefour-bar linkage on the right generates an oscillating rotation forlink B. Pull the crank to watch the ratchet work.

4.2 Geneva Wheel

An interesting example of intermittent gearing is the Geneva Wheel.

In this mechanism, for every turn of the driver wheel A, the drivenwheel B makes a quarter turn. The pin, attached to driver wheel A,moves in the slots causing the motion of wheel B. The contact betweenthe lower part of driver A with the corresponding hollow part of wheelB, retains it in position when the pin is out of the slot. Wheel A iscut away near the pin as shown, in order to provide clearance forwheel B as it moves. If one of the slots is closed, A can make lessthan one revolution in either direction before the pin strikes theclosed slot, stopping the motion. Early watches, music boxes, etc.,used Geneva wheels to prevent over winding. From this application,they also are called Geneva Stops. As a stop, wheel A is fastened tothe spring shaft, and B turns on the axis of the spring barrel. Thenumber of slots in B depends upon the number of times the spring shaftshould be turned.

The SimDesign file for Geneva wheel is 'geneva.sim'.

You may try this mechanism by pulling on the Geneva wheel.

Slot Machine Project Statistics 3 Bars Required

  • 1. Linkage mechanisms
    • 1.1 Four bar linkages
    • 1.2 Slider-crank mechanisms
  • 2. Cam mechanisms
  • 3. Gears
  • 4. Miscellaneous mechanisms
Slot Machine Project Statistics 3 Bars

Slot Machine Project Statistics 3 Bars Near Me