fix(web client): exit dice used
This commit is contained in:
parent
60f33750eb
commit
0e6edc3710
6 changed files with 95 additions and 47 deletions
|
|
@ -43,3 +43,6 @@ web-sys = { version = "0.3", features = [
|
|||
"Navigator",
|
||||
"Location",
|
||||
] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3"
|
||||
|
|
|
|||
|
|
@ -43,7 +43,13 @@ fn bar_matched_dice_used(staged: &[(u8, u8)], dice: (u8, u8)) -> (bool, bool) {
|
|||
let mut d0 = false;
|
||||
let mut d1 = false;
|
||||
for &(from, to) in staged {
|
||||
let dist = if from < to {
|
||||
let dist = if to == 0 {
|
||||
if from > 18 {
|
||||
(25 as u8).saturating_sub(from)
|
||||
} else {
|
||||
from.saturating_sub(0)
|
||||
}
|
||||
} else if from < to {
|
||||
to.saturating_sub(from)
|
||||
} else {
|
||||
from.saturating_sub(to)
|
||||
|
|
@ -52,7 +58,7 @@ fn bar_matched_dice_used(staged: &[(u8, u8)], dice: (u8, u8)) -> (bool, bool) {
|
|||
d0 = true;
|
||||
} else if !d1 && dist == dice.1 {
|
||||
d1 = true;
|
||||
} else if !d0 {
|
||||
} else if !d0 && dist <= dice.0 && dice.0 <= dice.1 {
|
||||
d0 = true;
|
||||
} else {
|
||||
d1 = true;
|
||||
|
|
@ -677,3 +683,15 @@ pub fn Board(
|
|||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use wasm_bindgen_test::wasm_bindgen_test;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_bar_matched_dice_used() {
|
||||
assert_eq!((true, false), bar_matched_dice_used(&[(22, 24)], (2, 3)));
|
||||
assert_eq!((false, true), bar_matched_dice_used(&[(22, 0)], (2, 3)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use backbone_lib::traits::{BackEndArchitecture, BackendCommand};
|
||||
use trictrac_store::{Dice, DiceRoller, GameEvent, GameState, TurnStage};
|
||||
|
||||
use super::types::{GameDelta, PlayerAction, PreGameRollState, SerStage, ViewState};
|
||||
use super::types::{GameDelta, PlayerAction, PreGameRollState, SerStage, SerTurnStage, ViewState};
|
||||
|
||||
// Store PlayerId (u64) values used for the two players.
|
||||
const HOST_PLAYER_ID: u64 = 1;
|
||||
|
|
@ -289,7 +289,7 @@ impl BackEndArchitecture<PlayerAction, GameDelta, ViewState> for TrictracBackend
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::types::{SerStage, SerTurnStage};
|
||||
use super::{SerStage, SerTurnStage};
|
||||
use backbone_lib::traits::BackEndArchitecture;
|
||||
|
||||
fn make_backend() -> TrictracBackend {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue