Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aadi123 committed Oct 10, 2023
1 parent 62a9b65 commit 9ca2cab
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chess::{Board, ChessMove, Error, MoveGen, Piece, Square};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn get_next_move(fen: &str) -> String {
pub fn get_next_move(fen: &str) -> JsValue {
let res: Result<Board, Error> = Board::from_str(fen);
let board = match res {
Ok(b) => b,
Expand All @@ -14,7 +14,9 @@ pub fn get_next_move(fen: &str) -> String {

for chess_move in movegen {
// This move does not capture anything
return chess_move.to_string();
return JsValue::from_str(&chess_move.to_string());
}
return ChessMove::new(Square::E4, Square::E4, Some(Piece::Queen)).to_string();
return JsValue::from_str(
&ChessMove::new(Square::E4, Square::E4, Some(Piece::Queen)).to_string(),
);
}

0 comments on commit 9ca2cab

Please sign in to comment.