clippy format

This commit is contained in:
2025-10-31 00:14:59 +01:00
parent 6efdc7a0d0
commit c1344a3553
4 changed files with 16 additions and 14 deletions

View File

@@ -16,6 +16,12 @@ pub struct Deck {
cards: Vec<Card>, cards: Vec<Card>,
} }
impl Default for Deck {
fn default() -> Self {
Self::new()
}
}
impl Deck { impl Deck {
pub fn new() -> Self { pub fn new() -> Self {
let cards = Suit::iter() let cards = Suit::iter()

View File

@@ -21,7 +21,7 @@ impl Gamemode {
} }
} }
fn winner_for_wenz<'a>(rank: Rank, trump_suit: Option<Suit>, cards: [&'a Card; 4]) -> &'a Card { fn winner_for_wenz(rank: Rank, trump_suit: Option<Suit>, cards: [&Card; 4]) -> &Card {
let ranks = [rank]; let ranks = [rank];
if cards.iter().any(|&c| is_trump(c, &ranks, trump_suit)) { 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<Suit>, 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]; let ranks = [Rank::Ober, Rank::Unter];
if cards.iter().any(|&c| is_trump(c, &ranks, Some(trump_suit))) { if cards.iter().any(|&c| is_trump(c, &ranks, Some(trump_suit))) {
// Highest trump wins // 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<Suit>) -> bool { fn is_trump(card: &Card, trump_ranks: &[Rank], trump_suit: Option<Suit>) -> 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: // 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<Suit>) -> u16 { fn trump_strength_wenz(card: &Card, rank: Rank, trump_suit: Option<Suit>) -> u16 {
if card.rank == rank { if card.rank == rank {
200 + ober_unter_suit_strength(card.suit) 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 100 + non_trump_strength(card.rank) as u16
} else { } else {
0 0

View File

@@ -1,7 +1,6 @@
use bevy::{ use bevy::{
asset::{AssetMetaCheck, AssetPlugin, RenderAssetUsages}, asset::{AssetMetaCheck, AssetPlugin, RenderAssetUsages},
prelude::*, prelude::*,
sprite::Anchor,
render::render_resource::{Extent3d, TextureDimension, TextureFormat}, render::render_resource::{Extent3d, TextureDimension, TextureFormat},
}; };
use schafkopf_logic::{ use schafkopf_logic::{
@@ -10,7 +9,6 @@ use schafkopf_logic::{
player::{HumanPlayer, InternalPlayer}, player::{HumanPlayer, InternalPlayer},
}; };
use std::fmt::Debug;
const CARD_TEXTURE_WIDTH: usize = 96; const CARD_TEXTURE_WIDTH: usize = 96;
@@ -94,7 +92,7 @@ fn setup_game(
let mut deck = Deck::new(); let mut deck = Deck::new();
deck.shuffle(); 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"); deck.deal_4x8().expect("expected a full deck to deal four hands");
sort_cards(&mut hand1); sort_cards(&mut hand1);
@@ -131,7 +129,7 @@ fn spawn_player_hand(
let base_handle = create_card_texture(&mut images, card); let base_handle = create_card_texture(&mut images, card);
let parent = commands 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(); .id();
commands.entity(parent).with_children(|c| { commands.entity(parent).with_children(|c| {
@@ -146,7 +144,7 @@ fn spawn_player_hand(
)) ))
.observe(on_hover()) .observe(on_hover())
.observe(on_unhover()) .observe(on_unhover())
.observe(on_click(card.clone())); .observe(on_click(*card));
c.spawn(( c.spawn((
Sprite::from_atlas_image( Sprite::from_atlas_image(

View File

@@ -111,13 +111,11 @@ impl InternalPlayer for HumanPlayer {
let _ = io::stdout().flush(); let _ = io::stdout().flush();
let mut input = String::new(); let mut input = String::new();
if io::stdin().read_line(&mut input).is_ok() { if io::stdin().read_line(&mut input).is_ok()
if let Ok(idx) = input.trim().parse::<usize>() { && let Ok(idx) = input.trim().parse::<usize>()
if idx < self.hand.len() { && idx < self.hand.len() {
return Ok(self.hand.remove(idx)); return Ok(self.hand.remove(idx));
} }
}
}
// fallback: pop last // fallback: pop last
self.hand.pop().ok_or(PlayerError::NoCards) self.hand.pop().ok_or(PlayerError::NoCards)