-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathDealer.kt
39 lines (30 loc) · 939 Bytes
/
Dealer.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package blackJack.model
class Dealer(val name: String) {
private var cardDeck = CardDeck.of()
val MAXIMUM_SCORE = 21
fun countCard(): Int {
return cardDeck.cards.size
}
fun drawCard(): Card {
val currentCard = cardDeck.cards
.shuffled()
.first()
cardDeck = cardDeck.cards
.filter { it != currentCard }
.let(::CardDeck)
return currentCard
}
fun startGame(players: List<Player>): List<Player> {
return initializePlayerHands(players)
}
private fun initializePlayerHands(players: List<Player>): List<Player> {
players.forEach { player ->
player requestCardToDealer drawCard()
player requestCardToDealer drawCard()
}
return players
}
}
infix fun Dealer.checkDrawCardIsAllowedFor(player: Player): Boolean {
return player.calculateScore() < MAXIMUM_SCORE
}