diff --git a/Cargo.lock b/Cargo.lock index d46962b6..6ecd7f9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4884,9 +4884,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "log", "pin-project-lite", @@ -4896,9 +4896,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", @@ -4907,9 +4907,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", ] @@ -4985,6 +4985,7 @@ dependencies = [ "strum_macros", "thiserror 1.0.56", "time", + "tracing", "xxhash-rust", ] diff --git a/truncate_client/src/lib.rs b/truncate_client/src/lib.rs index facc29a5..e90449eb 100644 --- a/truncate_client/src/lib.rs +++ b/truncate_client/src/lib.rs @@ -126,6 +126,18 @@ impl WebHandle { } } +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen] +pub fn backchannel_setup() { + use web_sys::console; + + // Make sure panics are logged using `console.error`. + console_error_panic_hook::set_once(); + + // Redirect tracing to console.log and friends: + tracing_wasm::set_as_global_default(); +} + // Functions used in the web worker // Used to evaluate games as the NPC using a separate thread, // preventing the UI from hanging during computation. diff --git a/truncate_client/src/regions/native_menu.rs b/truncate_client/src/regions/native_menu.rs index f4939c7e..ad9d8e76 100644 --- a/truncate_client/src/regions/native_menu.rs +++ b/truncate_client/src/regions/native_menu.rs @@ -98,11 +98,7 @@ pub fn render_native_menu_if_required( } ui.text_edit_singleline(room_code); if ui.button("Join Game").clicked() { - send_to_server(PlayerMessage::JoinGame( - room_code.clone(), - outer.name.clone(), - token.clone(), - )); + outer.launched_code = Some(room_code.clone()); return Some(GameStatus::PendingJoin(room_code.clone())); } if let Some(existing_token) = token { diff --git a/truncate_core/Cargo.toml b/truncate_core/Cargo.toml index 0ee3ca2a..ef3d42a7 100644 --- a/truncate_core/Cargo.toml +++ b/truncate_core/Cargo.toml @@ -19,6 +19,7 @@ chksum-hash-sha2 = { version = "0.0.0", default-features = false, features = [ "256", ] } noise = "0.8" +tracing = "0.1.41" [dev-dependencies] insta = { version = "1.29.0", features = ["yaml"] } diff --git a/truncate_core/src/game.rs b/truncate_core/src/game.rs index 441872a5..26f992fc 100644 --- a/truncate_core/src/game.rs +++ b/truncate_core/src/game.rs @@ -567,18 +567,15 @@ impl Game { } let neighbors = self.board.neighbouring_squares(position); + if !neighbors.iter().any(|&(_, square)| match square { + Square::Occupied { player: p, .. } => p == player, + Square::Artifact { player: p, .. } => p == player, + _ => false, + }) { + if neighbors.iter().any(|&(_, square)| matches!(square, Square::Artifact { player: p, .. } if p != player)) { + return Err(GamePlayError::OpponentStartPlace); + } - if self.turn_count == 0 && neighbors.iter().any(|&(_, square)| matches!(square, Square::Artifact { player: p, .. } if p != player)) { - return Err(GamePlayError::OpponentStartPlace); - } - - if !neighbors.iter().any( - |&(_, square)| match square { - Square::Occupied { player: p, .. } => p == player, - Square::Artifact { player: p, .. } => p == player, - _ => false, - }, - ) { return Err(GamePlayError::NonAdjacentPlace); } diff --git a/truncate_core/src/moves/mod.rs b/truncate_core/src/moves/mod.rs index 1418937c..64f71e3c 100644 --- a/truncate_core/src/moves/mod.rs +++ b/truncate_core/src/moves/mod.rs @@ -1014,7 +1014,7 @@ mod tests { players, player_turn_count: vec![0, 0], judge: short_dict(), - turn_count: 1, // any non zero value will do to avoid hitting OpponentStartPlace error + turn_count: 0, ..Game::new_legacy(3, 1, None, GameRules::generation(0)) }; game.start(); diff --git a/truncate_core/src/npc/mod.rs b/truncate_core/src/npc/mod.rs index fce64f6e..c22ad796 100644 --- a/truncate_core/src/npc/mod.rs +++ b/truncate_core/src/npc/mod.rs @@ -89,7 +89,6 @@ impl Game { let evaluation_player = game .next_player .expect("Minimax only works in non-periodic playmodes"); - let mut internal_arborist = if npc_params.pruning { Arborist::pruning() } else { @@ -140,15 +139,15 @@ impl Game { }; if log { - println!( + tracing::debug!( "Bot checked {} boards, going to a depth of {looked}", arborist.assessed() ); - println!("Bot has the hand: {}", game.players[evaluation_player].hand); + tracing::debug!("Bot has the hand: {}", game.players[evaluation_player].hand); - println!("Chosen tree has the score {best_score:#?}"); + tracing::debug!("Chosen tree has the score {best_score:#?}"); if let Some(board) = &best_score.board { - println!("Bot is aiming for the board {board}"); + tracing::debug!("Bot is aiming for the board {board}"); } } @@ -717,10 +716,8 @@ mod tests { initial_board: &'a str, depth: usize, dict: &WordDict, - turn_count: u32, ) -> (&'a str, String) { let mut game = test_game(initial_board, hand); - game.turn_count = turn_count; let (best_move, pruned_checks, total_checks) = best_test_move(&game, &dict, depth); @@ -989,7 +986,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1031,7 +1027,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1073,7 +1068,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1115,7 +1109,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1157,7 +1150,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1202,7 +1194,6 @@ mod tests { "###, 3, &dict, - 0, ); insta::with_settings!({ @@ -1250,7 +1241,6 @@ mod tests { "###, 4, &dict, - 0, ); insta::with_settings!({ @@ -1304,7 +1294,6 @@ mod tests { "###, 2, &dict, - 3, // any non zero turn count value will do ); insta::with_settings!({ diff --git a/web_client/src/static/worker.js b/web_client/src/static/worker.js index cad7fe45..ddb90a08 100644 --- a/web_client/src/static/worker.js +++ b/web_client/src/static/worker.js @@ -25,6 +25,8 @@ self.onmessage = function (e) { console.log("[WORKER] Successfully loaded Truncate"); loadedWasm = true; + wasm_bindgen.backchannel_setup(); + } function on_wasm_error(error) {