return ints from suggest() and interpret them in worker.js
This commit is contained in:
parent
4b0f62aa59
commit
f92c586cfc
|
@ -3,7 +3,7 @@ use wasm_bindgen_macro::wasm_bindgen;
|
||||||
|
|
||||||
use fish::{Bot, Weights};
|
use fish::{Bot, Weights};
|
||||||
use mino::srs::{PieceType, Queue};
|
use mino::srs::{PieceType, Queue};
|
||||||
use mino::{MatBuf, Rot};
|
use mino::MatBuf;
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
weights: Weights,
|
weights: Weights,
|
||||||
|
@ -45,7 +45,7 @@ pub fn get_config() -> Vec<i32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[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 matrix = parse_matrix(&matrix);
|
||||||
let hold = parse_hold(&hold)?;
|
let hold = parse_hold(&hold)?;
|
||||||
let next = parse_queue(&next)?;
|
let next = parse_queue(&next)?;
|
||||||
|
@ -59,18 +59,12 @@ pub fn suggest(matrix: String, hold: String, next: String) -> Result<String, Str
|
||||||
bot.suggest().ok_or("No suggestion found")?
|
bot.suggest().ok_or("No suggestion found")?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(format!(
|
Ok(vec![
|
||||||
"{},{},{},{}",
|
res.loc.x as i16 as i32,
|
||||||
res.loc.x,
|
res.loc.y as i16 as i32,
|
||||||
res.loc.y,
|
res.loc.r as i8 as i32,
|
||||||
match res.loc.r {
|
res.ty as u8 as i32,
|
||||||
Rot::N => "spawn",
|
])
|
||||||
Rot::E => "right",
|
|
||||||
Rot::S => "reverse",
|
|
||||||
Rot::W => "left",
|
|
||||||
},
|
|
||||||
res.ty.name(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_matrix(s: &str) -> MatBuf {
|
fn parse_matrix(s: &str) -> MatBuf {
|
||||||
|
|
|
@ -19,9 +19,10 @@ async function handle(msg) {
|
||||||
|
|
||||||
case 'suggest':
|
case 'suggest':
|
||||||
{
|
{
|
||||||
let res = suggest(msg.state.matrix, msg.state.hold, msg.state.next);
|
let [x, y, r, type] = suggest(msg.state.matrix, msg.state.hold, msg.state.next);
|
||||||
let [x, y, r, type] = res.split(',');
|
console.log(x,y,r,type);
|
||||||
x = +x, y = +y;
|
r = ['north', 'right', 'south', 'west'][r];
|
||||||
|
type = 'IJLOSTZ'[type];
|
||||||
return { x, y, r, type };
|
return { x, y, r, type };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue