public static async Task DoSpin() { w.winDisplayLbl.Content = ""; ChangeBalance(-5); Random rnd = new Random(); middleRoll.StartSpin(); rightRoll.StartSpin(); SlotSymbol leftSymbol = await leftRoll.Spin(rnd.Next(1, 8)); await middleRoll.StopSpin(); SlotSymbol middleSymbol = await middleRoll.Spin(rnd.Next(1, 5)); await rightRoll.StopSpin(); SlotSymbol rightSymbol = await rightRoll.Spin(rnd.Next(1, 4)); // Console.WriteLine($"{leftSymbol.ToString()} {middleSymbol.ToString()} {rightSymbol.ToString()}"); int win = GetWin(leftSymbol, middleSymbol, rightSymbol); ChangeBalance(win); if (win != 0) { DisplayWin(win); } if (win == 10) { } }
private void PopulateReels() { //Get data SlotSymbolPositions slotpos = slotModel.dataset.PARSHEET; int rowCount = slotpos.SlotGamePositions.GetLength(0); int colCount = slotpos.SlotGamePositions.GetLength(1); dataset.SlotRows = rowCount; dataset.SlotColumns = colCount; SessionValues.ReelDatasets = new SlotSymbol[rowCount, colCount]; for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { int SlotSymbolIndex = col; if (SlotSymbolIndex >= dataset.SlotSymbolsList.Count) { int countmultiplier = col / dataset.SlotSymbolsList.Count; SlotSymbolIndex -= dataset.SlotSymbolsList.Count * countmultiplier; } SlotSymbol _symbol = Instantiate(dataset.SlotSymbolsList[SlotSymbolIndex], slotView.Columns[row].transform); SessionValues.ReelDatasets[row, col] = _symbol; } } }
public IGameState Play(IPlayerState playerState) { SlotMachineGameState state = new SlotMachineGameState(); if (!this._isGameStarted) { state.Rows = "Game is not started"; return(state); } SlotMachinePlayerState smPlayerState = (SlotMachinePlayerState)playerState; if (this._player.Balance < smPlayerState.Stake) { state.Rows = "Player balance is not enough"; return(state); } this._player.Balance -= smPlayerState.Stake; Random rand = new Random(); decimal winningCoeficent = 0; for (int i = 0; i < this._rows; i++) { //current symbol of the row. If symbol is different than next symbol, than row is lost. SlotSymbol _symbols = null; //total coeficent of the row decimal coeficent = 0; //does winning condition of row is met bool isWinningRow = true; //Row symbols string result = ""; for (int j = 0; j < this._cols; j++) { SlotSymbol currentSymbol = this.GetSymbol(rand.Next(1, (int)this._totalProbabilitySum)); result += currentSymbol.Symbol; coeficent += currentSymbol.Coefficent; if (currentSymbol.Type == SlotSymbolType.Star) { continue; } if (_symbols == null) { _symbols = currentSymbol; } if (_symbols.Symbol != currentSymbol.Symbol) { isWinningRow = false; } } //if winning condition is true, than we add row coeficent to total coeficent if (isWinningRow) { winningCoeficent += coeficent; } state.Rows += string.Format("{0}\n", result); } state.ResultBalanceWin = smPlayerState.Stake * winningCoeficent; this._player.Balance += state.ResultBalanceWin; return(state); }
/* * public int getSymbol() * { * int chosen = -1; * while (chosen == -1) * { * //int selectedFrequency = UnityEngine.Random.Range(1,totalFrequency+1); * uint selectedFrequency = RNGManager.getRandomRange(slot.activeRNG, 1, totalFrequency+1); * for (int index = 0; index < cumulativeFrequencyList.Count; index++) * { * if (selectedFrequency <= cumulativeFrequencyList[index]) { chosen = index; break; } * } * int maxPerReel = slot.symbolPrefabs[chosen].GetComponent<SlotSymbol>().clampPerReel; * if (maxPerReel > 0) * { * if (getSymbolCountCurrentlyOnReel(chosen) >= maxPerReel) { chosen = -1; continue; } * int maxTotal = slot.symbolPrefabs[chosen].GetComponent<SlotSymbol>().clampTotal; * if (maxTotal > 0) * if (slot.getSymbolCountCurrentlyTotal(chosen) >= maxTotal) chosen = -1; * } * } * * return chosen; * } */ public int getSymbol(int reelIndex) { List <int> cumulativeFrequencyList = new List <int>(); int totalFrequency = 0; for (int index = 0; index < slot.symbolFrequencies.Count; index++) { SlotSymbol symbol = slot.symbolPrefabs[index].GetComponent <SlotSymbol>(); if (symbol.perReelFrequency) { totalFrequency += slot.reelFrequencies[index].freq[reelIndex]; } else { totalFrequency += slot.symbolFrequencies[index]; } cumulativeFrequencyList.Add(totalFrequency); } int chosen = -1; while (chosen == -1) { uint selectedFrequency = RNGManager.getRandomRange(slot.activeRNG, 1, totalFrequency + 1); if (selectedFrequency == totalFrequency + 1) { Debug.Log("wtf"); } for (int index = 0; index < cumulativeFrequencyList.Count; index++) { if (selectedFrequency <= cumulativeFrequencyList[index]) { chosen = index; break; } } int maxPerReel = slot.symbolPrefabs[chosen].GetComponent <SlotSymbol>().clampPerReel; if (maxPerReel > 0) { if (getSymbolCountCurrentlyOnReel(reelIndex, chosen) >= maxPerReel) { chosen = -1; continue; } int maxTotal = slot.symbolPrefabs[chosen].GetComponent <SlotSymbol>().clampTotal; if (maxTotal > 0) { if (getSymbolCountCurrentlyTotal(chosen) >= maxTotal) { chosen = -1; } } } } return(chosen); }
//Based on the random number, we calculate what is next number private SlotSymbol GetSymbol(int probabilityRandomNumber) { SlotSymbol symbol = this._symbols[this._probabilityDistribution.Length - 1]; for (var i = 0; i < this._probabilityDistribution.Length; i++) { if (probabilityRandomNumber <= this._probabilityDistribution[i]) { symbol = this._symbols[i]; break; } } return(symbol); }
public SlotrollElement(SlotSymbol slotSymbol, int position) { element = new Rectangle(); element.Height = 120; element.Width = 120; string imgName; Uri imgUri; switch (slotSymbol) { case SlotSymbol.Ace: imgName = "ace.png"; break; case SlotSymbol.Cherry: imgName = "cherry.png"; break; case SlotSymbol.Chip: imgName = "chip.png"; break; case SlotSymbol.Heart: imgName = "heart.png"; break; case SlotSymbol.Money: imgName = "money.png"; break; default: throw new Exception("file not found or something like that"); } imgUri = new Uri(@"pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/" + "Assets/RollImages/" + imgName, UriKind.Absolute); element.Fill = new ImageBrush(new BitmapImage(imgUri)); Canvas.SetLeft(element, 130); Canvas.SetTop(element, position); this.symbol = slotSymbol; this.pos = position; }
public IGame GetGame() { SlotSymbol[] symbols = new SlotSymbol[4]; symbols[0] = new SlotSymbol() { Type = SlotSymbolType.A, Symbol = "A", Coefficent = 0.4M, Probability = 45 }; symbols[1] = new SlotSymbol() { Type = SlotSymbolType.B, Symbol = "B", Coefficent = 0.6M, Probability = 35 }; symbols[2] = new SlotSymbol() { Type = SlotSymbolType.P, Symbol = "P", Coefficent = 0.8M, Probability = 15 }; symbols[3] = new SlotSymbol() { Type = SlotSymbolType.Star, Symbol = "*", Coefficent = 0M, Probability = 5 }; return(new SlotMachineGame(symbols, 4, 3)); }
public void StartGame(IGameStartingData data) { //game should have 1 player set by starting data. if (data.Players.Count > 0) { this._player = data.Players[0]; } this._totalProbabilitySum = 0; this._isGameStarted = true; this._probabilityDistribution = new double[this._symbols.Length]; double probabilityDistributionStart = 0; //calculating total probability and probability distribution of all symbols for (var i = 0; i < this._symbols.Length; i++) { SlotSymbol symbol = this._symbols[i]; this._totalProbabilitySum += symbol.Probability; probabilityDistributionStart += symbol.Probability; this._probabilityDistribution[i] = probabilityDistributionStart; } }
public static int GetWin(SlotSymbol symbol1, SlotSymbol symbol2, SlotSymbol symbol3) { //Check for jackpot if (symbol1 == symbol2 && symbol1 == symbol3 && symbol1 == SlotSymbol.Money) { return(100); } if (symbol1 == symbol2 && symbol1 == symbol3) { return(10); } else if (symbol1 == symbol2 || symbol2 == symbol3 || symbol1 == symbol3) { return(2); } else { return(0); } }
//////////////////////////////////////////////////////// // TODO: write a method to calculate the payout. the // payout is determined by the following rules: // // if all three symbols match, the payout is equal to // the value of the symbol raised to the 3rd power // // if two of the three symbols match, the payout is equal // to the value of the symbol // // the "Wild" symbol matches all other symbols public static int Payout(SlotSymbol s1, SlotSymbol s2, SlotSymbol s3) { int num1 = (int)s1; int num2 = (int)s2; int num3 = (int)s3; int[] slots = { num1, num2, num3 }; int max = Math.Max(Math.Max(num1, num2), num3); for (int i = 0; i < slots.Length; i++) { if (slots[i] == 0) { slots[i] = max; } } if (slots[0] == slots[1] && slots[1] != slots[2]) { return(slots[0]); } if (slots[1] == slots[2] && slots[1] != slots[0]) { return(slots[1]); } if (slots[0] == slots[2] && slots[0] != slots[1]) { return(slots[2]); } if (slots[0] == slots[1] && slots[1] == slots[2]) { return((int)Math.Pow(slots[0], 3)); } return(0); }
void cacheSymbolFrequency() { cumulativeFrequencyList.Clear(); totalFrequency = 0; for (int index = 0; index < slot.symbolFrequencies.Count; index++) { if (slot.symbolPrefabs[index] == null) { continue; } SlotSymbol symbol = slot.symbolPrefabs[index].GetComponent <SlotSymbol>(); if (symbol.perReelFrequency) { totalFrequency += slot.reelFrequencies[index].freq[reelIndex - 1]; } else { totalFrequency += slot.symbolFrequencies[index]; } cumulativeFrequencyList.Add(totalFrequency); } }
private int calculateSingleLine(SlotSymbol symbol1, SlotSymbol symbol2, SlotSymbol symbol3, int bet) { //Assign first symbol as main symbol(line maker) SlotSymbol mainSymbol = symbol1; //Check if line has only special Castle symbols if (symbol1.Currency == 0 && symbol2.Currency == 0 && symbol3.Currency == 0) { return(bet * 50); } //Exclude cases when line starts with the special Castle symbol if (mainSymbol.Currency == 0) { mainSymbol = symbol2; } if (mainSymbol.Currency == 0) { mainSymbol = symbol3; } //Check if we have a winning line - equal symbols or combinated with special symbol if (!(symbol1.Symbol == mainSymbol.Symbol || symbol1.Currency == 0)) { return(0); } if (!(symbol2.Symbol == mainSymbol.Symbol || symbol2.Currency == 0)) { return(0); } if (!(symbol3.Symbol == mainSymbol.Symbol || symbol3.Currency == 0)) { return(0); } return(bet * mainSymbol.Currency); }