Schafkopf-Server/Sources/App/Model/CardOrders/NormalCardOrder.swift
Christoph Hagen 3db9652cad Sync push
2021-12-03 18:03:29 +01:00

59 lines
1.5 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
}
}