From b2e1f6548dace99e93994dd599543da7cbd65280 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Mon, 13 Nov 2023 22:07:25 +0900 Subject: [PATCH 01/15] =?UTF-8?q?refactor:=201=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=EB=A5=BC=20=EB=B0=98=EC=98=81=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Skill 을 sealed interface로 만들고, 스킬 종류가 추가되면 이를 상속하도록 한다. - DSL을 위한 실습 코드이므로 별도의 코드 분리는 하지 않았음. --- src/test/kotlin/DslTest.kt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/DslTest.kt b/src/test/kotlin/DslTest.kt index 97c6924a63..59f76fea35 100644 --- a/src/test/kotlin/DslTest.kt +++ b/src/test/kotlin/DslTest.kt @@ -24,10 +24,10 @@ class DslTest { name shouldBe "greentea.latte" company shouldBe "kakao" softSkills shouldContainInOrder listOf( - "A passion for problem solving", - "Good communication skills" + Skill.SoftSkill("A passion for problem solving"), + Skill.SoftSkill("Good communication skills"), ) - hardSkills shouldContain "Kotlin" + hardSkills shouldContain Skill.HardSkill("Kotlin") languageLevels shouldContainInOrder listOf( "Korean" to 5, "English" to 3, @@ -45,8 +45,8 @@ class PersonBuilder { private lateinit var name: String private lateinit var company: String - private val softSkills = mutableListOf() - private val hardSkills = mutableListOf() + private val softSkills = mutableListOf() + private val hardSkills = mutableListOf() private val languageLevels = mutableListOf>() @@ -63,11 +63,11 @@ class PersonBuilder { } fun soft(value: String) { - softSkills.add(value) + softSkills.add(Skill.SoftSkill(value)) } fun hard(value: String) { - hardSkills.add(value) + hardSkills.add(Skill.HardSkill(value)) } fun languages(block: PersonBuilder.() -> Unit): PersonBuilder { @@ -92,7 +92,12 @@ class PersonBuilder { data class Person( val name: String, val company: String?, - val softSkills: List, - val hardSkills: List, + val softSkills: List, + val hardSkills: List, val languageLevels: List>, -) \ No newline at end of file +) + +sealed interface Skill { + data class SoftSkill(val name: String) : Skill + data class HardSkill(val name: String) : Skill +} \ No newline at end of file From 6bbe68857a6c637f99f8d83b6fe53b3e029b630a Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Mon, 13 Nov 2023 22:43:58 +0900 Subject: [PATCH 02/15] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20=EC=9E=85?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=A5=BC=20=EA=B5=AC=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 참여자 입력 메서드 및 초기 카드 배분을 알리는 출력 메서드 구현 - 참여자와 카드를 다루기 위한 Participant, Card 클래스 생성 --- .../blackjack/controller/BlackJackGame.kt | 12 ++++++++ src/main/kotlin/blackjack/model/Card.kt | 5 ++++ .../kotlin/blackjack/model/Participant.kt | 6 ++++ src/main/kotlin/blackjack/ui/InputView.kt | 29 +++++++++++++++++++ src/main/kotlin/blackjack/ui/ResultView.kt | 14 +++++++++ 5 files changed, 66 insertions(+) create mode 100644 src/main/kotlin/blackjack/controller/BlackJackGame.kt create mode 100644 src/main/kotlin/blackjack/model/Card.kt create mode 100644 src/main/kotlin/blackjack/model/Participant.kt create mode 100644 src/main/kotlin/blackjack/ui/InputView.kt create mode 100644 src/main/kotlin/blackjack/ui/ResultView.kt diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt new file mode 100644 index 0000000000..7782ee400e --- /dev/null +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -0,0 +1,12 @@ +package blackjack.controller + +import blackjack.ui.InputView +import blackjack.ui.ResultView + +class BlackJackGame { +} + +fun main() { + val participants = InputView.registerParticipants() + ResultView.showInitialStatusOfParticipants(participants) +} \ No newline at end of file diff --git a/src/main/kotlin/blackjack/model/Card.kt b/src/main/kotlin/blackjack/model/Card.kt new file mode 100644 index 0000000000..75bddb841e --- /dev/null +++ b/src/main/kotlin/blackjack/model/Card.kt @@ -0,0 +1,5 @@ +package blackjack.model + +data class Card( + val name: String, +) diff --git a/src/main/kotlin/blackjack/model/Participant.kt b/src/main/kotlin/blackjack/model/Participant.kt new file mode 100644 index 0000000000..d1477ea824 --- /dev/null +++ b/src/main/kotlin/blackjack/model/Participant.kt @@ -0,0 +1,6 @@ +package blackjack.model + +data class Participant( + val name: String, + val cards: List? = null, +) diff --git a/src/main/kotlin/blackjack/ui/InputView.kt b/src/main/kotlin/blackjack/ui/InputView.kt new file mode 100644 index 0000000000..af54a0468b --- /dev/null +++ b/src/main/kotlin/blackjack/ui/InputView.kt @@ -0,0 +1,29 @@ +package blackjack.ui + +import blackjack.model.Participant + +object InputView { + + fun registerParticipants(): List { + println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)") + return readlnOrNull() + ?.split(',') + ?.map { name -> + Participant(name) + } + ?.toList() + ?: throw IllegalArgumentException("참여자의 이름은 null을 허용하지 않습니다.") + } + + fun askCardPicking(name: String): Boolean { + println("${name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") + return readlnOrNull()?.let { + when (it) { + "y" -> true + "n" -> false + else -> throw IllegalArgumentException("카드 받기 여부는 y 또는 n만 입력 가능합니다.") + } + } ?: throw IllegalArgumentException("카드 받기 여부는 null을 허용하지 않습니다.") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt new file mode 100644 index 0000000000..e3ce6d7d8b --- /dev/null +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -0,0 +1,14 @@ +package blackjack.ui + +import blackjack.model.Participant + +object ResultView { + + fun showInitialStatusOfParticipants(participants: List) { + participants.forEach { participant -> + val separator = if (participant == participants.first()) "" else ", " + print("$separator${participant.name}") + } + println("에게 2장의 카드를 나눠주었습니다.") + } +} \ No newline at end of file From 8278288113aceb6e1c75113530d99932b9579a5c Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Mon, 13 Nov 2023 23:34:06 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=EC=B4=88=EA=B8=B0=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EB=B0=B0=EB=B6=84=EC=9D=84=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 두 장씩 배분했는지 확인하는 테스트 작성 - 게임 시작하며 카드 풀을 먼저 생성하고 두 장씩의 카드를 배분하도록 구현 - 린트 포맷팅 --- .../blackjack/controller/BlackJackGame.kt | 45 ++++++++++++++++++- src/main/kotlin/blackjack/model/Card.kt | 3 +- src/main/kotlin/blackjack/model/CardInfo.kt | 21 +++++++++ src/main/kotlin/blackjack/model/CardType.kt | 9 ++++ .../kotlin/blackjack/model/Participant.kt | 2 +- src/main/kotlin/blackjack/ui/InputView.kt | 3 +- src/main/kotlin/blackjack/ui/ResultView.kt | 2 +- src/test/kotlin/DslTest.kt | 3 +- .../blackjack/controller/BlackJackGameTest.kt | 28 ++++++++++++ 9 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/CardInfo.kt create mode 100644 src/main/kotlin/blackjack/model/CardType.kt create mode 100644 src/test/kotlin/blackjack/controller/BlackJackGameTest.kt diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 7782ee400e..8bf75e1e36 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -1,12 +1,53 @@ package blackjack.controller +import blackjack.model.Card +import blackjack.model.CardInfo +import blackjack.model.CardType +import blackjack.model.Participant import blackjack.ui.InputView import blackjack.ui.ResultView -class BlackJackGame { +class BlackJackGame( + val participants: List, +) { + + private val cardsPool = mutableSetOf() + + init { + makeCardsPool() + } + + private fun makeCardsPool() { + CardType.values().forEach { type -> + CardInfo.values().forEach { cardInfo -> + cardsPool.add(Card(type, cardInfo)) + } + } + } + + fun allocateDefaultCards() { + participants.forEach { + it.cards.addAll(pickRandomCards(DEFAULT_CARD_COUNTS)) + } + } + + private fun pickRandomCards(count: Int): List { + val pickedCards = cardsPool.shuffled().take(count) + pickedCards.forEach { pickedCard -> + cardsPool.remove(pickedCard) + } + return pickedCards + } + + companion object { + const val DEFAULT_CARD_COUNTS = 2 + } } fun main() { val participants = InputView.registerParticipants() + + val blackJackGame = BlackJackGame(participants) + ResultView.showInitialStatusOfParticipants(participants) -} \ No newline at end of file +} diff --git a/src/main/kotlin/blackjack/model/Card.kt b/src/main/kotlin/blackjack/model/Card.kt index 75bddb841e..da10fcd6ab 100644 --- a/src/main/kotlin/blackjack/model/Card.kt +++ b/src/main/kotlin/blackjack/model/Card.kt @@ -1,5 +1,6 @@ package blackjack.model data class Card( - val name: String, + val type: CardType, + val value: CardInfo, ) diff --git a/src/main/kotlin/blackjack/model/CardInfo.kt b/src/main/kotlin/blackjack/model/CardInfo.kt new file mode 100644 index 0000000000..6d3cfce85b --- /dev/null +++ b/src/main/kotlin/blackjack/model/CardInfo.kt @@ -0,0 +1,21 @@ +package blackjack.model + +enum class CardInfo( + val displayName: String, + val value1: Int, + val value2: Int = value1, +) { + Ace("ace", 1, 10), + One("1", 1), + Two("2", 2), + Three("3", 3), + Four("4", 4), + Five("5", 5), + Six("6", 6), + Seven("7", 7), + Eight("8", 8), + Nine("9", 9), + King("King", 10), + Queen("Queen", 10), + Jack("Jack", 10), +} diff --git a/src/main/kotlin/blackjack/model/CardType.kt b/src/main/kotlin/blackjack/model/CardType.kt new file mode 100644 index 0000000000..37a3fc7d06 --- /dev/null +++ b/src/main/kotlin/blackjack/model/CardType.kt @@ -0,0 +1,9 @@ +package blackjack.model + +enum class CardType { + Diamond, + Spade, + Heart, + Clover, + ; +} diff --git a/src/main/kotlin/blackjack/model/Participant.kt b/src/main/kotlin/blackjack/model/Participant.kt index d1477ea824..c5e7d1ad99 100644 --- a/src/main/kotlin/blackjack/model/Participant.kt +++ b/src/main/kotlin/blackjack/model/Participant.kt @@ -2,5 +2,5 @@ package blackjack.model data class Participant( val name: String, - val cards: List? = null, + val cards: MutableList = mutableListOf(), ) diff --git a/src/main/kotlin/blackjack/ui/InputView.kt b/src/main/kotlin/blackjack/ui/InputView.kt index af54a0468b..60cda5b501 100644 --- a/src/main/kotlin/blackjack/ui/InputView.kt +++ b/src/main/kotlin/blackjack/ui/InputView.kt @@ -25,5 +25,4 @@ object InputView { } } ?: throw IllegalArgumentException("카드 받기 여부는 null을 허용하지 않습니다.") } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt index e3ce6d7d8b..9bf93333a6 100644 --- a/src/main/kotlin/blackjack/ui/ResultView.kt +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -11,4 +11,4 @@ object ResultView { } println("에게 2장의 카드를 나눠주었습니다.") } -} \ No newline at end of file +} diff --git a/src/test/kotlin/DslTest.kt b/src/test/kotlin/DslTest.kt index 59f76fea35..265160eb1f 100644 --- a/src/test/kotlin/DslTest.kt +++ b/src/test/kotlin/DslTest.kt @@ -34,7 +34,6 @@ class DslTest { ) } } - } fun introduce(block: PersonBuilder.() -> Unit): Person { @@ -100,4 +99,4 @@ data class Person( sealed interface Skill { data class SoftSkill(val name: String) : Skill data class HardSkill(val name: String) : Skill -} \ No newline at end of file +} diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt new file mode 100644 index 0000000000..8f64757124 --- /dev/null +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -0,0 +1,28 @@ +package blackjack.controller + +import blackjack.controller.BlackJackGame.Companion.DEFAULT_CARD_COUNTS +import blackjack.model.Participant +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class BlackJackGameTest { + + @Test + fun checkDefaultAllocatedCards() { + val blackJackGame = BlackJackGame(participants) + blackJackGame.allocateDefaultCards() + + blackJackGame.participants.forEach { + it.cards.size shouldBe DEFAULT_CARD_COUNTS + } + } + + companion object { + private val participants = listOf( + Participant("Liam"), + Participant("Noel"), + Participant("Gem"), + Participant("Andy"), + ) + } +} From 2a5331c09adfdb73f8434e3565b3916cd00e3e79 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Mon, 13 Nov 2023 23:42:31 +0900 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=EC=B9=B4=EB=93=9C=20=EB=B0=B0?= =?UTF-8?q?=EB=B6=84=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/controller/BlackJackGame.kt | 1 + src/main/kotlin/blackjack/model/CardInfo.kt | 8 ++++---- src/main/kotlin/blackjack/model/CardType.kt | 12 +++++++----- src/main/kotlin/blackjack/ui/ResultView.kt | 15 ++++++++++++++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 8bf75e1e36..67dc4c9910 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -15,6 +15,7 @@ class BlackJackGame( init { makeCardsPool() + allocateDefaultCards() } private fun makeCardsPool() { diff --git a/src/main/kotlin/blackjack/model/CardInfo.kt b/src/main/kotlin/blackjack/model/CardInfo.kt index 6d3cfce85b..d3cfebb742 100644 --- a/src/main/kotlin/blackjack/model/CardInfo.kt +++ b/src/main/kotlin/blackjack/model/CardInfo.kt @@ -5,7 +5,7 @@ enum class CardInfo( val value1: Int, val value2: Int = value1, ) { - Ace("ace", 1, 10), + Ace("A", 1, 10), One("1", 1), Two("2", 2), Three("3", 3), @@ -15,7 +15,7 @@ enum class CardInfo( Seven("7", 7), Eight("8", 8), Nine("9", 9), - King("King", 10), - Queen("Queen", 10), - Jack("Jack", 10), + King("K", 10), + Queen("Q", 10), + Jack("J", 10), } diff --git a/src/main/kotlin/blackjack/model/CardType.kt b/src/main/kotlin/blackjack/model/CardType.kt index 37a3fc7d06..464c40e7fd 100644 --- a/src/main/kotlin/blackjack/model/CardType.kt +++ b/src/main/kotlin/blackjack/model/CardType.kt @@ -1,9 +1,11 @@ package blackjack.model -enum class CardType { - Diamond, - Spade, - Heart, - Clover, +enum class CardType( + val displayName: String, +) { + Diamond("다이아몬드"), + Spade("스페이드"), + Heart("하트"), + Clover("클로버"), ; } diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt index 9bf93333a6..fee1d3a4b8 100644 --- a/src/main/kotlin/blackjack/ui/ResultView.kt +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -1,5 +1,6 @@ package blackjack.ui +import blackjack.controller.BlackJackGame import blackjack.model.Participant object ResultView { @@ -9,6 +10,18 @@ object ResultView { val separator = if (participant == participants.first()) "" else ", " print("$separator${participant.name}") } - println("에게 2장의 카드를 나눠주었습니다.") + println("에게 ${BlackJackGame.DEFAULT_CARD_COUNTS}장의 카드를 나눠주었습니다.") + + participants.forEach { participant -> + print("${participant.name}카드 : ") + showCards(participant) + } + } + + private fun showCards(participant: Participant) { + participant.cards.forEach { + val postfix = if (it == participant.cards.last()) "\n" else ", " + print("${it.value.displayName}${it.type.displayName}$postfix") + } } } From 376b5bb09c4c30d4b8cb69232ea4219c9841df83 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:10:39 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=ED=95=9C=20=EC=9E=A5=EC=94=A9=20?= =?UTF-8?q?=EB=82=98=EB=88=A0=EC=A3=BC=EB=8A=94=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 한 장씩 나눠주는 케이스에 대한 테스트 코드 작성 - 초기에 모든 참여자에게 두 장씩 나눠주는 케이스는 init에서 처리하므로 접근 제한자를 private으로 변경 --- .../blackjack/controller/BlackJackGame.kt | 6 +++- .../blackjack/controller/BlackJackGameTest.kt | 34 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 67dc4c9910..5c7859b3a1 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -26,12 +26,16 @@ class BlackJackGame( } } - fun allocateDefaultCards() { + private fun allocateDefaultCards() { participants.forEach { it.cards.addAll(pickRandomCards(DEFAULT_CARD_COUNTS)) } } + fun allocateOneCard(participant: Participant) { + participant.cards.addAll(pickRandomCards(count = 1)) + } + private fun pickRandomCards(count: Int): List { val pickedCards = cardsPool.shuffled().take(count) pickedCards.forEach { pickedCard -> diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt index 8f64757124..19da0d0283 100644 --- a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -3,26 +3,42 @@ package blackjack.controller import blackjack.controller.BlackJackGame.Companion.DEFAULT_CARD_COUNTS import blackjack.model.Participant import io.kotest.matchers.shouldBe -import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.MethodSource class BlackJackGameTest { - @Test - fun checkDefaultAllocatedCards() { + @ParameterizedTest + @MethodSource("makeParticipants") + fun checkDefaultAllocatedCards(participants: List) { val blackJackGame = BlackJackGame(participants) - blackJackGame.allocateDefaultCards() blackJackGame.participants.forEach { it.cards.size shouldBe DEFAULT_CARD_COUNTS } } + @ParameterizedTest + @MethodSource("makeParticipants") + fun checkAfterOneCardAllocation(participants: List) { + val blackJackGame = BlackJackGame(participants) + blackJackGame.allocateOneCard(participants[0]) + + participants[0].cards.size shouldBe (DEFAULT_CARD_COUNTS + 1) + } + companion object { - private val participants = listOf( - Participant("Liam"), - Participant("Noel"), - Participant("Gem"), - Participant("Andy"), + @JvmStatic + fun makeParticipants() = listOf( + Arguments.of( + listOf( + Participant("Liam"), + Participant("Noel"), + Participant("Gem"), + Participant("Andy"), + ) + ) ) } } From 2059ffde97f50e6bd200b197e4d9ffa68d904704 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:17:58 +0900 Subject: [PATCH 06/15] =?UTF-8?q?refactor:=20Ace=EC=9D=98=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=9C=20=EA=B0=92=EC=9D=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ace는 1 또는 11로 계산할 수 있다. 10으로 잘못되어 있던 부분을 11로 수정. --- src/main/kotlin/blackjack/model/CardInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/blackjack/model/CardInfo.kt b/src/main/kotlin/blackjack/model/CardInfo.kt index d3cfebb742..1f39d32cbc 100644 --- a/src/main/kotlin/blackjack/model/CardInfo.kt +++ b/src/main/kotlin/blackjack/model/CardInfo.kt @@ -5,7 +5,7 @@ enum class CardInfo( val value1: Int, val value2: Int = value1, ) { - Ace("A", 1, 10), + Ace("A", 1, 11), One("1", 1), Two("2", 2), Three("3", 3), From 59c6b768b98337e56d2e7163876e92ad1f8f4dec Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:20:55 +0900 Subject: [PATCH 07/15] =?UTF-8?q?refactor:=20Card=EC=9D=98=20CardInfo=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=9D=98=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=EB=AA=85=EC=9D=84=20=EB=B3=80=EA=B2=BD=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Card.kt | 2 +- src/main/kotlin/blackjack/ui/ResultView.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Card.kt b/src/main/kotlin/blackjack/model/Card.kt index da10fcd6ab..634fd21c2a 100644 --- a/src/main/kotlin/blackjack/model/Card.kt +++ b/src/main/kotlin/blackjack/model/Card.kt @@ -2,5 +2,5 @@ package blackjack.model data class Card( val type: CardType, - val value: CardInfo, + val info: CardInfo, ) diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt index fee1d3a4b8..364cb5937c 100644 --- a/src/main/kotlin/blackjack/ui/ResultView.kt +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -21,7 +21,7 @@ object ResultView { private fun showCards(participant: Participant) { participant.cards.forEach { val postfix = if (it == participant.cards.last()) "\n" else ", " - print("${it.value.displayName}${it.type.displayName}$postfix") + print("${it.info.displayName}${it.type.displayName}$postfix") } } } From 0d038e4b4c727906caec953c2b1ecfd28a7430b8 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:34:29 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20=EC=B9=B4=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EB=8D=94=20=EB=BD=91=EC=9D=84=20=EC=88=98=20=EC=9E=88=EB=8A=94?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 현재 보유한 카드의 합이 21을 넘지 않는다면 카드를 계속 뽑을 수 있는 상태로 본다. - Ace는 1 또는 11로 계산할 수 있으나 카드 뽑기 선택을 더 넓게 하기 위해 checkCurrentScore()에서는 1로 처리한다. --- .../blackjack/controller/BlackJackGame.kt | 5 ++++ .../kotlin/blackjack/model/Participant.kt | 12 +++++++- .../blackjack/controller/BlackJackGameTest.kt | 28 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 5c7859b3a1..7129f72a53 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -46,6 +46,7 @@ class BlackJackGame( companion object { const val DEFAULT_CARD_COUNTS = 2 + const val BEST_SCORE = 21 } } @@ -55,4 +56,8 @@ fun main() { val blackJackGame = BlackJackGame(participants) ResultView.showInitialStatusOfParticipants(participants) + + blackJackGame.participants.forEach { + val isAllocated = InputView.askCardPicking(it.name) + } } diff --git a/src/main/kotlin/blackjack/model/Participant.kt b/src/main/kotlin/blackjack/model/Participant.kt index c5e7d1ad99..d9c40a5647 100644 --- a/src/main/kotlin/blackjack/model/Participant.kt +++ b/src/main/kotlin/blackjack/model/Participant.kt @@ -1,6 +1,16 @@ package blackjack.model +import blackjack.controller.BlackJackGame.Companion.BEST_SCORE + data class Participant( val name: String, val cards: MutableList = mutableListOf(), -) +) { + fun isPossibleToTakeMoreCard(): Boolean { + return checkCurrentScore() < BEST_SCORE + } + + private fun checkCurrentScore(): Int { + return cards.sumOf { it.info.value1 } + } +} diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt index 19da0d0283..641e465176 100644 --- a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -1,8 +1,12 @@ package blackjack.controller import blackjack.controller.BlackJackGame.Companion.DEFAULT_CARD_COUNTS +import blackjack.model.Card +import blackjack.model.CardInfo +import blackjack.model.CardType import blackjack.model.Participant import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource @@ -28,6 +32,30 @@ class BlackJackGameTest { participants[0].cards.size shouldBe (DEFAULT_CARD_COUNTS + 1) } + @Test + fun `카드를 더 뽑을 수 있는지 확인하는 용도의로 현재 가지고 있는 카드의 합을 계산`() { + val participantScore20 = Participant( + "Paul", + mutableListOf( + Card(CardType.Clover, CardInfo.Ace), + Card(CardType.Clover, CardInfo.Nine), + Card(CardType.Clover, CardInfo.King), + ) + ) + + val participantScore21 = Participant( + "Ringo", + mutableListOf( + Card(CardType.Clover, CardInfo.Six), + Card(CardType.Clover, CardInfo.Seven), + Card(CardType.Clover, CardInfo.Eight), + ) + ) + + participantScore20.isPossibleToTakeMoreCard() shouldBe true + participantScore21.isPossibleToTakeMoreCard() shouldBe false + } + companion object { @JvmStatic fun makeParticipants() = listOf( From 89cd4554c94d3cf769bd974fb5869695f3213310 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:38:03 +0900 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20=EC=B0=B8=EC=97=AC=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EC=B9=B4=EB=93=9C=20=ED=95=A9=20=EA=B3=84=EC=82=B0?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9D=98=20=EC=98=A4=ED=83=80?= =?UTF-8?q?=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=95=98=EA=B3=A0=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=84=20=EB=8D=94=20=EB=AA=85=ED=99=95=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EB=B3=80=EA=B2=BD=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/controller/BlackJackGameTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt index 641e465176..be6582322e 100644 --- a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -33,7 +33,7 @@ class BlackJackGameTest { } @Test - fun `카드를 더 뽑을 수 있는지 확인하는 용도의로 현재 가지고 있는 카드의 합을 계산`() { + fun `카드를 더 뽑을 수 있는지 참여자인지 확인하는 용도로 현재 가지고 있는 카드의 합을 계산`() { val participantScore20 = Participant( "Paul", mutableListOf( From 8e76b66d8d3a104c1651b460cde18170af227b91 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 00:43:32 +0900 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20=EB=8D=94=20=EB=82=98=EB=88=A0?= =?UTF-8?q?=EC=A4=84=20=EC=B9=B4=EB=93=9C=EA=B0=80=20=EC=9E=88=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A5=BC=20=EB=A7=8C=EB=93=A0=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/controller/BlackJackGame.kt | 2 ++ .../kotlin/blackjack/controller/BlackJackGameTest.kt | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 7129f72a53..4d6adf05cc 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -18,6 +18,8 @@ class BlackJackGame( allocateDefaultCards() } + fun isPossibleToAllocation() = cardsPool.isNotEmpty() + private fun makeCardsPool() { CardType.values().forEach { type -> CardInfo.values().forEach { cardInfo -> diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt index be6582322e..ffe8712be1 100644 --- a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -56,6 +56,18 @@ class BlackJackGameTest { participantScore21.isPossibleToTakeMoreCard() shouldBe false } + @ParameterizedTest + @MethodSource("makeParticipants") + fun `더 나눠줄 카드가 있는지 확인`(participants: List) { + val blackJackGame = BlackJackGame(participants) + blackJackGame.isPossibleToAllocation() shouldBe true + + repeat(52) { + blackJackGame.allocateOneCard(participants[0]) + } + blackJackGame.isPossibleToAllocation() shouldBe false + } + companion object { @JvmStatic fun makeParticipants() = listOf( From 0856693847b5725a7501214ddda44f21ff67bd80 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 01:00:18 +0900 Subject: [PATCH 11/15] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=9D=84=20=EC=9E=91=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 깜빡해서 늦게나마 작성... --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1c7c927d8..e16b9174f1 100644 --- a/README.md +++ b/README.md @@ -1 +1,16 @@ -# kotlin-blackjack \ No newline at end of file +# kotlin-blackjack + +게임 관련 기능 + +- [x] 카드 정보 클래스 구성 +- [x] 참여자 클래스 구성 +- [x] 기본 카드 나눠주기(게임 시작과 함께 2장씩 나눠준다.) +- [x] 카드를 나눠줄 수 있는 상태 확인(나눠줄 카드가 남아있는지, 현재 점수가 21점보다 작은지 판단) +- [ ] y/n 응답 별 카드 배분 + +입출력 기능 + +- [x] 참여자 입력 구현 +- [x] 현재 카드 상태 출력 +- [ ] y/n 응답 묻기 +- [ ] 결과 출력 \ No newline at end of file From a6f7065c1100129f636a9f2b34677506fe17c50c Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 01:01:40 +0900 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20=EC=B9=B4=EB=93=9C=20=EC=A0=90?= =?UTF-8?q?=EC=88=98=EC=99=80=20y/n=20=EC=9D=91=EB=8B=B5=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=B9=B4=EB=93=9C=EB=A5=BC=20=EB=8D=94=20?= =?UTF-8?q?=EB=BD=91=EC=9D=84=EC=A7=80=20=EB=A7=90=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=95=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - (고민) 테스트 코드를 작성할 수 있는 부분인지 모르겠음. --- README.md | 4 ++-- .../blackjack/controller/BlackJackGame.kt | 18 +++++++++++++++--- src/main/kotlin/blackjack/ui/ResultView.kt | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e16b9174f1..982b60b1a3 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ - [x] 참여자 클래스 구성 - [x] 기본 카드 나눠주기(게임 시작과 함께 2장씩 나눠준다.) - [x] 카드를 나눠줄 수 있는 상태 확인(나눠줄 카드가 남아있는지, 현재 점수가 21점보다 작은지 판단) -- [ ] y/n 응답 별 카드 배분 +- [x] y/n 응답 별 카드 배분 입출력 기능 - [x] 참여자 입력 구현 - [x] 현재 카드 상태 출력 -- [ ] y/n 응답 묻기 +- [x] y/n 응답 묻기 - [ ] 결과 출력 \ No newline at end of file diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index 4d6adf05cc..a9095d4d5a 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -18,6 +18,20 @@ class BlackJackGame( allocateDefaultCards() } + fun allocateCards() { + participants.forEach { participant -> + while (participant.isPossibleToTakeMoreCard()) { + if (InputView.askCardPicking(participant.name)) { + allocateOneCard(participant) + ResultView.showStatusOfParticipant(participant) + } else { + ResultView.showStatusOfParticipant(participant) + break + } + } + } + } + fun isPossibleToAllocation() = cardsPool.isNotEmpty() private fun makeCardsPool() { @@ -59,7 +73,5 @@ fun main() { ResultView.showInitialStatusOfParticipants(participants) - blackJackGame.participants.forEach { - val isAllocated = InputView.askCardPicking(it.name) - } + blackJackGame.allocateCards() } diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt index 364cb5937c..bf1dcb320d 100644 --- a/src/main/kotlin/blackjack/ui/ResultView.kt +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -18,6 +18,11 @@ object ResultView { } } + fun showStatusOfParticipant(participant: Participant) { + print("${participant.name}카드 : ") + showCards(participant) + } + private fun showCards(participant: Participant) { participant.cards.forEach { val postfix = if (it == participant.cards.last()) "\n" else ", " From a2970998075718b8fe6194c7a0e979d730c2f9ae Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 01:07:55 +0900 Subject: [PATCH 13/15] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=ED=95=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 상황에 따라 Ace의 점수를 1로 사용할지 11로 사용할지 결정하고, 21과 가장 가까운 점수로 계산하는 기능 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 982b60b1a3..c536644447 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [x] 기본 카드 나눠주기(게임 시작과 함께 2장씩 나눠준다.) - [x] 카드를 나눠줄 수 있는 상태 확인(나눠줄 카드가 남아있는지, 현재 점수가 21점보다 작은지 판단) - [x] y/n 응답 별 카드 배분 +- [ ] 최적의 점수 구하기 입출력 기능 From b6f555a27e7140d9e047075dc8005124627aca41 Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 01:30:18 +0900 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20Participant=EC=97=90=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=EC=9D=98=20=EC=A0=90=EC=88=98=EB=A5=BC=20=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 보유한 각 Ace가 1이거나 11인 경우를 모두 확인하고, 가장 적절한 점수를 반환하도록 구현 - 총점이 21보다 작거나 같다면 그 중 가장 큰 값을, 21보다 크다면 그 중 가장 작은 값을 반환 - 참고로 21을 넘어가면 의미가 없음 --- README.md | 2 +- .../kotlin/blackjack/model/Participant.kt | 19 +++++++++++++++ .../blackjack/controller/BlackJackGameTest.kt | 24 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c536644447..6353c2bddc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - [x] 기본 카드 나눠주기(게임 시작과 함께 2장씩 나눠준다.) - [x] 카드를 나눠줄 수 있는 상태 확인(나눠줄 카드가 남아있는지, 현재 점수가 21점보다 작은지 판단) - [x] y/n 응답 별 카드 배분 -- [ ] 최적의 점수 구하기 +- [x] 최적의 점수 구하기 입출력 기능 diff --git a/src/main/kotlin/blackjack/model/Participant.kt b/src/main/kotlin/blackjack/model/Participant.kt index d9c40a5647..2331599acf 100644 --- a/src/main/kotlin/blackjack/model/Participant.kt +++ b/src/main/kotlin/blackjack/model/Participant.kt @@ -1,6 +1,8 @@ package blackjack.model import blackjack.controller.BlackJackGame.Companion.BEST_SCORE +import kotlin.math.max +import kotlin.math.min data class Participant( val name: String, @@ -13,4 +15,21 @@ data class Participant( private fun checkCurrentScore(): Int { return cards.sumOf { it.info.value1 } } + + fun takeBestScore(): Int { + val scoreWithoutAce = cards.filter { it.info != CardInfo.Ace }.sumOf { it.info.value1 } + val countOfAce = cards.count { it.info == CardInfo.Ace } + var bestScore = scoreWithoutAce + countOfAce * CardInfo.Ace.value1 + (0 until countOfAce).forEach { countOfScoreOneAce -> + val scoreOfAces = + countOfScoreOneAce * CardInfo.Ace.value1 + (countOfAce - countOfScoreOneAce) * CardInfo.Ace.value2 + val totalScore = scoreWithoutAce + scoreOfAces + bestScore = if (totalScore <= BEST_SCORE) { + max(bestScore, totalScore) + } else { + min(bestScore, totalScore) + } + } + return bestScore + } } diff --git a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt index ffe8712be1..ba9a668ab4 100644 --- a/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt +++ b/src/test/kotlin/blackjack/controller/BlackJackGameTest.kt @@ -68,6 +68,30 @@ class BlackJackGameTest { blackJackGame.isPossibleToAllocation() shouldBe false } + @Test + fun `최적의 점수`() { + val participant = Participant( + "John", + mutableListOf( + Card(CardType.Clover, CardInfo.Ace), + Card(CardType.Clover, CardInfo.Jack), + Card(CardType.Clover, CardInfo.King), + ) + ) + + val participant2 = Participant( + "George", + mutableListOf( + Card(CardType.Clover, CardInfo.One), + Card(CardType.Clover, CardInfo.Two), + Card(CardType.Clover, CardInfo.Three), + ) + ) + + participant.takeBestScore() shouldBe 21 + participant2.takeBestScore() shouldBe 6 + } + companion object { @JvmStatic fun makeParticipants() = listOf( From f4cb19f9de6b7ae9d91cb6eaf1dc903269d6dc9d Mon Sep 17 00:00:00 2001 From: bsgreentea Date: Wed, 15 Nov 2023 01:34:49 +0900 Subject: [PATCH 15/15] =?UTF-8?q?feat:=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../kotlin/blackjack/controller/BlackJackGame.kt | 2 ++ src/main/kotlin/blackjack/ui/ResultView.kt | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6353c2bddc..5e0184a9a7 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ - [x] 참여자 입력 구현 - [x] 현재 카드 상태 출력 - [x] y/n 응답 묻기 -- [ ] 결과 출력 \ No newline at end of file +- [x] 결과 출력 \ No newline at end of file diff --git a/src/main/kotlin/blackjack/controller/BlackJackGame.kt b/src/main/kotlin/blackjack/controller/BlackJackGame.kt index a9095d4d5a..e1cb314974 100644 --- a/src/main/kotlin/blackjack/controller/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/controller/BlackJackGame.kt @@ -74,4 +74,6 @@ fun main() { ResultView.showInitialStatusOfParticipants(participants) blackJackGame.allocateCards() + + ResultView.showGameResult(blackJackGame.participants) } diff --git a/src/main/kotlin/blackjack/ui/ResultView.kt b/src/main/kotlin/blackjack/ui/ResultView.kt index bf1dcb320d..8a00b66911 100644 --- a/src/main/kotlin/blackjack/ui/ResultView.kt +++ b/src/main/kotlin/blackjack/ui/ResultView.kt @@ -15,18 +15,28 @@ object ResultView { participants.forEach { participant -> print("${participant.name}카드 : ") showCards(participant) + println() } } - fun showStatusOfParticipant(participant: Participant) { + fun showStatusOfParticipant(participant: Participant, useNewLine: Boolean = true) { print("${participant.name}카드 : ") showCards(participant) + if (useNewLine) println() } private fun showCards(participant: Participant) { participant.cards.forEach { - val postfix = if (it == participant.cards.last()) "\n" else ", " + val postfix = if (it == participant.cards.last()) "" else ", " print("${it.info.displayName}${it.type.displayName}$postfix") } } + + fun showGameResult(participants: List) { + println() + participants.forEach { participant -> + showStatusOfParticipant(participant, useNewLine = false) + println(" - 결과 : ${participant.takeBestScore()}") + } + } }