mirror of
https://github.com/Vale54321/schafkop-neu.git
synced 2025-12-11 09:59:33 +01:00
clippy format
This commit is contained in:
@@ -16,6 +16,12 @@ pub struct Deck {
|
||||
cards: Vec<Card>,
|
||||
}
|
||||
|
||||
impl Default for Deck {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deck {
|
||||
pub fn new() -> Self {
|
||||
let cards = Suit::iter()
|
||||
|
||||
@@ -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];
|
||||
|
||||
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];
|
||||
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<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:
|
||||
@@ -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 {
|
||||
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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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::<usize>() {
|
||||
if idx < self.hand.len() {
|
||||
if io::stdin().read_line(&mut input).is_ok()
|
||||
&& let Ok(idx) = input.trim().parse::<usize>()
|
||||
&& idx < self.hand.len() {
|
||||
return Ok(self.hand.remove(idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: pop last
|
||||
self.hand.pop().ok_or(PlayerError::NoCards)
|
||||
|
||||
Reference in New Issue
Block a user