Compare commits

...

4 Commits

4 changed files with 28 additions and 83 deletions

View File

@ -8,7 +8,7 @@ version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"once_cell",
"version_check",
"zerocopy",
@ -32,18 +32,22 @@ version = "3.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "fish"
version = "0.1.0"
@ -60,11 +64,11 @@ dependencies = [
name = "fish-webworker"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"fish",
"mino",
"wasm-bindgen",
"wasm-bindgen-macro",
"wee_alloc",
]
[[package]]
@ -83,24 +87,12 @@ version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
[[package]]
name = "mino"
version = "0.1.0"
@ -235,7 +227,7 @@ version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"wasm-bindgen-macro",
]
@ -283,40 +275,6 @@ version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
[[package]]
name = "wee_alloc"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"cfg-if 0.1.10",
"libc",
"memory_units",
"winapi",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.7.32"

View File

@ -13,6 +13,4 @@ mino = { path = "../mino" }
wasm-bindgen = "0.2"
wasm-bindgen-macro = "0.2"
wee_alloc = "0.4"
# console_error_panic_hook = "0.1.7"
console_error_panic_hook = "0.1.7"

View File

@ -3,10 +3,7 @@ use wasm_bindgen_macro::wasm_bindgen;
use fish::{Bot, Weights};
use mino::srs::{PieceType, Queue};
use mino::{MatBuf, Rot};
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
use mino::MatBuf;
struct State {
weights: Weights,
@ -30,6 +27,7 @@ impl State {
#[wasm_bindgen(start)]
fn start() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
unsafe { STATE.write(State::new()) };
}
@ -47,7 +45,7 @@ pub fn get_config() -> Vec<i32> {
}
#[wasm_bindgen]
pub fn suggest(matrix: String, hold: String, next: String) -> Result<String, String> {
pub fn suggest(matrix: String, hold: String, next: String) -> Result<Vec<i32>, String> {
let matrix = parse_matrix(&matrix);
let hold = parse_hold(&hold)?;
let next = parse_queue(&next)?;
@ -61,22 +59,12 @@ pub fn suggest(matrix: String, hold: String, next: String) -> Result<String, Str
bot.suggest().ok_or("No suggestion found")?
};
Ok(format!(
"{x},{y},{r},{ty}",
x = res.loc.x,
y = res.loc.y,
r = rot(res.loc.r),
ty = res.ty
))
}
fn rot(r: Rot) -> &'static str {
match r {
Rot::N => "spawn",
Rot::E => "right",
Rot::S => "reverse",
Rot::W => "left",
}
Ok(vec![
res.loc.x as i16 as i32,
res.loc.y as i16 as i32,
res.loc.r as i8 as i32,
res.ty as u8 as i32,
])
}
fn parse_matrix(s: &str) -> MatBuf {

View File

@ -19,10 +19,11 @@ async function handle(msg) {
case 'suggest':
{
let res = suggest(msg.state.matrix, msg.state.hold, msg.state.next);
let [x, y, r, type] = res.split(',');
x = +x, y = +y;
return { moves: [{ x, y, r, type }] };
let [x, y, r, type] = suggest(msg.state.matrix, msg.state.hold, msg.state.next);
console.log(x,y,r,type);
r = ['north', 'right', 'south', 'west'][r];
type = 'IJLOSTZ'[type];
return { x, y, r, type };
}
default: