59 lines
1.5 KiB
Swift
59 lines
1.5 KiB
Swift
|
//
|
|||
|
// File.swift
|
|||
|
//
|
|||
|
//
|
|||
|
// Created by iMac on 03.12.21.
|
|||
|
//
|
|||
|
|
|||
|
import Foundation
|
|||
|
|
|||
|
struct NormalCardOrder: CardOrder {
|
|||
|
|
|||
|
private static let cardOrder = [
|
|||
|
Card(.eichel, .ober),
|
|||
|
Card(.blatt, .ober),
|
|||
|
Card(.herz, .ober),
|
|||
|
Card(.schelln, .ober),
|
|||
|
Card(.eichel, .unter),
|
|||
|
Card(.blatt, .unter),
|
|||
|
Card(.herz, .unter),
|
|||
|
Card(.schelln, .unter),
|
|||
|
Card(.herz, .ass),
|
|||
|
Card(.herz, .zehn),
|
|||
|
Card(.herz, .könig),
|
|||
|
Card(.herz, .neun),
|
|||
|
Card(.herz, .acht),
|
|||
|
Card(.herz, .sieben),
|
|||
|
Card(.eichel, .ass),
|
|||
|
Card(.eichel, .zehn),
|
|||
|
Card(.eichel, .könig),
|
|||
|
Card(.eichel, .neun),
|
|||
|
Card(.eichel, .acht),
|
|||
|
Card(.eichel, .sieben),
|
|||
|
Card(.blatt, .ass),
|
|||
|
Card(.blatt, .zehn),
|
|||
|
Card(.blatt, .könig),
|
|||
|
Card(.blatt, .neun),
|
|||
|
Card(.blatt, .acht),
|
|||
|
Card(.blatt, .sieben),
|
|||
|
Card(.schelln, .ass),
|
|||
|
Card(.schelln, .zehn),
|
|||
|
Card(.schelln, .könig),
|
|||
|
Card(.schelln, .neun),
|
|||
|
Card(.schelln, .acht),
|
|||
|
Card(.schelln, .sieben),
|
|||
|
]
|
|||
|
|
|||
|
private static let sortIndex: [Card : Int] = {
|
|||
|
cardOrder.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }
|
|||
|
}()
|
|||
|
|
|||
|
static let trumpOrder: [Card] = Array(cardOrder[0..<8])
|
|||
|
|
|||
|
private static let trumps: Set<Card> = Set(trumpOrder)
|
|||
|
|
|||
|
static func trumpCount(_ cards: [Card]) -> Int {
|
|||
|
cards.filter { trumps.contains(card) }.count
|
|||
|
}
|
|||
|
}
|