@@ -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 } ;
@@ -608,7 +609,7 @@ impl BoardMap {
608609 legal_positions
609610 }
610611 /// generate all possible move position for piece
611- pub fn gen_to_positions ( & self , from : Position ) -> Vec < Position > {
612+ pub fn gen_to_positions ( & self , from : Position ) -> ArrayVec < Position , 32 > {
612613 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
613614 if let Some ( piece_type) = piece_from. get_type ( ) {
614615 return match piece_type {
@@ -620,11 +621,12 @@ impl BoardMap {
620621 PieceType :: Knight => self . gen_knight ( from) ,
621622 } ;
622623 }
623- vec ! [ ]
624+
625+ ArrayVec :: new ( )
624626 }
625- pub fn gen_sliding ( & self , from : Position , piece_type : PieceType ) -> Vec < Position > {
627+ pub fn gen_sliding ( & self , from : Position , piece_type : PieceType ) -> ArrayVec < Position , 32 > {
626628 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
627- let mut positions = vec ! [ ] ;
629+ let mut positions = ArrayVec :: new ( ) ;
628630 let start = if piece_type == PieceType :: Bishop {
629631 4
630632 } else {
@@ -653,9 +655,9 @@ impl BoardMap {
653655 }
654656 positions
655657 }
656- pub fn gen_king ( & self , from : Position ) -> Vec < Position > {
658+ pub fn gen_king ( & self , from : Position ) -> ArrayVec < Position , 32 > {
657659 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
658- let mut positions = vec ! [ ] ;
660+ let mut positions = ArrayVec :: new ( ) ;
659661 for ( direction, offset) in DIRECTION_OFFSETS . iter ( ) . enumerate ( ) {
660662 let index = from[ 0 ] * 8 + from[ 1 ] ;
661663 let target_index = index as i32 + offset;
@@ -698,9 +700,9 @@ impl BoardMap {
698700
699701 positions
700702 }
701- pub fn gen_pawn ( & self , from : Position ) -> Vec < Position > {
703+ pub fn gen_pawn ( & self , from : Position ) -> ArrayVec < Position , 32 > {
702704 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
703- let mut moves = vec ! [ ] ;
705+ let mut moves = ArrayVec :: new ( ) ;
704706 let shift = match piece_from. get_color ( ) {
705707 PieceColor :: Black => 1 ,
706708 PieceColor :: White => -1 ,
@@ -776,7 +778,7 @@ impl BoardMap {
776778 }
777779 moves
778780 }
779- pub fn gen_knight ( & self , from : Position ) -> Vec < Position > {
781+ pub fn gen_knight ( & self , from : Position ) -> ArrayVec < Position , 32 > {
780782 let piece_from = self . squares [ from[ 0 ] ] [ from[ 1 ] ] ;
781783 KNIGHT_DIRECTION_OFFSETS
782784 . iter ( )
0 commit comments