Skip to content

Commit

Permalink
Fix clippy lint issues
Browse files Browse the repository at this point in the history
This change fixes and/or silences all clippy lint issues.

`use chess::...` is changed to `use minorhacks_chess::...` to follow the
crate rename, to allow doc tests to pass once again.
  • Loading branch information
minor-fixes committed Apr 23, 2021
1 parent c8ed4f8 commit 4232f3c
Show file tree
Hide file tree
Showing 27 changed files with 9,993 additions and 9,234 deletions.
8 changes: 4 additions & 4 deletions src/bitboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, M
/// using the implemented operators to work with this object.
///
/// ```
/// use chess::{BitBoard, Square};
/// use minorhacks_chess::{BitBoard, Square};
///
/// let bb = BitBoard(7); // lower-left 3 squares
///
Expand All @@ -29,7 +29,7 @@ pub struct BitBoard(pub u64);
/// An empty bitboard. It is sometimes useful to use !EMPTY to get the universe of squares.
///
/// ```
/// use chess::EMPTY;
/// use minorhacks_chess::EMPTY;
///
/// assert_eq!(EMPTY.count(), 0);
///
Expand Down Expand Up @@ -262,7 +262,7 @@ impl fmt::Display for BitBoard {
s.push_str(". ");
}
if x % 8 == 7 {
s.push_str("\n");
s.push('\n');
}
}
write!(f, "{}", s)
Expand Down Expand Up @@ -291,7 +291,7 @@ impl BitBoard {
/// Convert an `Option<Square>` to an `Option<BitBoard>`
#[inline]
pub fn from_maybe_square(sq: Option<Square>) -> Option<BitBoard> {
sq.map(|s| BitBoard::from_square(s))
sq.map(BitBoard::from_square)
}

/// Convert a `BitBoard` to a `Square`. This grabs the least-significant `Square`
Expand Down
80 changes: 38 additions & 42 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Default for Board {
}
}

