fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
pub mod benchmark;
|
pub mod benchmark;
|
||||||
pub mod play;
|
pub mod play;
|
||||||
|
pub mod selfplay;
|
||||||
pub mod train;
|
pub mod train;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
|
pub fn run() {}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
pub fn run() {}
|
||||||
+37
-10
@@ -249,25 +249,20 @@ pub fn decode_move(idx: usize, board: &Board) -> Option<ChessMove> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default pawn moves to final rank (perspective fr == 6 -> tr == 7) to Queen promotion if not underpromotion
|
let stm = board.side_to_move();
|
||||||
|
|
||||||
|
// Default pawn moves to final rank (perspective fr == 6 -> tr == 7) to Queen promotion if not underpromotion.
|
||||||
|
// fr/ff are perspective coordinates, so deorient back to real squares before inspecting the board.
|
||||||
if promo.is_none()
|
if promo.is_none()
|
||||||
&& fr == 6
|
&& fr == 6
|
||||||
&& tr == 7
|
&& tr == 7
|
||||||
&& dy == 1
|
&& dy == 1
|
||||||
&& dx.abs() <= 1
|
&& dx.abs() <= 1
|
||||||
&& board.piece_on(Square::make_square(
|
&& board.piece_on(deorient_square(ff, fr, stm)) == Some(Piece::Pawn)
|
||||||
Rank::from_index(fr as usize),
|
|
||||||
File::from_index(ff as usize),
|
|
||||||
)) == Some(Piece::Pawn)
|
|
||||||
{
|
{
|
||||||
promo = Some(Piece::Queen);
|
promo = Some(Piece::Queen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if fr == 6 && tr == 7 && dy == 1 && dx.abs() <= 1 && promo.is_none() {
|
|
||||||
// promo = Some(Piece::Queen);
|
|
||||||
// }
|
|
||||||
|
|
||||||
let stm = board.side_to_move();
|
|
||||||
let from = deorient_square(ff, fr, stm);
|
let from = deorient_square(ff, fr, stm);
|
||||||
let to = deorient_square(tf, tr, stm);
|
let to = deorient_square(tf, tr, stm);
|
||||||
|
|
||||||
@@ -349,4 +344,36 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(mv, dec);
|
assert_eq!(mv, dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn queen_promotion_roundtrip_black() {
|
||||||
|
// Black pawn on d2, white king on h1, black king on e8, black to move.
|
||||||
|
// d2-d1 is a legal promotion; d1 is empty.
|
||||||
|
let board = Board::from_str("4k3/8/8/8/8/8/3p4/7K b - - 0 1").unwrap();
|
||||||
|
|
||||||
|
let from = Square::make_square(Rank::Second, File::D);
|
||||||
|
let to = Square::make_square(Rank::First, File::D);
|
||||||
|
|
||||||
|
let mv = ChessMove::new(from, to, Some(Piece::Queen));
|
||||||
|
|
||||||
|
let enc = encode_move(mv, Color::Black).unwrap();
|
||||||
|
let dec = decode_move(enc, &board).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(mv, dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn underpromotion_roundtrip_black() {
|
||||||
|
let board = Board::from_str("4k3/8/8/8/8/8/3p4/7K b - - 0 1").unwrap();
|
||||||
|
|
||||||
|
let from = Square::make_square(Rank::Second, File::D);
|
||||||
|
let to = Square::make_square(Rank::First, File::D);
|
||||||
|
|
||||||
|
let mv = ChessMove::new(from, to, Some(Piece::Knight));
|
||||||
|
|
||||||
|
let enc = encode_move(mv, Color::Black).unwrap();
|
||||||
|
let dec = decode_move(enc, &board).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(mv, dec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
use chess::{ChessMove, Game};
|
use chess::{ChessMove, Game};
|
||||||
use engine::{legal_action_mask, Engine};
|
use engine::Engine;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user