fix(web client): exit dice used

This commit is contained in:
Henri Bourcereau 2026-05-02 20:02:47 +02:00
parent 60f33750eb
commit 0e6edc3710
6 changed files with 95 additions and 47 deletions

50
Cargo.lock generated
View file

@ -5339,6 +5339,16 @@ dependencies = [
"unicase", "unicase",
] ]
[[package]]
name = "minicov"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4869b6a491569605d66d3952bcdf03df789e5b536e5f0cf7758a7f08a55ae24d"
dependencies = [
"cc",
"walkdir",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -8707,6 +8717,7 @@ dependencies = [
"trictrac-store", "trictrac-store",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasm-bindgen-test",
"web-sys", "web-sys",
] ]
@ -9158,6 +9169,45 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "wasm-bindgen-test"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bb55e2540ad1c56eec35fd63e2aea15f83b11ce487fd2de9ad11578dfc047ea"
dependencies = [
"async-trait",
"cast",
"js-sys",
"libm",
"minicov",
"nu-ansi-term",
"num-traits",
"oorandom",
"serde",
"serde_json",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
"wasm-bindgen-test-shared",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caf0ca1bd612b988616bac1ab34c4e4290ef18f7148a1d8b7f31c150080e9295"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]]
name = "wasm-bindgen-test-shared"
version = "0.2.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23cda5ecc67248c48d3e705d3e03e00af905769b78b9d2a1678b663b8b9d4472"
[[package]] [[package]]
name = "wasm-encoder" name = "wasm-encoder"
version = "0.244.0" version = "0.244.0"

View file

@ -43,3 +43,6 @@ web-sys = { version = "0.3", features = [
"Navigator", "Navigator",
"Location", "Location",
] } ] }
[dev-dependencies]
wasm-bindgen-test = "0.3"

View file

@ -43,7 +43,13 @@ fn bar_matched_dice_used(staged: &[(u8, u8)], dice: (u8, u8)) -> (bool, bool) {
let mut d0 = false; let mut d0 = false;
let mut d1 = false; let mut d1 = false;
for &(from, to) in staged { 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) to.saturating_sub(from)
} else { } else {
from.saturating_sub(to) from.saturating_sub(to)
@ -52,7 +58,7 @@ fn bar_matched_dice_used(staged: &[(u8, u8)], dice: (u8, u8)) -> (bool, bool) {
d0 = true; d0 = true;
} else if !d1 && dist == dice.1 { } else if !d1 && dist == dice.1 {
d1 = true; d1 = true;
} else if !d0 { } else if !d0 && dist <= dice.0 && dice.0 <= dice.1 {
d0 = true; d0 = true;
} else { } else {
d1 = true; d1 = true;
@ -677,3 +683,15 @@ pub fn Board(
</div> </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)));
}
}

View file

@ -1,7 +1,7 @@
use backbone_lib::traits::{BackEndArchitecture, BackendCommand}; use backbone_lib::traits::{BackEndArchitecture, BackendCommand};
use trictrac_store::{Dice, DiceRoller, GameEvent, GameState, TurnStage}; 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. // Store PlayerId (u64) values used for the two players.
const HOST_PLAYER_ID: u64 = 1; const HOST_PLAYER_ID: u64 = 1;
@ -289,7 +289,7 @@ impl BackEndArchitecture<PlayerAction, GameDelta, ViewState> for TrictracBackend
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use super::types::{SerStage, SerTurnStage}; use super::{SerStage, SerTurnStage};
use backbone_lib::traits::BackEndArchitecture; use backbone_lib::traits::BackEndArchitecture;
fn make_backend() -> TrictracBackend { fn make_backend() -> TrictracBackend {

View file

@ -13,6 +13,9 @@ runcli:
dev: dev:
trunk serve trunk serve
test-web:
wasm-pack test --node clients/web
[working-directory: 'clients/web'] [working-directory: 'clients/web']
build: build:
trunk build --release trunk build --release
@ -25,31 +28,6 @@ build:
run-relay: run-relay:
./relay-server ./relay-server
# Legacy targets kept for reference during transition
[working-directory: 'clients/web-game']
dev-game:
trunk serve
[working-directory: 'clients/web-game']
build-game:
trunk build --release
cp dist/index.html ../../deploy/trictrac.html
cp dist/*.wasm ../../deploy/
cp dist/*.js ../../deploy/
cp dist/*.css ../../deploy/
[working-directory: 'clients/web-user-portal']
dev-portal:
trunk serve
[working-directory: 'clients/web-user-portal']
build-portal:
trunk build --release
cp dist/index.html ../../deploy/portal.html
cp dist/*.wasm ../../deploy/
cp dist/*.js ../../deploy/
cp dist/*.css ../../deploy/
build-relay: build-relay:
CARGO_PROFILE_RELEASE_OPT_LEVEL=3 cargo build -p relay-server --release CARGO_PROFILE_RELEASE_OPT_LEVEL=3 cargo build -p relay-server --release
mkdir -p deploy mkdir -p deploy

View file

@ -260,8 +260,7 @@ impl MoveRules {
// A chained move (tout d'une): the first destination is a resting field. // A chained move (tout d'une): the first destination is a resting field.
// Exception: a resting field in the opponent's big jan (13-18) is allowed // Exception: a resting field in the opponent's big jan (13-18) is allowed
// during a chained move to pass into the return jan. // during a chained move to pass into the return jan.
let is_chained = let is_chained = moves.1.get_from() != 0 && moves.0.get_to() == moves.1.get_from();
moves.1.get_from() != 0 && moves.0.get_to() == moves.1.get_from();
if !is_chained { if !is_chained {
let to0 = moves.0.get_to(); let to0 = moves.0.get_to();
@ -756,6 +755,8 @@ impl MoveRules {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use anyhow::Ok;
use super::*; use super::*;
#[test] #[test]
@ -887,6 +888,20 @@ mod tests {
state.moves_allowed(&moves) state.moves_allowed(&moves)
); );
// on peut sortir une dame avec un nombre exact, même si on peut en jouer une avec un nombre défaillant
state.board.set_positions(
&Color::White,
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 2, 0,
],
);
state.dice.values = (2, 5);
let moves = (
CheckerMove::new(20, 0).unwrap(),
CheckerMove::new(23, 0).unwrap(),
);
assert!(state.moves_allowed(&moves).is_ok());
// on doit jouer le nombre excédant le plus éloigné // on doit jouer le nombre excédant le plus éloigné
state.board.set_positions( state.board.set_positions(
&Color::White, &Color::White,
@ -1489,22 +1504,6 @@ mod tests {
state.get_possible_moves_sequences(true, vec![]) state.get_possible_moves_sequences(true, vec![])
); );
state.board.set_positions(
&Color::White,
[
-8, -4, -1, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 2, 2, 2,
],
);
state.dice.values = (1, 4);
let moves = (
CheckerMove::new(21, 22).unwrap(),
CheckerMove::new(22, 0).unwrap(),
);
assert_eq!(
vec![moves],
state.get_possible_moves_sequences(true, vec![])
);
state.dice.values = (5, 3); state.dice.values = (5, 3);
state.board.set_positions( state.board.set_positions(
&crate::Color::White, &crate::Color::White,