diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 22:44:41 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 22:44:41 +0100 |
| commit | 63c2e2fc3ea299aee31b66d2bdd6ecd871df223a (patch) | |
| tree | 9c85ab7a4de17125055257dc055fa3e53dc1e8cf /src/server/games/slots.rs | |
| parent | v0.2.6: preserve buffered lines and add request read timeouts (diff) | |
| download | zagan-bet-63c2e2fc3ea299aee31b66d2bdd6ecd871df223a.tar.gz zagan-bet-63c2e2fc3ea299aee31b66d2bdd6ecd871df223a.zip | |
v0.3.0: add server core, bcrypt migration and plays audit
Diffstat (limited to 'src/server/games/slots.rs')
| -rw-r--r-- | src/server/games/slots.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/server/games/slots.rs b/src/server/games/slots.rs index 0a9797d..02595b1 100644 --- a/src/server/games/slots.rs +++ b/src/server/games/slots.rs | |||
| @@ -5,6 +5,8 @@ use std::collections::HashMap; | |||
| 5 | pub struct SlotsGame { | 5 | pub struct SlotsGame { |
| 6 | symbols: Vec<char>, | 6 | symbols: Vec<char>, |
| 7 | payouts: HashMap<String, u64>, | 7 | payouts: HashMap<String, u64>, |
| 8 | /// Deterministic reels for tests and demos. | ||
| 9 | fixed_reels: Option<Vec<char>>, | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | impl SlotsGame { | 12 | impl SlotsGame { |
| @@ -27,10 +29,25 @@ impl SlotsGame { | |||
| 27 | payouts.insert("DD".to_string(), 2); | 29 | payouts.insert("DD".to_string(), 2); |
| 28 | payouts.insert("SS".to_string(), 3); | 30 | payouts.insert("SS".to_string(), 3); |
| 29 | 31 | ||
| 30 | Self { symbols, payouts } | 32 | Self { |
| 33 | symbols, | ||
| 34 | payouts, | ||
| 35 | fixed_reels: None, | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | /// Build a slots game that always spins the given three symbols. | ||
| 40 | pub fn with_reels(reels: &str) -> Self { | ||
| 41 | let mut game = Self::new(); | ||
| 42 | game.fixed_reels = Some(reels.chars().take(3).collect()); | ||
| 43 | game | ||
| 31 | } | 44 | } |
| 32 | 45 | ||
| 33 | fn spin_reels(&self) -> Vec<char> { | 46 | fn spin_reels(&self) -> Vec<char> { |
| 47 | if let Some(reels) = &self.fixed_reels { | ||
| 48 | return reels.clone(); | ||
| 49 | } | ||
| 50 | |||
| 34 | let mut rng = rand::thread_rng(); | 51 | let mut rng = rand::thread_rng(); |
| 35 | (0..3) | 52 | (0..3) |
| 36 | .map(|_| self.symbols[rng.gen_range(0..self.symbols.len())]) | 53 | .map(|_| self.symbols[rng.gen_range(0..self.symbols.len())]) |
| @@ -41,7 +58,7 @@ impl SlotsGame { | |||
| 41 | let reel_string: String = reels.iter().collect(); | 58 | let reel_string: String = reels.iter().collect(); |
| 42 | 59 | ||
| 43 | if let Some(&multiplier) = self.payouts.get(&reel_string) { | 60 | if let Some(&multiplier) = self.payouts.get(&reel_string) { |
| 44 | return bet * multiplier; | 61 | return bet.saturating_mul(multiplier); |
| 45 | } | 62 | } |
| 46 | 63 | ||
| 47 | // Check all three pairs including non-adjacent (e.g. [C,D,C]) | 64 | // Check all three pairs including non-adjacent (e.g. [C,D,C]) |
| @@ -51,7 +68,7 @@ impl SlotsGame { | |||
| 51 | if reels[a] == reels[b] { | 68 | if reels[a] == reels[b] { |
| 52 | let two_of_kind = format!("{}{}", reels[a], reels[a]); | 69 | let two_of_kind = format!("{}{}", reels[a], reels[a]); |
| 53 | if let Some(&multiplier) = self.payouts.get(&two_of_kind) { | 70 | if let Some(&multiplier) = self.payouts.get(&two_of_kind) { |
| 54 | best = best.max(bet * multiplier); | 71 | best = best.max(bet.saturating_mul(multiplier)); |
| 55 | } | 72 | } |
| 56 | } | 73 | } |
| 57 | } | 74 | } |
