summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/games/roulette.rs8
-rw-r--r--src/roulette.rs10
2 files changed, 16 insertions, 2 deletions
diff --git a/src/client/games/roulette.rs b/src/client/games/roulette.rs
index ec9573c..f0ed816 100644
--- a/src/client/games/roulette.rs
+++ b/src/client/games/roulette.rs
@@ -95,7 +95,7 @@ impl Cursor {
95 pub fn target(&self) -> Option<BetTarget> { 95 pub fn target(&self) -> Option<BetTarget> {
96 match self { 96 match self {
97 Cursor::Zero => Some(BetTarget::Straight { number: 0 }), 97 Cursor::Zero => Some(BetTarget::Straight { number: 0 }),
98 Cursor::Lattice { x, y } => felt_target(*x, *y), 98 Cursor::Lattice { x, y } => target_at(*x, *y),
99 Cursor::Dozen(index) => Some(BetTarget::Dozen { 99 Cursor::Dozen(index) => Some(BetTarget::Dozen {
100 index: *index as u8, 100 index: *index as u8,
101 }), 101 }),
@@ -171,7 +171,11 @@ fn cell_number(column: usize, row: usize) -> Option<u8> {
171} 171}
172 172
173/// Bet under a point of the fine grid. 173/// Bet under a point of the fine grid.
174fn felt_target(x: usize, y: usize) -> Option<BetTarget> { 174///
175/// Both frontends use this: the terminal moves a cursor over the lattice, and
176/// the GUI snaps a mouse position to it. Odd coordinates are cell centres,
177/// even coordinates are the lines where a split or corner chip sits.
178pub fn target_at(x: usize, y: usize) -> Option<BetTarget> {
175 if !(1..=FELT_X_MAX).contains(&x) || !(1..=FELT_Y_MAX).contains(&y) { 179 if !(1..=FELT_X_MAX).contains(&x) || !(1..=FELT_Y_MAX).contains(&y) {
176 return None; 180 return None;
177 } 181 }
diff --git a/src/roulette.rs b/src/roulette.rs
index 6b73c2a..b697e31 100644
--- a/src/roulette.rs
+++ b/src/roulette.rs
@@ -226,6 +226,16 @@ impl Bets {
226 } 226 }
227 } 227 }
228 228
229 /// Take `amount` back from one target, dropping the chip when it empties.
230 ///
231 /// This is the felt undo: a right or middle click removes one chip.
232 pub fn reduce(&mut self, target: &BetTarget, amount: u64) {
233 if let Some(chip) = self.chips.iter_mut().find(|chip| &chip.target == target) {
234 chip.amount = chip.amount.saturating_sub(amount);
235 }
236 self.chips.retain(|chip| chip.amount > 0);
237 }
238
229 /// Total returned for a winning number, including returned stakes. 239 /// Total returned for a winning number, including returned stakes.
230 pub fn winnings(&self, number: u8) -> u64 { 240 pub fn winnings(&self, number: u8) -> u64 {
231 self.chips.iter().fold(0u64, |total, chip| { 241 self.chips.iter().fold(0u64, |total, chip| {