Randomize the deck of tiles

This commit is contained in:
2023-02-12 21:01:38 +01:00
parent ea6572dca2
commit 8943d1d898
7 changed files with 194 additions and 13 deletions

View File

@@ -1,11 +1,12 @@
use crate::hand_view::HandView;
use crate::tile_view::PlacedTileView;
use board_shared::board::Board;
use board_shared::deck::RngDeck;
use board_shared::expr::is_valid_guess;
use board_shared::game::Game;
use board_shared::position::Grid2d;
use board_shared::tile::Tile;
use gloo_dialogs::alert;
use board_shared::position::Grid2d;
use yew::prelude::*;
enum SelectedTile {
@@ -78,11 +79,14 @@ pub fn app() -> Html {
let current_game = current_game.clone();
Callback::from(move |_| {
let diff = game.board.difference(&current_game.board);
let mut deck = RngDeck::new_complete();
if let Some(true) = Board::is_contiguous(&diff) {
if let Ok(true) = is_valid_guess(&current_game.board, &diff) {
alert("Valid move!");
let mut in_hand = current_game.in_hand.clone();
in_hand.complete();
if in_hand.complete(&mut deck).is_err() {
alert("No more tiles left in deck!");
}
game.set(Game {
board: current_game.board.clone(),
in_hand: in_hand.clone(),
@@ -103,7 +107,9 @@ pub fn app() -> Html {
alert("Invalid move! (not contiguous)");
}
let mut in_hand = game.in_hand.clone();
in_hand.complete();
if in_hand.complete(&mut deck).is_err() {
alert("No more tiles left in deck!");
}
current_game.set(Game {
board: game.board.clone(),
in_hand,