#[allow(clippy::derive_hash_xor_eq)]
impl Hash for Board {
fn hash<H: Hasher>(&self, state: &mut H) {
self.hash.hash(state);
Expand All @@ -77,9 +78,9 @@ impl Board {
/// Construct a board from a FEN string.
///
/// ```
/// use chess::Board;
/// use minorhacks_chess::Board;
/// use std::str::FromStr;
/// # use chess::Error;
/// # use minorhacks_chess::Error;
///
/// # fn main() -> Result<(), Error> {
///
Expand Down Expand Up @@ -117,7 +118,7 @@ impl Board {
/// Is this game Ongoing, is it Stalemate, or is it Checkmate?
///
/// ```
/// use chess::{Board, BoardStatus, Square, ChessMove};
/// use minorhacks_chess::{Board, BoardStatus, Square, ChessMove};
///
/// let mut board = Board::default();
///
Expand Down Expand Up @@ -171,7 +172,7 @@ impl Board {
/// Grab the "combined" `BitBoard`. This is a `BitBoard` with every piece.
///
/// ```
/// use chess::{Board, BitBoard, Rank, get_rank};
/// use minorhacks_chess::{Board, BitBoard, Rank, get_rank};
///
/// let board = Board::default();
///
Expand All @@ -191,7 +192,7 @@ impl Board {
/// color.
///
/// ```
/// use chess::{Board, BitBoard, Rank, get_rank, Color};
/// use minorhacks_chess::{Board, BitBoard, Rank, get_rank, Color};
///
/// let board = Board::default();
///
Expand All @@ -212,7 +213,7 @@ impl Board {
/// Give me the `Square` the `color` king is on.
///
/// ```
/// use chess::{Board, Square, Color};
/// use minorhacks_chess::{Board, Square, Color};
///
/// let board = Board::default();
///
Expand All @@ -227,7 +228,7 @@ impl Board {
/// Grab the "pieces" `BitBoard`. This is a `BitBoard` with every piece of a particular type.
///
/// ```
/// use chess::{Board, BitBoard, Piece, Square};
/// use minorhacks_chess::{Board, BitBoard, Piece, Square};
///
/// // The rooks should be in each corner of the board
/// let rooks = BitBoard::from_square(Square::A1) |
Expand All @@ -247,7 +248,7 @@ impl Board {
/// Grab the `CastleRights` for a particular side.
///
/// ```
/// use chess::{Board, Square, CastleRights, Color, ChessMove};
/// use minorhacks_chess::{Board, Square, CastleRights, Color, ChessMove};
///
/// let move1 = ChessMove::new(Square::A2,
/// Square::A4,
Expand Down Expand Up @@ -299,7 +300,7 @@ impl Board {
/// Remove castle rights for a particular side.
///
/// ```
/// use chess::{Board, CastleRights, Color};
/// use minorhacks_chess::{Board, CastleRights, Color};
///
/// let mut board = Board::default();
/// assert_eq!(board.castle_rights(Color::White), CastleRights::Both);
Expand All @@ -322,7 +323,7 @@ impl Board {
/// Who's turn is it?
///
/// ```
/// use chess::{Board, Color};
/// use minorhacks_chess::{Board, Color};
///
/// let mut board = Board::default();
/// assert_eq!(board.side_to_move(), Color::White);
Expand All @@ -335,7 +336,7 @@ impl Board {
/// Grab my `CastleRights`.
///
/// ```
/// use chess::{Board, Color, CastleRights};
/// use minorhacks_chess::{Board, Color, CastleRights};
///
/// let mut board = Board::default();
/// board.remove_castle_rights(Color::White, CastleRights::KingSide);
Expand Down Expand Up @@ -363,7 +364,7 @@ impl Board {
/// Remove some of my `CastleRights`.
///
/// ```
/// use chess::{Board, CastleRights};
/// use minorhacks_chess::{Board, CastleRights};
///
/// let mut board = Board::default();
/// assert_eq!(board.my_castle_rights(), CastleRights::Both);
Expand All @@ -385,7 +386,7 @@ impl Board {
/// My opponents `CastleRights`.
///
/// ```
/// use chess::{Board, Color, CastleRights};
/// use minorhacks_chess::{Board, Color, CastleRights};
///
/// let mut board = Board::default();
/// board.remove_castle_rights(Color::White, CastleRights::KingSide);
Expand Down Expand Up @@ -413,7 +414,7 @@ impl Board {
/// Remove some of my opponents `CastleRights`.
///
/// ```
/// use chess::{Board, CastleRights};
/// use minorhacks_chess::{Board, CastleRights};
///
/// let mut board = Board::default();
/// assert_eq!(board.their_castle_rights(), CastleRights::Both);
Expand Down Expand Up @@ -445,7 +446,7 @@ impl Board {
/// For a chess UI: set a piece on a particular square.
///
/// ```
/// use chess::{Board, Piece, Color, Square};
/// use minorhacks_chess::{Board, Piece, Color, Square};
///
/// let board = Board::default();
///
Expand Down Expand Up @@ -496,7 +497,7 @@ impl Board {
/// For a chess UI: clear a particular square.
///
/// ```
/// use chess::{Board, Square, Piece};
/// use minorhacks_chess::{Board, Square, Piece};
///
/// let board = Board::default();
///
Expand Down Expand Up @@ -547,7 +548,7 @@ impl Board {
/// always give the same result back.
///
/// ```
/// use chess::{Board, Color};
/// use minorhacks_chess::{Board, Color};
///
/// let board = Board::default();
///
Expand Down Expand Up @@ -575,7 +576,7 @@ impl Board {
/// This is for sanity checking.
///
/// ```
/// use chess::{Board, Color, Piece, Square};
/// use minorhacks_chess::{Board, Color, Piece, Square};
///
/// let board = Board::default();
///
Expand All @@ -589,10 +590,8 @@ impl Board {
// make sure there is no square with multiple pieces on it
for x in ALL_PIECES.iter() {
for y in ALL_PIECES.iter() {
if *x != *y {
if self.pieces(*x) & self.pieces(*y) != EMPTY {
return false;
}
if *x != *y && self.pieces(*x) & self.pieces(*y) != EMPTY {
return false;
}
}
}
Expand Down Expand Up @@ -661,12 +660,11 @@ impl Board {
}
// if we have castle rights, make sure we have a king on the (E, {1,8}) square,
// depending on the color
if castle_rights != CastleRights::NoRights {
if self.pieces(Piece::King) & self.color_combined(*color)
if castle_rights != CastleRights::NoRights
&& self.pieces(Piece::King) & self.color_combined(*color)
!= get_file(File::E) & get_rank(color.to_my_backrank())
{
return false;
}
{
return false;
}
}

Expand All @@ -676,7 +674,7 @@ impl Board {
}

// it checks out
return true;
true
}

/// Get a hash of the board.
Expand Down Expand Up @@ -714,7 +712,7 @@ impl Board {
/// What piece is on a particular `Square`? Is there even one?
///
/// ```
/// use chess::{Board, Piece, Square};
/// use minorhacks_chess::{Board, Piece, Square};
///
/// let board = Board::default();
///
Expand Down Expand Up @@ -745,14 +743,12 @@ impl Board {
} else {
Some(Piece::Bishop)
}
} else if self.pieces(Piece::Rook) & opp != EMPTY {
Some(Piece::Rook)
} else if self.pieces(Piece::Queen) & opp != EMPTY {
Some(Piece::Queen)
} else {
if self.pieces(Piece::Rook) & opp != EMPTY {
Some(Piece::Rook)
} else if self.pieces(Piece::Queen) & opp != EMPTY {
Some(Piece::Queen)
} else {
Some(Piece::King)
}
Some(Piece::King)
}
}
}
Expand All @@ -777,7 +773,7 @@ impl Board {
/// Give me the en_passant square, if it exists.
///
/// ```
/// use chess::{Board, ChessMove, Square};
/// use minorhacks_chess::{Board, ChessMove, Square};
///
/// let move1 = ChessMove::new(Square::D2,
/// Square::D4,
Expand Down Expand Up @@ -825,7 +821,7 @@ impl Board {
/// input.
///
/// ```
/// use chess::{Board, ChessMove, Square, MoveGen};
/// use minorhacks_chess::{Board, ChessMove, Square, MoveGen};
///
/// let move1 = ChessMove::new(Square::E2,
/// Square::E4,
Expand All @@ -842,15 +838,15 @@ impl Board {
/// ```
#[inline]
pub fn legal(&self, m: ChessMove) -> bool {
MoveGen::new_legal(&self).find(|x| *x == m).is_some()
MoveGen::new_legal(&self).any(|x| x == m)
}

/// Make a chess move onto a new board.
///
/// panic!() if king is captured.
///
/// ```
/// use chess::{Board, ChessMove, Square, Color};
/// use minorhacks_chess::{Board, ChessMove, Square, Color};
///
/// let m = ChessMove::new(Square::D2,
/// Square::D4,
Expand All @@ -873,7 +869,7 @@ impl Board {
/// panic!() if king is captured.
///
/// ```
/// use chess::{Board, ChessMove, Square, Color};
/// use minorhacks_chess::{Board, ChessMove, Square, Color};
///
/// let m = ChessMove::new(Square::D2,
/// Square::D4,
Expand Down Expand Up @@ -1105,7 +1101,7 @@ impl FromStr for Board {
type Err = Error;

fn from_str(value: &str) -> Result<Self, Self::Err> {
Ok(BoardBuilder::from_str(value)?.try_into()?)
BoardBuilder::from_str(value)?.try_into()
}
}

Expand Down
Loading

0 comments on commit 4232f3c

Please sign in to comment.