Randomize the deck of tiles
This commit is contained in:
@@ -11,3 +11,4 @@ categories = ["gui", "wasm", "web-programming"]
|
||||
yew = { version="0.20", features=["csr"] }
|
||||
board-shared = { path = "../board-shared" }
|
||||
gloo-dialogs = "0.1.1"
|
||||
getrandom = { version = "0.2.8", features = ["js"] }
|
||||
|
@@ -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(¤t_game.board);
|
||||
let mut deck = RngDeck::new_complete();
|
||||
if let Some(true) = Board::is_contiguous(&diff) {
|
||||
if let Ok(true) = is_valid_guess(¤t_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,
|
||||
|
Reference in New Issue
Block a user