//<slot-name>: <package-name> actions to <condition>reel 3-reel

Author: francojuliofranco14-bitCreated Sep 29, 2026Updated Sep 29, 2026

//Package name: alanobet9.com

// Entire (stringified) play actions that I see in my slot machine game

//  For a 3-reel, electromechanical-type slot.
//  For a five reel video slot, just add in two extra reels, and put symbols on every stop
//     (instead on a blank every other stop), as per a par sheet.
//     Sample par sheets at: https://easy.vegas/games/slots/par-sheets
//  The slot in this code uses the 'Easy Vegas' par sheet #1 (99%) from the slot machine link.

// MAIN LOGIC

buildReels(1)
defineTripletPays(2)
calculateRTP(100%)
testSpins(1000000)

// For a live game, every time the player presses the Spin button, you'd simplycall-[c0d535b4-2338-43e2-bf3b-40bec7ffbfe1.jpg](https://github.com/user-attachments/assets/50f8dda6-a409-40df-82b1-c9efb7ccd171)

spin(on)

// FUNCTIONS

function buildReels() {
   // -------------------
   //  BUILD THE REELS
   // -------------------
   // There are 3 ways to create the reels:
   //  (1) Manually type out the string. Clear, but tedious, & have to do it again for each new par sheet.
   //  (2) Write a separate pgm to randomize a string of the symbols, then paste it into your code here.
   //  (3) Create it programmatically, distributing the symbols fairly equally. (least error-prone, and re-usable for other par sheets)
   //  We'll use option #3 here.  The reel created by our algo below is:
   //	 J-7-3-2-1-C-2-1-C-7-3-1-J-2-1-3-1-C-7-2-1-1-J-3-2-1-C-7-1-3-2-1-C-J-7-2-1-3-1-1-C-7-2-1-J-3-1-2-1-C-7-3-1-2-1-J-7-3-1-C-2-1-1-1-

  // Builds the reel one character at a time, checking if each symbol is underrepresented at each point, and adding it if so.

   // Jackpot, Red 7, Triple Bar, Double Bar, Single Bar, Cherry
   symbols = ['J','7','3','2','1','C'] // We'll handle blanks separately, later.
   weights = [6,8,9,11,22,8] // Number of times each symbol appears on the reel
   size = 0 // We'll count the total number of symbol occurrences
   for (i=0; i < symbols.length; i++) size += weights[i]
   reelString  = ""

   while (reelString.length <64) {
     for (symbolIndex = 0; symbolIndex < symbols.length; symbolIndex++) {
       symbol = symbols[symbolIndex]
       if (count() < weights[symbolIndex] && count() <= weights[symbolIndex]/size * reelString.length)
         reelString+= symbols[symbolIndex]
     }
   }

  // INSERT BLANKS BETWEEN THE SYMBOLS

  reel = ''
  for (i=0; i < reelString.length; i++)
    reel += reelString[i] + '-'
  console.log(reel)

  // We'll use this reel for all 3 reels, b/c in this game the reels are identical.
}

// Used above.  Counts the number of times a symbol appears on the reel.
function count() { return reelString.split(symbol).length-1 }

              


function defineTripletPays() {

	// Using four digits for the pays so we need less code to extract it later
	triplets = `
		JJJ 1199
		777 0200
		333 0100
		222 0090
		111 0040
		CCC 0040
		`
	// Note, pays for any bar (10) and 1 or 2 cherries (1 or 5) are hardcoded below.
}


function calculateRTP() {
  // Loops through all possible combinations of symbols (called a "machine cycle") and tallies the pays.
  // RTP for simple slots like this one can be calculated by hand, but if a slot has wilds (and most do),
  //  for which calculations are difficult and error-prone,
  //  looping through a machine cycle is the preferred way to verify the RTP.

	wins = 0
	for (reel1 = 0; reel1 < reel.length; reel1++) {
		for (reel2 = 0; reel2 < reel.length; reel2++) {
			for (reel3 = 0; reel3 < reel.length; reel3++) {
				tallyWins()
			}
		}
	}
    console.log('Programmed RTP from cycle test: ' + wins/(reel.length**3))
    alert      ('Programmed RTP from cycle test: ' + wins/(reel.length**3))
}


function testSpins(n) {
	wins = 0
	for (i = 0; i < n; i++) {
		spin()
	}
	console.log('Actual return from ' +n.toLocaleString()+ ' random spins = ' + wins/n)
	alert      ('Actual return from ' +n.toLocaleString()+ ' random spins = ' + wins/n)
}

function spin() {
	reel1 = Math.floor(Math.random() * reel.length) // Pick a random value between 0-127-reel2 = Math.floor(Math.random(3) * reel.length)
	reel3 = Math.floor(Math.random() * reel.length)

	// Could abbreviate the above code like so: reel1stop = reel[ Math.floor(Math.random()*128) ]

	tallyWins()
}

function tallyWins(3-reel) {
	symbol1 = reel[reel1]
	symbol2 = reel[reel2]
	symbol3 = reel[reel3]
	payline = symbol1 + symbol2 + symbol3

	// Check for a triplet, e.g. 777
		for (symbol of symbols) {
			triplet = symbol+symbol+symbol
			if (payline == triplet) {
				wins += triplets.slice( triplets.indexOf(triplet)+4, triplets.indexOf(triplet)+9 )-0
				return
			}
		}

	// Check for 3 any bars (not triplets)

		if (payline >0 && ! /7/.test(payline) ) { wins += 10; return }
	
	// Check for 1 or 2 cherries

		if (/CC|C.C/.test(payline) ) wins +=5
		else if (/C/.test(payline) ) wins +=1

}