From 1f714677b471af929953df25cee05a4f09f1f4c1 Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Mon, 27 Nov 2023 13:58:23 +0900 Subject: [PATCH 1/9] =?UTF-8?q?refactor:=20Blackjack.kt=20=EC=9D=98=20prin?= =?UTF-8?q?t=20=EA=B5=AC=EB=AC=B8=20result=20view=20=EB=A1=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Blackjack.kt | 2 +- src/main/kotlin/blackjack/view/ResultView.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/blackjack/Blackjack.kt b/src/main/kotlin/blackjack/Blackjack.kt index e58e36b88a..6dc86a7c73 100644 --- a/src/main/kotlin/blackjack/Blackjack.kt +++ b/src/main/kotlin/blackjack/Blackjack.kt @@ -37,6 +37,7 @@ class Blackjack( while (player.state == PlayerState.Hit) { val command = inputView.getPlayerCommand(player.name) player.play(command == "y") + resultView.printPlayer(player) } } @@ -49,7 +50,6 @@ class Blackjack( hit() val card = deck.draw() addCard(card) - println("$name: ${hand.handCards}") } else { stay() } diff --git a/src/main/kotlin/blackjack/view/ResultView.kt b/src/main/kotlin/blackjack/view/ResultView.kt index 3439cb4854..289d790e59 100644 --- a/src/main/kotlin/blackjack/view/ResultView.kt +++ b/src/main/kotlin/blackjack/view/ResultView.kt @@ -16,7 +16,7 @@ class ResultView { } } - private fun printPlayer(player: Player) { + fun printPlayer(player: Player) { println("${player.name}: ${player.hand}") } } From bb775f94b16f0626651409a7e860f3aec0409d1d Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Mon, 27 Nov 2023 14:36:08 +0900 Subject: [PATCH 2/9] =?UTF-8?q?refactor:=20InputViewCommand=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Blackjack.kt | 3 ++- src/main/kotlin/blackjack/view/InputView.kt | 14 +++++++++++++- src/main/kotlin/blackjack/view/UserInputView.kt | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/blackjack/Blackjack.kt b/src/main/kotlin/blackjack/Blackjack.kt index 6dc86a7c73..2c8000552f 100644 --- a/src/main/kotlin/blackjack/Blackjack.kt +++ b/src/main/kotlin/blackjack/Blackjack.kt @@ -6,6 +6,7 @@ import blackjack.domain.player.Hand import blackjack.domain.player.Player import blackjack.domain.player.PlayerState import blackjack.view.InputView +import blackjack.view.InputViewCommand import blackjack.view.ResultView import blackjack.view.UserInputView @@ -36,7 +37,7 @@ class Blackjack( private fun processPlayerTurn(player: Player) { while (player.state == PlayerState.Hit) { val command = inputView.getPlayerCommand(player.name) - player.play(command == "y") + player.play(command == InputViewCommand.Yes) resultView.printPlayer(player) } } diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 1f32a8e840..e97cfe52d2 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -3,5 +3,17 @@ package blackjack.view interface InputView { fun getPlayerNames(): List - fun getPlayerCommand(playerName: String): String + fun getPlayerCommand(playerName: String): InputViewCommand +} + +sealed interface InputViewCommand { + object Yes : InputViewCommand + object No: InputViewCommand + + companion object { + private val validYesCommands: Set = setOf("y") + fun get(commandString: String) : InputViewCommand { + return if (commandString in validYesCommands) Yes else No + } + } } diff --git a/src/main/kotlin/blackjack/view/UserInputView.kt b/src/main/kotlin/blackjack/view/UserInputView.kt index 75ac6988e2..980e0966fe 100644 --- a/src/main/kotlin/blackjack/view/UserInputView.kt +++ b/src/main/kotlin/blackjack/view/UserInputView.kt @@ -6,8 +6,9 @@ class UserInputView : InputView { return readln().split(",").map { it.trim() } } - override fun getPlayerCommand(playerName: String): String { + override fun getPlayerCommand(playerName: String): InputViewCommand { println("${playerName}은 한 장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") - return readln().trim() + val cmd = readln().trim() + return InputViewCommand.get(cmd) } } From 39ecc0a7451c266792b050e08d2eb2cd4aa94dc5 Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 14:53:38 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feature:=20Dealer=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Blackjack.kt | 20 ++++++------ .../kotlin/blackjack/domain/player/Dealer.kt | 32 +++++++++++++++++++ src/main/kotlin/blackjack/view/InputView.kt | 4 +-- src/main/kotlin/blackjack/view/ResultView.kt | 8 +++++ 4 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/blackjack/domain/player/Dealer.kt diff --git a/src/main/kotlin/blackjack/Blackjack.kt b/src/main/kotlin/blackjack/Blackjack.kt index 2c8000552f..8fde27391a 100644 --- a/src/main/kotlin/blackjack/Blackjack.kt +++ b/src/main/kotlin/blackjack/Blackjack.kt @@ -1,8 +1,7 @@ package blackjack import blackjack.domain.cards.Deck -import blackjack.domain.cards.HandCards -import blackjack.domain.player.Hand +import blackjack.domain.player.Dealer import blackjack.domain.player.Player import blackjack.domain.player.PlayerState import blackjack.view.InputView @@ -14,15 +13,13 @@ class Blackjack( private val inputView: InputView, private val resultView: ResultView, ) { - private val deck = Deck.fullDeck() - - init { - deck.shuffle() - } + private val dealer = Dealer(Deck.fullDeck()) fun simulate() { val playerNames = inputView.getPlayerNames() + dealer.initHand() + val players = createPlayers(playerNames) resultView.printInitialState(players) @@ -31,6 +28,11 @@ class Blackjack( processPlayerTurn(player) } + dealer.processTurn { + resultView.printDealerTurn(it) + } + + resultView.printPlayer(dealer.asPlayer) resultView.printResult(players) } @@ -43,13 +45,13 @@ class Blackjack( } private fun createPlayers(playerNames: List): List { - return playerNames.map { Player(it, Hand(HandCards(mutableListOf(deck.draw(), deck.draw())))) } + return playerNames.map { Player(it, dealer.createInitialHand()) } } private fun Player.play(isHit: Boolean) { if (isHit) { hit() - val card = deck.draw() + val card = dealer.provideCard() addCard(card) } else { stay() diff --git a/src/main/kotlin/blackjack/domain/player/Dealer.kt b/src/main/kotlin/blackjack/domain/player/Dealer.kt new file mode 100644 index 0000000000..9aa1360d99 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/player/Dealer.kt @@ -0,0 +1,32 @@ +package blackjack.domain.player + +import blackjack.domain.cards.Deck +import blackjack.domain.cards.HandCards + +class Dealer(private val deck: Deck) { + private lateinit var _player: Player + val asPlayer get() = _player + + init { + deck.shuffle() + } + + fun provideCard() = deck.draw() + + fun createInitialHand(): Hand = Hand(HandCards(mutableListOf(deck.draw(), deck.draw()))) + + fun initHand() { + _player = Player( + "딜러", + hand = createInitialHand() + ) + } + + fun processTurn(onResult: (Boolean) -> Unit) { + val addCard = _player.hand.valueSum() <= 16 + + if (addCard) _player.addCard(deck.draw()) + + onResult(addCard) + } +} diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index e97cfe52d2..d467aaed12 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -8,11 +8,11 @@ interface InputView { sealed interface InputViewCommand { object Yes : InputViewCommand - object No: InputViewCommand + object No : InputViewCommand companion object { private val validYesCommands: Set = setOf("y") - fun get(commandString: String) : InputViewCommand { + fun get(commandString: String): InputViewCommand { return if (commandString in validYesCommands) Yes else No } } diff --git a/src/main/kotlin/blackjack/view/ResultView.kt b/src/main/kotlin/blackjack/view/ResultView.kt index 289d790e59..8e49b6d16f 100644 --- a/src/main/kotlin/blackjack/view/ResultView.kt +++ b/src/main/kotlin/blackjack/view/ResultView.kt @@ -19,4 +19,12 @@ class ResultView { fun printPlayer(player: Player) { println("${player.name}: ${player.hand}") } + + fun printDealerTurn(addedCard: Boolean) { + if (addedCard) { + println("딜러는 16이하라 한장의 카드를 더 받았습니다.") + } else { + println("딜러는 17이상이라 카드를 받지 않았습니다.") + } + } } From 470085f32af87de385996d6e4f292a6e945d462a Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 15:38:15 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feature:=20Dealer=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/main/kotlin/blackjack/Blackjack.kt | 10 ++++++++++ .../kotlin/blackjack/domain/BlackjackResult.kt | 15 +++++++++++++++ src/main/kotlin/blackjack/domain/player/Dealer.kt | 8 ++++++++ src/main/kotlin/blackjack/domain/player/Hand.kt | 4 ++++ .../kotlin/blackjack/domain/player/PlayerState.kt | 5 ++++- src/main/kotlin/blackjack/view/ResultView.kt | 9 +++++++++ 7 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/blackjack/domain/BlackjackResult.kt diff --git a/README.md b/README.md index e046039d03..b2a7a187c2 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ - [x] Player 가 bust 상태가 되면 hit 할 수 없다 - [x] Player 가 blackjack 상태가 되면 hit 할 수 없다 - [x] Player 는 stay 후엔 다시 hit 할 수 없다 +- [x] Dealer 와 Player 의 승패가 정확히 결정된다 diff --git a/src/main/kotlin/blackjack/Blackjack.kt b/src/main/kotlin/blackjack/Blackjack.kt index 8fde27391a..a8b9984d32 100644 --- a/src/main/kotlin/blackjack/Blackjack.kt +++ b/src/main/kotlin/blackjack/Blackjack.kt @@ -1,5 +1,7 @@ package blackjack +import blackjack.domain.BlackjackResult +import blackjack.domain.PlayerResult import blackjack.domain.cards.Deck import blackjack.domain.player.Dealer import blackjack.domain.player.Player @@ -34,6 +36,14 @@ class Blackjack( resultView.printPlayer(dealer.asPlayer) resultView.printResult(players) + + val gameResult = BlackjackResult( + players.map { player -> + PlayerResult(player, dealer.wins(player)) + } + ) + + resultView.printBlackjackResult(gameResult) } private fun processPlayerTurn(player: Player) { diff --git a/src/main/kotlin/blackjack/domain/BlackjackResult.kt b/src/main/kotlin/blackjack/domain/BlackjackResult.kt new file mode 100644 index 0000000000..2491da3c94 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/BlackjackResult.kt @@ -0,0 +1,15 @@ +package blackjack.domain + +import blackjack.domain.player.Player + +data class BlackjackResult( + val playerResult: List +) { + val dealerWin get() = playerResult.count { it.isWin.not() } + val dealerLose get() = playerResult.count { it.isWin } +} + +data class PlayerResult( + val player: Player, + val isWin: Boolean, +) diff --git a/src/main/kotlin/blackjack/domain/player/Dealer.kt b/src/main/kotlin/blackjack/domain/player/Dealer.kt index 9aa1360d99..7cefed0071 100644 --- a/src/main/kotlin/blackjack/domain/player/Dealer.kt +++ b/src/main/kotlin/blackjack/domain/player/Dealer.kt @@ -29,4 +29,12 @@ class Dealer(private val deck: Deck) { onResult(addCard) } + + fun wins(player: Player): Boolean { + return if (asPlayer.state.isBust()) { + false + } else { + asPlayer.hand.blackjackDiff() < player.hand.blackjackDiff() + } + } } diff --git a/src/main/kotlin/blackjack/domain/player/Hand.kt b/src/main/kotlin/blackjack/domain/player/Hand.kt index b9ef10cf05..42d5e016ec 100644 --- a/src/main/kotlin/blackjack/domain/player/Hand.kt +++ b/src/main/kotlin/blackjack/domain/player/Hand.kt @@ -2,13 +2,17 @@ package blackjack.domain.player import blackjack.domain.card.Card import blackjack.domain.cards.HandCards +import kotlin.math.abs data class Hand(val handCards: HandCards) { fun addCard(card: Card) { handCards.add(card) } + fun valueSum(): Int = handCards.cardList.sumOf { it.character.value } + fun blackjackDiff() = abs(valueSum() - BLACK_JACK) + fun isBlackjack() = valueSum() == BLACK_JACK fun isBust() = valueSum() > BLACK_JACK diff --git a/src/main/kotlin/blackjack/domain/player/PlayerState.kt b/src/main/kotlin/blackjack/domain/player/PlayerState.kt index 9a4cb7cad2..0a1d7b5c41 100644 --- a/src/main/kotlin/blackjack/domain/player/PlayerState.kt +++ b/src/main/kotlin/blackjack/domain/player/PlayerState.kt @@ -1,5 +1,8 @@ package blackjack.domain.player enum class PlayerState { - Hit, Stay, Bust, Blackjack + Hit, Stay, Bust, Blackjack; + + fun isHit() = this == Hit + fun isBust() = this == Bust } diff --git a/src/main/kotlin/blackjack/view/ResultView.kt b/src/main/kotlin/blackjack/view/ResultView.kt index 8e49b6d16f..6360e90a54 100644 --- a/src/main/kotlin/blackjack/view/ResultView.kt +++ b/src/main/kotlin/blackjack/view/ResultView.kt @@ -1,5 +1,6 @@ package blackjack.view +import blackjack.domain.BlackjackResult import blackjack.domain.player.Player class ResultView { @@ -27,4 +28,12 @@ class ResultView { println("딜러는 17이상이라 카드를 받지 않았습니다.") } } + + fun printBlackjackResult(blackjackResult: BlackjackResult) { + println("## 최종 승패") + println("딜러: ${blackjackResult.dealerWin}승 ${blackjackResult.dealerLose}패") + blackjackResult.playerResult.forEach { playerResult -> + println("${playerResult.player.name}: ${if (playerResult.isWin) "승" else "패"}") + } + } } From 3d4ee06c4fbfedf7e800509a209094d96749700e Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 15:38:23 +0900 Subject: [PATCH 5/9] =?UTF-8?q?test:=20Dealer=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/domain/player/DealerTest.kt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/kotlin/blackjack/domain/player/DealerTest.kt diff --git a/src/test/kotlin/blackjack/domain/player/DealerTest.kt b/src/test/kotlin/blackjack/domain/player/DealerTest.kt new file mode 100644 index 0000000000..85dd313655 --- /dev/null +++ b/src/test/kotlin/blackjack/domain/player/DealerTest.kt @@ -0,0 +1,66 @@ +package blackjack.domain.player + +import blackjack.domain.card.Card +import blackjack.domain.card.Character +import blackjack.domain.card.Suit +import blackjack.domain.cards.Deck +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class DealerTest : StringSpec({ + "Dealer 는 Bust 패배한다" { + val dealer = Dealer(Deck.fullDeck()) + dealer.initHand() + + while (dealer.asPlayer.state.isHit()) { + dealer.asPlayer.addCard(dealer.provideCard()) + } + + val player = Player("pp", dealer.createInitialHand()) + + dealer.asPlayer.state.isBust() shouldBe true + dealer.wins(player) shouldBe false + } + + "Dealer 는 동점이면 패배한다" { + val dealer = Dealer(Deck.fullDeck()) + dealer.initHand() + + dealer.asPlayer.toTargetValue(20) + + val player = Player("pp", dealer.createInitialHand()) + + player.toTargetValue(20) + + dealer.asPlayer.hand.valueSum() shouldBe 20 + player.hand.valueSum() shouldBe 20 + + dealer.wins(player) shouldBe false + } + + "Dealer 승리 테스트" { + val dealer = Dealer(Deck.fullDeck()) + dealer.initHand() + + dealer.asPlayer.toTargetValue(21) + + val player = Player("pp", dealer.createInitialHand()) + + player.toTargetValue(20) + + dealer.asPlayer.hand.valueSum() shouldBe 21 + player.hand.valueSum() shouldBe 20 + + dealer.wins(player) shouldBe true + } +}) + +private fun Player.toTargetValue(targetValue: Int) { + var remain = targetValue - hand.valueSum() + + while (remain != 0) { + val cardValue = if (remain > 10) remain - 10 else remain + addCard(Card(Suit.Diamond, Character.values().first { it.value == cardValue })) + remain -= cardValue + } +} From 991a8d6dbf319e91663927a46f625537e452c6b8 Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 15:41:40 +0900 Subject: [PATCH 6/9] =?UTF-8?q?test:=20Dealer=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/domain/player/Dealer.kt | 2 ++ .../blackjack/domain/player/DealerTest.kt | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/blackjack/domain/player/Dealer.kt b/src/main/kotlin/blackjack/domain/player/Dealer.kt index 7cefed0071..4158c3355f 100644 --- a/src/main/kotlin/blackjack/domain/player/Dealer.kt +++ b/src/main/kotlin/blackjack/domain/player/Dealer.kt @@ -33,6 +33,8 @@ class Dealer(private val deck: Deck) { fun wins(player: Player): Boolean { return if (asPlayer.state.isBust()) { false + } else if (asPlayer.state.isBust().not() && player.state.isBust()) { + true } else { asPlayer.hand.blackjackDiff() < player.hand.blackjackDiff() } diff --git a/src/test/kotlin/blackjack/domain/player/DealerTest.kt b/src/test/kotlin/blackjack/domain/player/DealerTest.kt index 85dd313655..56f4fc66b8 100644 --- a/src/test/kotlin/blackjack/domain/player/DealerTest.kt +++ b/src/test/kotlin/blackjack/domain/player/DealerTest.kt @@ -26,11 +26,11 @@ class DealerTest : StringSpec({ val dealer = Dealer(Deck.fullDeck()) dealer.initHand() - dealer.asPlayer.toTargetValue(20) + dealer.asPlayer.toTargetValueOver19(20) val player = Player("pp", dealer.createInitialHand()) - player.toTargetValue(20) + player.toTargetValueOver19(20) dealer.asPlayer.hand.valueSum() shouldBe 20 player.hand.valueSum() shouldBe 20 @@ -42,20 +42,31 @@ class DealerTest : StringSpec({ val dealer = Dealer(Deck.fullDeck()) dealer.initHand() - dealer.asPlayer.toTargetValue(21) + dealer.asPlayer.toTargetValueOver19(21) val player = Player("pp", dealer.createInitialHand()) - player.toTargetValue(20) + player.toTargetValueOver19(20) dealer.asPlayer.hand.valueSum() shouldBe 21 player.hand.valueSum() shouldBe 20 dealer.wins(player) shouldBe true } + + "Dealer process turn 테스트" { + val dealer = Dealer(Deck.fullDeck()) + dealer.initHand() + + dealer.asPlayer.toTargetValueOver19(20) + + dealer.processTurn { + it shouldBe false + } + } }) -private fun Player.toTargetValue(targetValue: Int) { +private fun Player.toTargetValueOver19(targetValue: Int) { var remain = targetValue - hand.valueSum() while (remain != 0) { From d928fb879eba0b8bc1bd2b3edfb0ed4b3c05795d Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 15:48:16 +0900 Subject: [PATCH 7/9] =?UTF-8?q?test:=20blackjackDiff=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/domain/player/HandTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/kotlin/blackjack/domain/player/HandTest.kt b/src/test/kotlin/blackjack/domain/player/HandTest.kt index ff048de7bf..7c88cb1c30 100644 --- a/src/test/kotlin/blackjack/domain/player/HandTest.kt +++ b/src/test/kotlin/blackjack/domain/player/HandTest.kt @@ -46,4 +46,11 @@ class HandTest : StringSpec({ hand.isBlackjack() shouldBe false hand.isBust() shouldBe true } + + "blackjackDiff 테스트" { + val hand = Hand(HandCards(mutableListOf(Card(Suit.Spade, Character.Jack), Card(Suit.Clover, Character.Jack)))) + + hand.valueSum() shouldBe 20 + hand.blackjackDiff() shouldBe 1 + } }) From 606d4f5823711eeeeaa79a16b87e57fd9928180d Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Wed, 29 Nov 2023 15:56:05 +0900 Subject: [PATCH 8/9] =?UTF-8?q?test:=20blackjackResult=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/domain/BlackjackResultTest.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/kotlin/blackjack/domain/BlackjackResultTest.kt diff --git a/src/test/kotlin/blackjack/domain/BlackjackResultTest.kt b/src/test/kotlin/blackjack/domain/BlackjackResultTest.kt new file mode 100644 index 0000000000..3861d4106f --- /dev/null +++ b/src/test/kotlin/blackjack/domain/BlackjackResultTest.kt @@ -0,0 +1,44 @@ +package blackjack.domain + +import blackjack.domain.card.Card +import blackjack.domain.card.Character +import blackjack.domain.card.Suit +import blackjack.domain.cards.HandCards +import blackjack.domain.player.Hand +import blackjack.domain.player.Player +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +private fun randomCard() = Card(Suit.values().random(), Character.values().random()) + +class BlackjackResultTest : StringSpec({ + "blackjackResult 테스트" { + val player1 = Player("a", Hand(HandCards(mutableListOf(randomCard(), randomCard())))) + val player2 = Player("b", Hand(HandCards(mutableListOf(randomCard(), randomCard())))) + val player3 = Player("c", Hand(HandCards(mutableListOf(randomCard(), randomCard())))) + val player4 = Player("d", Hand(HandCards(mutableListOf(randomCard(), randomCard())))) + val player5 = Player("e", Hand(HandCards(mutableListOf(randomCard(), randomCard())))) + + val playerResults = listOf( + PlayerResult( + player1, true + ), + PlayerResult( + player2, false + ), + PlayerResult( + player3, true + ), + PlayerResult( + player4, false + ), + PlayerResult( + player5, false + ), + ) + + val blackjackResult = BlackjackResult(playerResults) + blackjackResult.dealerWin shouldBe 3 + blackjackResult.dealerLose shouldBe 2 + } +}) From 44d5d141c388014d067b041a7e7f84d7bfb64edb Mon Sep 17 00:00:00 2001 From: "silvio.oivlis" Date: Fri, 8 Dec 2023 17:51:30 +0900 Subject: [PATCH 9/9] =?UTF-8?q?doc:=20=EB=AC=B8=EC=84=9C=20=ED=83=80?= =?UTF-8?q?=EC=9D=B4=ED=8B=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2a7a187c2..25bccbd783 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # kotlin-blackjack -## step2 +## step3 - [x] 초기 DeckCards 은 52장의 카드로 이루어진다 - [x] 초기 DeckCards 의 각 Suit 카드는 13장씩 있어야 한다 - [x] 초기 DeckCards 는 중복 없는 카드로 이루어져야 한다