diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-24 17:36:19 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-24 17:36:19 +0200 |
| commit | 828eb472701af16b7bd913111273b62d22ea3627 (patch) | |
| tree | 48ab3876cc1e2b7420609c7c1b016c939c9b84d1 /src/bin/server/games/slots.rs | |
| parent | TOFU host trust: SPKI fingerprint pinning, tests, forget-host (diff) | |
| download | zagan-bet-828eb472701af16b7bd913111273b62d22ea3627.tar.gz zagan-bet-828eb472701af16b7bd913111273b62d22ea3627.zip | |
Fix critical game bugs: payout, sessions, balance type, render_lines; add AGENTS.md and regression tests
Diffstat (limited to '')
| -rw-r--r-- | src/bin/server/games/slots.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/bin/server/games/slots.rs b/src/bin/server/games/slots.rs index d84e21f..3d285ef 100644 --- a/src/bin/server/games/slots.rs +++ b/src/bin/server/games/slots.rs | |||
| @@ -36,23 +36,25 @@ impl SlotsGame { | |||
| 36 | .collect() | 36 | .collect() |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn calculate_payout(&self, reels: &[char], bet: u64) -> u64 { | 39 | pub fn calculate_payout(&self, reels: &[char], bet: u64) -> u64 { |
| 40 | let reel_string: String = reels.iter().collect(); | 40 | let reel_string: String = reels.iter().collect(); |
| 41 | 41 | ||
| 42 | if let Some(&multiplier) = self.payouts.get(&reel_string) { | 42 | if let Some(&multiplier) = self.payouts.get(&reel_string) { |
| 43 | return bet * multiplier; | 43 | return bet * multiplier; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | for i in 0..2 { | 46 | // Check all three pairs including non-adjacent (e.g. [C,D,C]) |
| 47 | if reels[i] == reels[i + 1] { | 47 | let pairs: [(usize, usize); 3] = [(0, 1), (1, 2), (0, 2)]; |
| 48 | let two_of_kind = format!("{}{}", reels[i], reels[i]); | 48 | let mut best: u64 = 0; |
| 49 | for &(a, b) in &pairs { | ||
| 50 | if reels[a] == reels[b] { | ||
| 51 | let two_of_kind = format!("{}{}", reels[a], reels[a]); | ||
| 49 | if let Some(&multiplier) = self.payouts.get(&two_of_kind) { | 52 | if let Some(&multiplier) = self.payouts.get(&two_of_kind) { |
| 50 | return bet * multiplier; | 53 | best = best.max(bet * multiplier); |
| 51 | } | 54 | } |
| 52 | } | 55 | } |
| 53 | } | 56 | } |
| 54 | 57 | best | |
| 55 | 0 | ||
| 56 | } | 58 | } |
| 57 | } | 59 | } |
| 58 | 60 | ||
| @@ -108,11 +110,8 @@ impl Game for SlotsGame { | |||
| 108 | new_data.insert("reels".to_string(), reel_string.clone()); | 110 | new_data.insert("reels".to_string(), reel_string.clone()); |
| 109 | new_data.insert("status".to_string(), "spun".to_string()); | 111 | new_data.insert("status".to_string(), "spun".to_string()); |
| 110 | 112 | ||
| 111 | let winnings = self.calculate_payout(&reels, state.bet_amount); | ||
| 112 | new_data.insert("winnings".to_string(), winnings.to_string()); | ||
| 113 | |||
| 114 | let is_jackpot = reels[0] == reels[1] && reels[1] == reels[2]; | 113 | let is_jackpot = reels[0] == reels[1] && reels[1] == reels[2]; |
| 115 | let is_two = reels[0] == reels[1] || reels[1] == reels[2]; | 114 | let is_two = reels[0] == reels[1] || reels[1] == reels[2] || reels[0] == reels[2]; |
| 116 | new_data.insert( | 115 | new_data.insert( |
| 117 | "win_type".to_string(), | 116 | "win_type".to_string(), |
| 118 | if is_jackpot { | 117 | if is_jackpot { |
