diff --git a/src/game.rs b/src/game.rs index 751313e..66203e2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -37,7 +37,7 @@ pub struct PlayerState { #[tsify(from_wasm_abi)] pub struct PlayedTile { pub index: usize, - pub character: char, + pub character: Option, // we only set this if PlayedTile is a blank } #[derive(Debug, Serialize, Deserialize, Tsify)] @@ -164,7 +164,15 @@ impl Game { let coord = Coordinates::new_from_index(played_tile.index); if letter.is_blank { - letter.text = played_tile.character; + match played_tile.character { + None => { + panic!("You can't play a blank character without providing a letter value") + } + Some(x) => { + // TODO - check that x is a valid alphabet letter + letter.text = x; + } + } } played_letters.push((letter, coord)); diff --git a/src/player_interaction/ai.rs b/src/player_interaction/ai.rs index fb9aec1..81262d2 100644 --- a/src/player_interaction/ai.rs +++ b/src/player_interaction/ai.rs @@ -72,9 +72,14 @@ impl CompleteMove { match m { Some(x) => { if letter.partial_match(&x.letter) { + let character = if x.letter.is_blank { + Some(x.letter.text) + } else { + None + }; played_tiles.push(Some(PlayedTile { index: x.coordinates.map_to_index(), - character: x.letter.text, + character, })); *m = None; found_match = true;