[EXAMPLE] Slot machine algorithm [updated v2]


#1

This is a functional and adaptable algorithm to display a slot row simulating a slot machine:

Some features that can be modified by changing the value of a variable:

  • Position
  • Number of slots
  • Number of slot symbols
  • Size of sprites
  • Minimum spin time
  • Lapse between slots

Added in v2:

  • Result data stored in a structure
  • Control of probability

Further explanation is in comments, inside the project (the scene don’t have any noticeable objects at design time, just run it and press any key to see what it does :sunglasses: ).

V2:
slot_machine_example_v2.zip (50.9 KB)

:wink:


#2

This is absolutely amazing erdo :mrgreen: !! I was going to reply to tell you that your last example worked perfectly, but then I read the post and I am treated to this :smiley:. I can’t thank you enough for helping me with this example and making a sample for me. You made my day :smiley:. Thank you again!! I am sure I will have more questions regarding help :stuck_out_tongue:, but this is a huge leap forward. Awesome!!!

Take Care
InsertCoin25


#3

Well here we go with my first question :smiley:. What events or variable would I call to show that 2 or 3 of the symbols have a match. For example I have 2 coins and 1 cherry or 3 lucky clovers? I know that the events would have to go something like this:

If variable(slot1) and variable (slot2) and variable(slot3) = variable (lucky clovers)
Do = Something

I just need to know what variable is associated with each individual slot or animation frame. I know it probably sounds confusing and if you need a better example I will try and come up with one. Thank you again erdo!!

InsertCoin25


#4

You can just check the animation frame and not bother using extra variables. This is really easy if you make each slot space a different sprite object (this also can give you control over what is on each individual wheel to make more interesting slot machines).

The animation of slot1 = 0 The animation of slot2 = 0 The animation of slot3 = 0 |--------------------------------| Do +50 to variable money.


#5

You’re right. In fact there is a new version of the algorithm that uses the expression object.Sprite() instead of that variable of mine (̶u̶p̶d̶a̶t̶e̶d̶ ̶s̶o̶o̶n̶) (updated)

Actually, each slot in my example is a different object, even there are custom timers working for each of this objects during the algorithm.

So, it’s not a slot row animation. Is a real algorithm decreasing the velocity of an animation trough time and eventually stopping each slot at different and calculated moments.

Proof of that, you can modify the number of slots by just changing the value of the variable ‘slot_max’ at the start of the scene and then run the project. You will see the number of slots you specify perfectly working (it can be 1, it can be 254… but in that case you will have to wait a lot until the last slot stops the spinning :stuck_out_tongue: ).

The result of each slot is “pre-calculated” since the beginning of the spin for each slot and stored in variable called ‘value’, this variable is present in each slot object (an object variable). So you just have to evaluate if the ‘value’ variables of each slot object have the same, well… value. If all of those have the same value, you have a match.

I’ll help you with that, u̶p̶d̶a̶t̶e̶d̶ ̶s̶o̶o̶n̶ updated in the main post.


#6

New version

Added in v2:

  • Result data stored in a structure
  • Control of probability

Download from the main post.


#7

Looks good!! :smiley:

May I include it to GD examples? :slight_smile:


#8

Yes, please!

:mrgreen:


#9

Added for next release (GitHub commit for developers: github.com/4ian/GD/commit/fff22 … 0311a555ff) :smiley:
Thanks! :slight_smile:


#10

This is amazing erdo!!! Does this also match 2 of the same symbols next to each other and on either side of each other? For example: Diamond - Diamond - Cherry = Match and Diamond - Cherry - Diamond = Match and Cherry - Diamond - Diamond = Match.
I will be studying this tutorial more so I can get a better grasp on things. Amazing work and congrats on getting built into GDevelop, well deserved :smiley:. Let me know about the Matching of 2 Symbols (icons). Thank you.

InsertCoin25


#11

Not exactly… this will be a long explanation:

Here is a super-duper special version of the project for you:

slot_machine_example_v2b.zip (56.6 KB)

It stills don’t evaluates sub-matches (on purpose) but it has a small and useful change: it copies the results stored in the ‘value’ object variable of each slot object to a more accesible variable in the result data structure.

What it means?
Well, it means you can access the result of each slot with this expression:

For the result of the first slot: Variable(result.slot_1)
For the result of the second slot: Variable(result.slot_2)
For the result of the third slot: Variable(result.slot_3)
Etc

So you just need to check if two slots have the same result to see if they match, using a condition.

In this example you are evaluating if the result of the first and second slots are matching (consecutive):

Condition | Variable result.slot_1 is = To Variable(result.slot_2) Action | [Whatever you want...]

And in this another example you are evaluating if the result of the first and third slots are matching (non consecutive):

Condition | Variable result.slot_1 is = To Variable(result.slot_3) Action | [Whatever you want...]

But be careful! Remember: you don’t need to evaluate any sub-matches if you have a full match. So, first check that condition.

On the other hand, if you are NOT planning to use more than 3 slots AND, as you are saying, you want to check for matches in consecutive slots and the slots at the sides of the row THEN you don’t even need to do those evaluations.
Why? Because if there are only 3 slots and you are evaluating sub-matches of 2 different slots then:

  1. There are only three possible positions where a matching pair can be and all of them are valid:
  • The matching icons are on the sides
  • The matching icons are next to each other and are in the slots 1 and 2
  • The matching icons are next to each other and are in the slots 2 and 3

