Skip to content

Commit df281cd

Browse files
committed
add arrayvec
1 parent 056684f commit df281cd

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};
@@ -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

Comments
 (0)