Skip to content

Commit 463bf7e

Browse files
committed
add arrayvec
1 parent 240aa31 commit 463bf7e

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

check-buddy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = ["chess", "chess-engine"]
1313
rand = "0.9"
1414
anyhow = "1"
1515
thiserror = "2"
16+
arrayvec = "0.7.6"
1617

1718
[dev-dependencies]
1819
calamine = "0.32.0"

check-buddy/src/board.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::piece::{piece_type::*, Piece};
66
use crate::piece_color::PieceColor;
77
use crate::uci_move::{UciMove, UciMoveType, NON_PAWN_SYMBOLS};
88
use anyhow::{anyhow, Result};
9+
use arrayvec::ArrayVec;
910
use std::borrow::BorrowMut;
1011
use std::cmp::min;
1112
use 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

Comments
 (0)