Skip to content

Commit 226ccfa

Browse files
committed
chore: add a separate Piece type
1 parent d4d5919 commit 226ccfa

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

games/src/ataxx/piece.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ impl ops::Not for Color {
3535
}
3636
}
3737

38+
representable_type!(
39+
/// Piece represents the types of pieces in ataxx, namely Piece and Block.
40+
enum Piece: u8 { Piece "x", Block "■", }
41+
);
42+
3843
representable_type!(
3944
/// Piece represents all the possible ataxx pieces.
4045
enum ColoredPiece: u8 { Black "x", White "o", Block "■", }
4146
);
4247

4348
impl ColoredPieceType for ColoredPiece {
44-
type Piece = Color;
49+
type Piece = Piece;
4550
type Color = Color;
4651

47-
fn piece(self) -> Color {
52+
fn piece(self) -> Piece {
4853
match self {
49-
ColoredPiece::Black => Color::Black,
50-
ColoredPiece::White => Color::White,
51-
_ => panic!("Piece::color() called on Piece::Block"),
54+
ColoredPiece::Black | ColoredPiece::White => Piece::Piece,
55+
ColoredPiece::Block => Piece::Block,
5256
}
5357
}
5458

games/src/ataxx/position.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use thiserror::Error;
2727
#[rustfmt::skip]
2828
use crate::ataxx::{
2929
BitBoard, ColoredPiece, File, Hash, Move,
30-
Rank, Square, Color
30+
Rank, Square, Color, Piece
3131
};
3232
use crate::interface::MoveStore;
3333

@@ -83,7 +83,7 @@ impl PositionType for Position {
8383
}
8484
}
8585

86-
fn piece_bb(&self, piece: Color) -> BitBoard {
86+
fn piece_bb(&self, piece: Piece) -> BitBoard {
8787
self.bitboards[piece as usize]
8888
}
8989

0 commit comments

Comments
 (0)