@@ -6,6 +6,7 @@ use crate::piece::{piece_type::*, Piece};
66use crate :: piece_color:: PieceColor ;
77use crate :: uci_move:: { UciMove , UciMoveType , NON_PAWN_SYMBOLS } ;
88use anyhow:: { anyhow, Result } ;
9+ use arrayvec:: ArrayVec ;
910use std:: borrow:: BorrowMut ;
1011use std:: cmp:: min;
1112use std:: fmt:: { Debug , Formatter } ;
@@ -619,7 +620,7 @@ impl BoardMap {
619620 legal_positions
620621 }
621622 /// generate all possible move position for piece
622- pub fn gen_to_positions ( & self , from : Position ) -> Vec < Position > {
623+ pub fn gen_to_positions ( & self , from : Position ) -> ArrayVec < Position , 32 > {
623624 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
624625 if let Some ( piece_type) = piece_from. get_type ( ) {
625626 return match piece_type {
@@ -631,11 +632,12 @@ impl BoardMap {
631632 PieceType :: Knight => self . gen_knight ( from) ,
632633 } ;
633634 }
634- vec ! [ ]
635+
636+ ArrayVec :: new ( )
635637 }
636- pub fn gen_sliding ( & self , from : Position , piece_type : PieceType ) -> Vec < Position > {
638+ pub fn gen_sliding ( & self , from : Position , piece_type : PieceType ) -> ArrayVec < Position , 32 > {
637639 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
638- let mut positions = vec ! [ ] ;
640+ let mut positions = ArrayVec :: new ( ) ;
639641 let start = if piece_type == PieceType :: Bishop {
640642 4
641643 } else {
@@ -664,9 +666,9 @@ impl BoardMap {
664666 }
665667 positions
666668 }
667- pub fn gen_king ( & self , from : Position ) -> Vec < Position > {
669+ pub fn gen_king ( & self , from : Position ) -> ArrayVec < Position , 32 > {
668670 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
669- let mut positions = vec ! [ ] ;
671+ let mut positions = ArrayVec :: new ( ) ;
670672 for ( direction, offset) in DIRECTION_OFFSETS . iter ( ) . enumerate ( ) {
671673 let index = from[ 0 ] * 8 + from[ 1 ] ;
672674 let target_index = index as i32 + offset;
@@ -709,9 +711,9 @@ impl BoardMap {
709711
710712 positions
711713 }
712- pub fn gen_pawn ( & self , from : Position ) -> Vec < Position > {
714+ pub fn gen_pawn ( & self , from : Position ) -> ArrayVec < Position , 32 > {
713715 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
714- let mut moves = vec ! [ ] ;
716+ let mut moves = ArrayVec :: new ( ) ;
715717 let shift = match piece_from. get_color ( ) {
716718 PieceColor :: Black => 1 ,
717719 PieceColor :: White => -1 ,
@@ -787,7 +789,7 @@ impl BoardMap {
787789 }
788790 moves
789791 }
790- pub fn gen_knight ( & self , from : Position ) -> Vec < Position > {
792+ pub fn gen_knight ( & self , from : Position ) -> ArrayVec < Position , 32 > {
791793 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
792794 KNIGHT_DIRECTION_OFFSETS
793795 . iter ( )
0 commit comments