use bitvec
This commit is contained in:
11
src/board.rs
11
src/board.rs
@@ -8,6 +8,7 @@ use lazy_static::lazy_static;
|
||||
use std::{cmp::Ordering, fmt};
|
||||
|
||||
pub const BOARD_SIZE: usize = 8;
|
||||
pub const BOARD_AREA: usize = BOARD_SIZE * BOARD_SIZE;
|
||||
|
||||
/// A chain of positions across the board
|
||||
type Chain = ArrayVec<(usize, usize), BOARD_SIZE>;
|
||||
@@ -115,7 +116,7 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn starting_pos(mut self) -> Self {
|
||||
pub fn starting_pos(mut self) -> Self {
|
||||
self.place_unchecked((BOARD_SIZE / 2) - 1, (BOARD_SIZE / 2) - 1, Piece::White);
|
||||
self.place_unchecked(BOARD_SIZE / 2, (BOARD_SIZE / 2) - 1, Piece::Black);
|
||||
self.place_unchecked((BOARD_SIZE / 2) - 1, BOARD_SIZE / 2, Piece::Black);
|
||||
@@ -133,7 +134,7 @@ impl Board {
|
||||
|
||||
/// Returns a reference to a place on the [`Board`]
|
||||
/// at (i, j)
|
||||
pub const fn get(&self, i: usize, j: usize) -> Option<Piece> {
|
||||
pub fn get(&self, i: usize, j: usize) -> Option<Piece> {
|
||||
let white = self.white_board.get(i, j);
|
||||
let black = self.black_board.get(i, j);
|
||||
if white {
|
||||
@@ -145,7 +146,7 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
const fn place_unchecked(&mut self, i: usize, j: usize, piece: Piece) {
|
||||
fn place_unchecked(&mut self, i: usize, j: usize, piece: Piece) {
|
||||
match piece {
|
||||
Piece::Black => {
|
||||
self.black_board.set(i, j, true);
|
||||
@@ -175,14 +176,14 @@ impl Board {
|
||||
self.get(i, j).is_none() && !self.propegate_from_dry(i, j, piece).is_empty()
|
||||
}
|
||||
|
||||
pub fn place(&mut self, i: usize, j: usize, piece: Piece) -> Result<(), String> {
|
||||
pub fn place(&mut self, i: usize, j: usize, piece: Piece) -> Result<(), &'static str> {
|
||||
if let Some(what_if_result) = self.what_if(i, j, piece) {
|
||||
if what_if_result.1 > 0 {
|
||||
*self = what_if_result.0;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err("move would not propegate".to_string())
|
||||
Err("move would not propegate")
|
||||
}
|
||||
|
||||
fn propegate_from(&mut self, i: usize, j: usize) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user