50 lines
815 B
Swift
50 lines
815 B
Swift
|
//
|
||
|
// File.swift
|
||
|
//
|
||
|
//
|
||
|
// Created by iMac on 03.12.21.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
enum CardOrderType {
|
||
|
|
||
|
/// The sorting for most games, where heart is trump
|
||
|
case normal
|
||
|
|
||
|
case wenz
|
||
|
|
||
|
case geier
|
||
|
|
||
|
case soloEichel
|
||
|
|
||
|
case soloBlatt
|
||
|
|
||
|
case soloSchelln
|
||
|
}
|
||
|
|
||
|
protocol CardOrder {
|
||
|
|
||
|
static var trumpOrder: [Card] { get }
|
||
|
|
||
|
static var sortIndex: [Card : Int] { get }
|
||
|
}
|
||
|
|
||
|
extension CardOrder {
|
||
|
|
||
|
static func consecutiveTrumps(_ cards: [Card]) -> Int {
|
||
|
var count = 0
|
||
|
while cards.contains(trumpOrder[count]) {
|
||
|
count += 1
|
||
|
}
|
||
|
guard count >= 3 else {
|
||
|
return 0
|
||
|
}
|
||
|
return count
|
||
|
}
|
||
|
|
||
|
static func sort(_ cards: [Card]) -> [Card] {
|
||
|
cards.sorted { sortIndex[$0]! < sortIndex[$1]! }
|
||
|
}
|
||
|
}
|