Schafkopf-Server/Sources/App/Model/Dealer.swift
2021-12-06 11:43:30 +01:00

24 lines
619 B
Swift

import Foundation
struct Dealer {
/**
Creates a random assignment of 4 cards per 4 players for the initial round of doubling.
*/
static func dealFirstCards() -> [Hand] {
// Select 16 random cards for the first hands
Array(Card.allCards.shuffled()[0..<16])
.split(intoChunksOf: 4)
.map { $0.sortedCards(order: NormalCardOrder.self) }
}
static func dealRemainingCards(of initial: [Hand]) -> [Hand] {
Card.allCards
.subtracting(initial.reduce([], +))
.shuffled()
.split(intoChunksOf: 4)
}
}