Skip to content

Commit

Permalink
style: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Sep 26, 2024
1 parent d055366 commit 337211e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 40 deletions.
22 changes: 9 additions & 13 deletions crates/game-solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ fn negamax<T: Game<Player = impl TwoPlayer + 'static> + Eq + Hash>(
} else {
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
} else if stats.original_player == winning_player {
stats.terminal_ends.winning.fetch_add(1, Ordering::Relaxed);
} else {
if stats.original_player == winning_player {
stats.terminal_ends.winning.fetch_add(1, Ordering::Relaxed);
} else {
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
}

Expand Down Expand Up @@ -131,12 +129,10 @@ fn negamax<T: Game<Player = impl TwoPlayer + 'static> + Eq + Hash>(
} else {
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
} else if stats.original_player == winning_player {
stats.terminal_ends.winning.fetch_add(1, Ordering::Relaxed);
} else {
if stats.original_player == winning_player {
stats.terminal_ends.winning.fetch_add(1, Ordering::Relaxed);
} else {
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
stats.terminal_ends.losing.fetch_add(1, Ordering::Relaxed);
}
}

Expand Down Expand Up @@ -197,7 +193,7 @@ fn negamax<T: Game<Player = impl TwoPlayer + 'static> + Eq + Hash>(
-beta,
-alpha,
stats,
&cancellation_token,
cancellation_token,
)?
} else {
let score = -negamax(
Expand All @@ -206,7 +202,7 @@ fn negamax<T: Game<Player = impl TwoPlayer + 'static> + Eq + Hash>(
-alpha - 1,
-alpha,
stats,
&cancellation_token,
cancellation_token,
)?;
if score > alpha {
-negamax(
Expand All @@ -215,7 +211,7 @@ fn negamax<T: Game<Player = impl TwoPlayer + 'static> + Eq + Hash>(
-beta,
-alpha,
stats,
&cancellation_token,
cancellation_token,
)?
} else {
score
Expand Down
2 changes: 1 addition & 1 deletion crates/games/src/chomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Display for Chomp {

impl Debug for Chomp {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<Self as Display>::fmt(&self, f)
<Self as Display>::fmt(self, f)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/games/src/domineering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<const WIDTH: usize, const HEIGHT: usize> Display for Domineering<WIDTH, HEI

impl<const WIDTH: usize, const HEIGHT: usize> Debug for Domineering<WIDTH, HEIGHT> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<Self as Display>::fmt(&self, f)
<Self as Display>::fmt(self, f)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/games/src/nim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Display for Nim {

impl Debug for Nim {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
<Self as Display>::fmt(&self, f)
<Self as Display>::fmt(self, f)
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ mod tests {
#[test]
fn max_moves_is_heap_sum() {
assert_eq!(Nim::new(vec![3, 5, 7]).max_moves(), Some(3 + 5 + 7));
assert_eq!(Nim::new(vec![0, 2, 2]).max_moves(), Some(0 + 2 + 2));
assert_eq!(Nim::new(vec![0, 2, 2]).max_moves(), Some(2 + 2));
}

#[test]
Expand Down
5 changes: 2 additions & 3 deletions crates/games/src/order_and_chaos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<
> Debug for OrderAndChaos<WIDTH, HEIGHT, MIN_WIN_LENGTH, MAX_WIN_LENGTH>
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<Self as Display>::fmt(&self, f)
<Self as Display>::fmt(self, f)
}
}

Expand Down Expand Up @@ -347,14 +347,13 @@ mod tests {
fn from_string(string: &str) -> OrderAndChaos<6, 6, 5, 6> {
let board_internal = string
.chars()
.map(|ch| match ch {
.filter_map(|ch| match ch {
'X' => Some(Some(CellType::X)),
'O' => Some(Some(CellType::O)),
'.' => Some(None),
'\n' => None,
_ => panic!("There shouldn't be other characters in the string!"),
})
.filter_map(|x| x)
.collect::<Vec<_>>();

let element_count = board_internal.iter().filter(|x| x.is_some()).count();
Expand Down
2 changes: 1 addition & 1 deletion crates/games/src/reversi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl fmt::Display for Reversi {

impl Debug for Reversi {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as fmt::Display>::fmt(&self, f)
<Self as fmt::Display>::fmt(self, f)
}
}

Expand Down
16 changes: 6 additions & 10 deletions crates/games/src/sprouts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ impl PartialEq for Sprouts {
&& self.0.edge_references().collect::<Vec<_>>()
== other.0.edge_references().collect::<Vec<_>>()
}

fn ne(&self, other: &Self) -> bool {
!self.eq(other)
}
}

impl Eq for Sprouts {}
Expand Down Expand Up @@ -119,22 +115,22 @@ impl Game for Sprouts {
fn make_move(&mut self, m: &Self::Move) -> Result<(), Self::MoveError> {
// There already exists an edge here!
if self.0.has_edge(m.from, m.to) {
return Err(SproutsMoveError::SproutsConnected(m.clone()));
return Err(SproutsMoveError::SproutsConnected(*m));
}

// move index is out of bounds
{
if !self.0.node_identifiers().contains(&m.from) {
return Err(SproutsMoveError::MoveOutOfBounds(
m.from.index().try_into().unwrap(),
m.clone(),
*m,
));
}

if !self.0.node_identifiers().contains(&m.to) {
return Err(SproutsMoveError::MoveOutOfBounds(
m.to.index().try_into().unwrap(),
m.clone(),
*m,
));
}
}
Expand All @@ -144,14 +140,14 @@ impl Game for Sprouts {
if self.0.edges(m.from).count() >= MAX_SPROUTS {
return Err(SproutsMoveError::DeadSprout(
m.from.index().try_into().unwrap(),
m.clone(),
*m,
));
}

if self.0.edges(m.to).count() >= MAX_SPROUTS {
return Err(SproutsMoveError::DeadSprout(
m.to.index().try_into().unwrap(),
m.clone(),
*m,
));
}
}
Expand Down Expand Up @@ -244,7 +240,7 @@ impl Debug for Sprouts {

impl Display for Sprouts {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
<Self as Debug>::fmt(&self, f)
<Self as Debug>::fmt(self, f)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/games/src/tic_tac_toe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl TicTacToe {
fn winning_line(&self, point: &Dim<IxDynImpl>, offset: &[i32]) -> Option<Square> {
let square = self.board.get(point).unwrap();

if *square == None {
if square.is_none() {
return None;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ impl Game for TicTacToe {

// check every move
for (index, square) in self.board.indexed_iter() {
if square == &None {
if square.is_none() {
continue;
}

Expand All @@ -220,7 +220,7 @@ impl Game for TicTacToe {
}

fn make_move(&mut self, m: &Self::Move) -> Result<(), Self::MoveError> {
if *self.board.get(m.0.clone()).unwrap() == None {
if self.board.get(m.0.clone()).unwrap().is_none() {
let square = Square::from_player(self.player());

*self.board.get_mut(m.0.clone()).unwrap() = Some(square);
Expand All @@ -235,7 +235,7 @@ impl Game for TicTacToe {
self.board
.indexed_iter()
.filter_map(move |(index, square)| {
if square == &None {
if square.is_none() {
Some(TicTacToeMove(index))
} else {
None
Expand Down Expand Up @@ -320,7 +320,7 @@ impl Display for TicTacToe {

impl Debug for TicTacToe {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
<Self as Display>::fmt(&self, f)
<Self as Display>::fmt(self, f)
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/games/src/util/cli/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ impl<G: Game> App<G> {
}

fn handle_key_event(&mut self, key_event: KeyEvent) {
match key_event.code {
KeyCode::Char('q') => self.exit(),
_ => {}
if let KeyCode::Char('q') = key_event.code {
self.exit()
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/nimnim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ impl Add for Nimber {
type Output = Nimber;

fn add(self, rhs: Self) -> Self::Output {
return Nimber(self.0 ^ rhs.0);
// bitxor is the way nimbers are added.
#[allow(clippy::suspicious_arithmetic_impl)]
Nimber(self.0 ^ rhs.0)
}
}

Expand Down

0 comments on commit 337211e

Please sign in to comment.