Writing a slot machine is very challenging for me. It includes multiple challenges:

  • Programming in Rust (I hardly know the language)
  • Graphics programming, including animation
  • Probabilities
  • Getting the architecture right

It’s a big project, but also an opportunity to learn many things.

Overview

A slot machine contains two parts:

  • Gameplay
  • Graphics

The visual part includes the “board”, the reels, animation, text, buttons.

Gameplay includes interaction and the actual play of the machine.

I’m not sure how to tackle this, so the best way is probably one step at a time.

Architecture

Since this is going to be an interactive program, it makes sense to have a mainloop that handles input as well as runs the graphic part (updates and animation).

The “business logic” controls the gameplay. It controls the reels, the payout (if any), the money and any additional mini-games. This part feels like it could live on its own. But it should interact with the visual part and with user input.

The graphic part controls all the visuals (I am not thinking about sound at this point, but maybe later). This includes the board, the reels, the buttons, text, help, money side, etc. This should have multiple components. For example, a resource manager, an animation manager (including different animation schemes), timed actions (highlights), and so on. Even something like “big win” that shows coins is a whole set of rules and code to implement (possibly its own component).

This is a very high-level view of the architecture. I will have to break it down a bit in order to make sense of the project.

Reels and Payout

This is the core of the machine. It probably deserves a post. This is the design of the payouts and reels (whether real or not) to implement the payout. For example, if the only thing that pays out is 5 oranges, that pays X and I want the game to pay Y% then I expect the reels to show 5 oranges Z% of the time, so that the payout is Y%. This can get complicated.

Real reels are actual reels (that really have a sequence of symboles and roll around). Fake reels are just random symbols that land the way I need them to land. I feel that having real ones is nicer, but could be quite tricky to design.

Once the reels and payout are designed, it should be possible to write the business logic and make it event driven (sort of pub/sub).