File tree 1 file changed +11
-13
lines changed
src/main/kotlin/blackjack/controller
1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -43,29 +43,27 @@ class BlackjackGame(
43
43
return participants.map { playerTurn(it, gameTable) }
44
44
}
45
45
46
- private fun playerTurn (
46
+ private tailrec fun playerTurn (
47
47
player : Participant ,
48
48
gameTable : GameTable ,
49
49
): Participant {
50
- return if (player.canHit() && inputView.inputHit(player)) {
51
- val hitPlayer = gameTable.hit(player)
52
- resultView.printParticipantCard(participant = player, printScore = false )
53
- playerTurn(hitPlayer, gameTable)
54
- } else {
55
- player
50
+ if (! player.canHit() || ! inputView.inputHit(player)) {
51
+ return player
56
52
}
53
+ val hitPlayer = gameTable.hit(player)
54
+ resultView.printParticipantCard(participant = player, printScore = false )
55
+ return playerTurn(hitPlayer, gameTable)
57
56
}
58
57
59
- private fun dealerTurn (
58
+ private tailrec fun dealerTurn (
60
59
dealer : Participant ,
61
60
gameTable : GameTable ,
62
61
): Participant {
63
- return if (dealer.canHit()) {
64
- resultView.printDealerHit()
65
- dealerTurn(gameTable.hit(dealer), gameTable)
66
- } else {
67
- dealer
62
+ if (! dealer.canHit()) {
63
+ return dealer
68
64
}
65
+ resultView.printDealerHit()
66
+ return dealerTurn(gameTable.hit(dealer), gameTable)
69
67
}
70
68
71
69
private fun printGameResult (participants : List <Participant >) {
You can’t perform that action at this time.
0 commit comments