vampirc / vampirc-uci

A Universal Chess Interface (UCI) protocol parser and message generator.
https://vampirc.kejzar.si
Apache License 2.0
19 stars 7 forks source link

Integration to the chess crate #8

Closed UlisseMini closed 4 years ago

UlisseMini commented 4 years ago

It would be nice to support native integration into the chess crate, I understand you may not want to depend on it simply for a nicer API for the people who happen to be using it, but I think (i'm a beginner) it should be possible to hide such an API behind some sort of compile time checks.

Just my 2 cents, likely i'm totally wrong.

UlisseMini commented 4 years ago

I "solved" my problem by writing this

use vampirc_uci as uci;

pub fn to_chess_square(uci_square: uci::UciSquare) -> chess::Square {
    chess::Square::make_square(
        chess::Rank::from_index(uci_square.rank as usize - 1),
        chess::File::from_index(uci_square.file as usize - 'a' as usize),
    )
}

pub fn to_chess_piece(uci_piece: uci::UciPiece) -> chess::Piece {
    use chess::Piece;
    use vampirc_uci::UciPiece::*;
    match uci_piece {
        King => Piece::King,
        Queen => Piece::Queen,
        Knight => Piece::Knight,
        Pawn => Piece::Pawn,
        Bishop => Piece::Bishop,
        Rook => Piece::Rook,
    }
}

pub fn to_chess_move(uci_move: uci::UciMove) -> chess::ChessMove {
    let from = to_chess_square(uci_move.from);
    let to = to_chess_square(uci_move.to);

    let mut promo = None;
    if uci_move.promotion.is_some() {
        promo = Some(to_chess_piece(uci_move.promotion.unwrap()));
    }

    chess::ChessMove::new(from, to, promo)
}

but that is hardly a solution

MadMatt04 commented 4 years ago

Yeah, vampirc has its own move generation and representation of chess concepts (currently not public), but in theory it would be easy to do this as an optional dependency.

MadMatt04 commented 4 years ago

Implemented in #11, to be released as 0.9.0.

MadMatt04 commented 4 years ago

Released in 0.9.0.