From c1344a355349bd8fb52244ec852ca6e50811dd5d Mon Sep 17 00:00:00 2001 From: Valentin Heiserer Date: Fri, 31 Oct 2025 00:14:59 +0100 Subject: [PATCH] clippy format --- schafkopf-logic/src/deck/mod.rs | 6 ++++++ schafkopf-logic/src/gamemode/mod.rs | 8 ++++---- schafkopf-logic/src/main.rs | 8 +++----- schafkopf-logic/src/player/mod.rs | 8 +++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/schafkopf-logic/src/deck/mod.rs b/schafkopf-logic/src/deck/mod.rs index abf6ce6..7a70f9a 100644 --- a/schafkopf-logic/src/deck/mod.rs +++ b/schafkopf-logic/src/deck/mod.rs @@ -16,6 +16,12 @@ pub struct Deck { cards: Vec, } +impl Default for Deck { + fn default() -> Self { + Self::new() + } +} + impl Deck { pub fn new() -> Self { let cards = Suit::iter() diff --git a/schafkopf-logic/src/gamemode/mod.rs b/schafkopf-logic/src/gamemode/mod.rs index bfa1f2a..ab5f3c3 100644 --- a/schafkopf-logic/src/gamemode/mod.rs +++ b/schafkopf-logic/src/gamemode/mod.rs @@ -21,7 +21,7 @@ impl Gamemode { } } -fn winner_for_wenz<'a>(rank: Rank, trump_suit: Option, cards: [&'a Card; 4]) -> &'a Card { +fn winner_for_wenz(rank: Rank, trump_suit: Option, cards: [&Card; 4]) -> &Card { let ranks = [rank]; if cards.iter().any(|&c| is_trump(c, &ranks, trump_suit)) { @@ -46,7 +46,7 @@ fn winner_for_wenz<'a>(rank: Rank, trump_suit: Option, cards: [&'a Card; 4 } } -fn winner_for_trump<'a>(trump_suit: Suit, cards: [&'a Card; 4]) -> &'a Card { +fn winner_for_trump(trump_suit: Suit, cards: [&Card; 4]) -> &Card { let ranks = [Rank::Ober, Rank::Unter]; if cards.iter().any(|&c| is_trump(c, &ranks, Some(trump_suit))) { // Highest trump wins @@ -73,7 +73,7 @@ fn winner_for_trump<'a>(trump_suit: Suit, cards: [&'a Card; 4]) -> &'a Card { } fn is_trump(card: &Card, trump_ranks: &[Rank], trump_suit: Option) -> bool { - trump_ranks.iter().any(|&r| card.rank == r) || trump_suit.map_or(false, |s| card.suit == s) + trump_ranks.contains(&card.rank) || (trump_suit == Some(card.suit)) } // Trump strength according to Schafkopf: @@ -92,7 +92,7 @@ fn trump_strength(card: &Card, trump_suit: Suit) -> u16 { fn trump_strength_wenz(card: &Card, rank: Rank, trump_suit: Option) -> u16 { if card.rank == rank { 200 + ober_unter_suit_strength(card.suit) - } else if trump_suit.map_or(false, |s| card.suit == s) { + } else if trump_suit == Some(card.suit) { 100 + non_trump_strength(card.rank) as u16 } else { 0 diff --git a/schafkopf-logic/src/main.rs b/schafkopf-logic/src/main.rs index c538aa3..fdc68f5 100644 --- a/schafkopf-logic/src/main.rs +++ b/schafkopf-logic/src/main.rs @@ -1,7 +1,6 @@ use bevy::{ asset::{AssetMetaCheck, AssetPlugin, RenderAssetUsages}, prelude::*, - sprite::Anchor, render::render_resource::{Extent3d, TextureDimension, TextureFormat}, }; use schafkopf_logic::{ @@ -10,7 +9,6 @@ use schafkopf_logic::{ player::{HumanPlayer, InternalPlayer}, }; -use std::fmt::Debug; const CARD_TEXTURE_WIDTH: usize = 96; @@ -94,7 +92,7 @@ fn setup_game( let mut deck = Deck::new(); deck.shuffle(); - let [mut hand1, mut hand2, mut hand3, mut hand4] = + let [mut hand1, hand2, hand3, hand4] = deck.deal_4x8().expect("expected a full deck to deal four hands"); sort_cards(&mut hand1); @@ -131,7 +129,7 @@ fn spawn_player_hand( let base_handle = create_card_texture(&mut images, card); let parent = commands - .spawn((Transform::from_xyz(start_x + i as f32 * spacing, y, 0.0))) + .spawn(Transform::from_xyz(start_x + i as f32 * spacing, y, 0.0)) .id(); commands.entity(parent).with_children(|c| { @@ -146,7 +144,7 @@ fn spawn_player_hand( )) .observe(on_hover()) .observe(on_unhover()) - .observe(on_click(card.clone())); + .observe(on_click(*card)); c.spawn(( Sprite::from_atlas_image( diff --git a/schafkopf-logic/src/player/mod.rs b/schafkopf-logic/src/player/mod.rs index 91026c5..9eb3f30 100644 --- a/schafkopf-logic/src/player/mod.rs +++ b/schafkopf-logic/src/player/mod.rs @@ -111,13 +111,11 @@ impl InternalPlayer for HumanPlayer { let _ = io::stdout().flush(); let mut input = String::new(); - if io::stdin().read_line(&mut input).is_ok() { - if let Ok(idx) = input.trim().parse::() { - if idx < self.hand.len() { + if io::stdin().read_line(&mut input).is_ok() + && let Ok(idx) = input.trim().parse::() + && idx < self.hand.len() { return Ok(self.hand.remove(idx)); } - } - } // fallback: pop last self.hand.pop().ok_or(PlayerError::NoCards)