So it’s irrelevant where they are.

  1. There can be only one sub-match (if you have two, it is a full match).

So you don’t need to check for other sub-matches.

So, again… IF YOU WILL ONLY USE 3 SLOTS AND THE SUB-MATCHES YOU ARE CHECKING ARE THE CONSECUTIVES SLOTS AND THE SLOTS AT THE SIDES OF THE ROW… THEN AND ONLY THEN all the answers you’re looking-for are already being calculated by the algorithm… everything is in the variables.

Want to know if there is a sub-match of two slots? Check the variables that holds the number of instances of an icon in the result row, you know…

For the number of instances of the first icon: Variable(result.icon_1)
For the number of instances of the second icon: Variable(result.icon_2)
For the number of instances of the third icon: Variable(result.icon_3)
For the number of instances of the fourth icon: Variable(result.icon_4)
etc

If the value of one of those variables is equal to 2, you have a sub-match (the only one that can exist if you are using only 3 slots).


So I guess you can guess what to do with this.

[b]ADVICE:

READ EVERYTHING I’M SAYING IN THIS POST AGAIN…
READ THE INSTRUCTIONS IN THE COMMENTS OF MY PROJECT…
READ THE GDEVELOP WIKI, THE DEATH SEA SCROLLS, THE POPOL VUH AND THE BRITISH ENCYCLOPEDIA…
AND WHEN YOU FINISH READING IT ALL… READ IT AGAIN![/b]

Good luck!

… and let me know
[size=85]if you need [/size]
[size=50]more help…[/size]


#12

Thank you :laughing:


#13

Only one I have to finish reading on that list is the GDEVELOP WIKI :smiley:.

But none the less I appreciate the help and I will continue to try and understand GDevelop.

Take Care
InsertCoin25


#14

Cool! But don’t get frustrated at any moment!

GDevelop is extremely easy (you can do a basic platformer in a few clicks, there is a tutorial in youtube) but there are things a little bit complicated in any programming language or IDE (GDevelop is an IDE, Integrated Development Enviroment)… the algorithm needed for a functional slot machine simulation seems to be NOT basic stuff.

An algorithm is the “recipe” or set of instructions that something (in this case the language/IDE) use to complete an usually repetitive task…

In this short article a less sleepy person describes (better than me) what an algorithm is in a very funny, intuitive and useful way:
http://code.tutsplus.com/tutorials/understanding-the-principles-of-algorithm-design–net-26561
And don’t frustrate if you don’t understand the blocks of pseudocode in the article, it’s not necessary!

So, the algorithm is just an organized idea or concept that exists independently of any language/IDE. How you implement an algorithm to a language/IDE depends of the specific tools, settings, features and characteristics a language/IDE has.

As I said to you before, GDevelop is made to be an extremely easy yet powerful tool to develop games and you can make some basic games in minutes (see the examples, follow the tutorials). In fact, you already have done some algorithms in GDevelop: any condition or action you set in the events windows is part of a bigger algorithm. But, for more complex games, you’ll need more complex algorithms and the trick here is to discover how to describe that algorithm (that idea, that set of instructions) as conditions and actions in the window of GDevelop (or any other language/IDE you’re using).

So, my advice: learn the basics. Understand GDevelop. You want to make an amazing game? GDevelop is your tool to reach that goal, so practice a lot with that tool before try to do something big and perfect. Make a lot of basic games.

And try to finish the implementation of the slot machine algorithm in your game. Everything is already done, you just need to copy-paste and use the data stored in the result variables to choose your next action in the game (that’s the “output” mentioned in the article).

If you need help, don’t hesitate in ask for it; even for a basic explanation.


#15

Wow :mrgreen: I found these lines quite beautiful to read :laughing:
That pretty sum up as how GDevelop (or any development tool) should be used.

(Sorry for being off topic :smiley: )


#16

:wink:


#17

Best games that you can find here are the black jack, the roulette, keno, sports betting, baccarat and more fun games. With many online casino springing u these days is important to have all the needed technology available


#18

I am very new to GD - can anyone tell me how I can open/execute a .gdg file as in this package here ? It doesn’t open as a project in the osx gdevelop ide.


#19

It is the old format GD4 was using. You need to use GDevelop 4 to open .gdg and then export from GD4 as JSON, then you can open the JSON in GD5.

But, it may be not 100% compatible. At times you need to delete and create the objects and add behaviors and set collision mask again in all scenes to get old GD4 projects working properly in GD5. Also, in case it is uses some native only features and events that we don’t have implemented in GD5 you may get “unknown events” that can not be fixed.

You can download GD4 from here.

Unfortunately though, GD4 had a very poor Mac and Linux support, you may be better off trying the Windows version through WINE:
http://winebottler.kronenberg.org/
https://www.playonmac.com/en/

Actually I’m wondering if maybe we did not ported this example over to GD5 exactly because it is uses some features that is missing from GD5 :thinking:


#20

ahh cool okay, now i understand. thanks! :slight_smile: