From 45309613e9ca06e994c815e8c8fc98b38df8fa74 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 01:45:10 +0900 Subject: [PATCH 01/81] =?UTF-8?q?refactor=20:=20=EC=99=B8=EB=B6=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B8=94=EB=9E=99=EC=9E=AD=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EB=BD=91=EB=8A=94=20=EC=A0=84=EB=9E=B5?= =?UTF-8?q?=EC=9D=84=20=EC=A3=BC=EC=9E=85=EB=B0=9B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 5 +++-- src/main/kotlin/blackjack/model/Participants.kt | 6 ++++-- src/main/kotlin/blackjack/model/Player.kt | 12 ++++++------ src/test/kotlin/blackjack/model/PlayerTest.kt | 5 +++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 01b613427d..c15bb34ef5 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -2,12 +2,13 @@ package blackjack import blackjack.model.Participants import blackjack.model.Player +import blackjack.model.pack.ShuffledPack import blackjack.view.InputView import blackjack.view.OutputView fun main() { val participants = InputView.join() - participants.dealing() + participants.dealing(ShuffledPack) OutputView.dealing(participants) OutputView.presentCards(participants) while (participants.isContinue()) { @@ -24,7 +25,7 @@ fun playingBlackJack(participants: Participants) { private fun Player.hitOrStand() { if (InputView.askHit(this)) { - this.hit() + this.hit(ShuffledPack) } OutputView.playerCardPresent(this) } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 875f0f922f..6aba24afcb 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -1,5 +1,7 @@ package blackjack.model +import blackjack.model.pack.Pack + class Participants( val participants: Set, ) { @@ -7,8 +9,8 @@ class Participants( return participants.size } - fun dealing() { - participants.forEach { it.deal() } + fun dealing(pack: Pack) { + participants.forEach { it.deal(pack) } } private fun isGameOver(): Boolean { diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 4d98a6840d..23f4c92504 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -1,17 +1,17 @@ package blackjack.model -import blackjack.model.pack.ShuffledPack +import blackjack.model.pack.Pack data class Player( val name: String, val cards: Cards = Cards.emptyCards(), ) { - fun deal() { - cards.add(ShuffledPack.pickCard()) - cards.add(ShuffledPack.pickCard()) + fun deal(pack: Pack) { + cards.add(pack.pickCard()) + cards.add(pack.pickCard()) } - fun hit() { - cards.add(ShuffledPack.pickCard()) + fun hit(pack: Pack) { + cards.add(pack.pickCard()) } } diff --git a/src/test/kotlin/blackjack/model/PlayerTest.kt b/src/test/kotlin/blackjack/model/PlayerTest.kt index 41efb3eb5f..64fd69304b 100644 --- a/src/test/kotlin/blackjack/model/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/PlayerTest.kt @@ -1,5 +1,6 @@ package blackjack.model +import blackjack.model.pack.ShuffledPack import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -8,7 +9,7 @@ class PlayerTest : StringSpec({ "플레이어는 dealing 시 2장의 카드를 받을 수 있다" { shouldNotThrow { val player = Player("구글") - player.deal() + player.deal(ShuffledPack) player.cards.count() shouldBe 2 } } @@ -16,7 +17,7 @@ class PlayerTest : StringSpec({ "플레이어는 hit 시 1장의 카드를 받을 수 있다" { shouldNotThrow { val player = Player("애플") - player.hit() + player.hit(ShuffledPack) player.cards.count() shouldBe 1 } } From 768e5e88db9a742b03a9b9c93f21d4d786a46143 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 01:57:47 +0900 Subject: [PATCH 02/81] =?UTF-8?q?learn=20:=20=EB=AF=B8=EC=99=84=EC=84=B1?= =?UTF-8?q?=20=ED=95=99=EC=8A=B5=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=99=84?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=ED=82=B4=20:=20=EB=B0=A9=EC=96=B4=EC=A0=81?= =?UTF-8?q?=20=EB=B3=B5=EC=82=AC=20=EA=B4=80=EB=A0=A8=20=EC=98=88=EC=A0=9C?= =?UTF-8?q?=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/study/DefensiveCopyLearn.kt | 47 ++++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/study/DefensiveCopyLearn.kt b/src/test/kotlin/study/DefensiveCopyLearn.kt index d8aa5eede9..4f8cbb3c01 100644 --- a/src/test/kotlin/study/DefensiveCopyLearn.kt +++ b/src/test/kotlin/study/DefensiveCopyLearn.kt @@ -1,21 +1,46 @@ package study -import blackjack.model.Card -import blackjack.model.Cards -import blackjack.model.pack.ShuffledPack import blackjack.view.Console.present import io.kotest.core.spec.style.StringSpec class DefensiveCopyLearn : StringSpec({ - "sdf" { - val list = mutableListOf() - list.add(ShuffledPack.pickCard()) - list.add(ShuffledPack.pickCard()) - list.add(ShuffledPack.pickCard()) - val cards = Cards(list) - println("BEFORE : ${cards.present()}") + "방어적 복사를 하지 않았을 때의 문제가 되는 코드 예제" { + val list = mutableListOf() + list.add("goodNight") + list.add("goodMorning") + list.add("niceYoMeetYou") + val nonDefensiveClass = NonDefensiveClass(list) + println("BEFORE : ${nonDefensiveClass.present()}") list.clear() - println("AFTER : ${cards.present()}") + println("AFTER : ${nonDefensiveClass.present()}") + } + + "방어적 복사를 적용한 코드 예제" { + val list = mutableListOf() + list.add("goodNight") + list.add("goodMorning") + list.add("niceYoMeetYou") + val nonDefensiveClass = NonDefensiveClass(list) + println("BEFORE : ${nonDefensiveClass.present()}") + list.clear() + println("AFTER : ${nonDefensiveClass.present()}") } }) + +class NonDefensiveClass( + val strings: MutableList +) { + fun present(): String { + return strings.toString() + } +} + +class DefensiveClass { + private val _strings: MutableList = strings.toMutableList() + val strings: List get() = _strings.toList() + + fun present(): String { + return strings.toString() + } +} From f595abb19726b3ecab6ce1222b9a00bea684584f Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 01:59:16 +0900 Subject: [PATCH 03/81] =?UTF-8?q?learn=20:=20=EB=AF=B8=EC=99=84=EC=84=B1?= =?UTF-8?q?=20=ED=95=99=EC=8A=B5=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=99=84?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=ED=82=B4=20:=20=EB=B0=A9=EC=96=B4=EC=A0=81?= =?UTF-8?q?=20=EB=B3=B5=EC=82=AC=20=EA=B4=80=EB=A0=A8=20=EC=98=88=EC=A0=9C?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/study/DefensiveCopyLearn.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/kotlin/study/DefensiveCopyLearn.kt b/src/test/kotlin/study/DefensiveCopyLearn.kt index 4f8cbb3c01..5f91f024b7 100644 --- a/src/test/kotlin/study/DefensiveCopyLearn.kt +++ b/src/test/kotlin/study/DefensiveCopyLearn.kt @@ -21,10 +21,10 @@ class DefensiveCopyLearn : StringSpec({ list.add("goodNight") list.add("goodMorning") list.add("niceYoMeetYou") - val nonDefensiveClass = NonDefensiveClass(list) - println("BEFORE : ${nonDefensiveClass.present()}") + val defensiveClass = DefensiveClass(list.toList()) + println("BEFORE : ${defensiveClass.present()}") list.clear() - println("AFTER : ${nonDefensiveClass.present()}") + println("AFTER : ${defensiveClass.present()}") } }) From 2c3439f26eeca6e03e29ad2ef36cea7d1fda609d Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:00:04 +0900 Subject: [PATCH 04/81] =?UTF-8?q?learn=20:=20=EB=AF=B8=EC=99=84=EC=84=B1?= =?UTF-8?q?=20=ED=95=99=EC=8A=B5=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=99=84?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=ED=82=B4=20:=20=EB=B0=A9=EC=96=B4=EC=A0=81?= =?UTF-8?q?=20=EB=B3=B5=EC=82=AC=20=EA=B4=80=EB=A0=A8=20=EC=98=88=EC=A0=9C?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/study/DefensiveCopyLearn.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/study/DefensiveCopyLearn.kt b/src/test/kotlin/study/DefensiveCopyLearn.kt index 5f91f024b7..0bef41a000 100644 --- a/src/test/kotlin/study/DefensiveCopyLearn.kt +++ b/src/test/kotlin/study/DefensiveCopyLearn.kt @@ -1,6 +1,5 @@ package study -import blackjack.view.Console.present import io.kotest.core.spec.style.StringSpec class DefensiveCopyLearn : StringSpec({ @@ -36,7 +35,9 @@ class NonDefensiveClass( } } -class DefensiveClass { +class DefensiveClass( + strings: List +) { private val _strings: MutableList = strings.toMutableList() val strings: List get() = _strings.toList() From ec334d4004649c4c0566ac55e8c4340208c02862 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:06:40 +0900 Subject: [PATCH 05/81] =?UTF-8?q?refactor=20:=20Pair<>=20=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=EA=B5=AC=EC=A1=B0=EB=A5=BC=20=ED=95=98=EB=82=98?= =?UTF-8?q?=EC=9D=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=AC=B6?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Par 를 Tramp 로 수정 --- src/main/kotlin/blackjack/model/Card.kt | 6 +++--- src/main/kotlin/blackjack/model/Trump.kt | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/Trump.kt diff --git a/src/main/kotlin/blackjack/model/Card.kt b/src/main/kotlin/blackjack/model/Card.kt index 25808b1c81..c9a81e6eab 100644 --- a/src/main/kotlin/blackjack/model/Card.kt +++ b/src/main/kotlin/blackjack/model/Card.kt @@ -5,16 +5,16 @@ class Card private constructor( val cardRank: CardRank, ) { companion object { - private val CARDS: Map, Card> by lazy { + private val CARDS: Map by lazy { Suit.values().flatMap { suit -> CardRank.values().map { rank -> - (suit to rank) to Card(suit, rank) + Trump(suit to rank) to Card(suit, rank) } }.toMap() } fun of(suit: Suit, cardRank: CardRank): Card { - return requireNotNull(this.CARDS[suit to cardRank]) { "입력된 suit=[$suit] , cardRank=[$cardRank] 는 찾을수 없습니다" } + return requireNotNull(this.CARDS[Trump(suit to cardRank)]) { "입력된 suit=[$suit] , cardRank=[$cardRank] 는 찾을수 없습니다" } } } } diff --git a/src/main/kotlin/blackjack/model/Trump.kt b/src/main/kotlin/blackjack/model/Trump.kt new file mode 100644 index 0000000000..fbc8f3139a --- /dev/null +++ b/src/main/kotlin/blackjack/model/Trump.kt @@ -0,0 +1,6 @@ +package blackjack.model + +@JvmInline +value class Trump( + val trump: Pair, +) From 2196d5b25080291f03c54e90fbb4f797a8bddc09 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:08:28 +0900 Subject: [PATCH 06/81] =?UTF-8?q?refactor=20:=20=EA=B3=BC=EB=8F=84?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EA=B8=B8=EA=B3=A0=20=EB=8B=A4=EC=86=8C=20?= =?UTF-8?q?=EB=B6=80=EC=A1=B1=ED=95=9C=20=ED=91=9C=ED=98=84=EC=9D=98=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=EC=9D=84=20=EC=A0=81=EC=A0=88?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Cards.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Cards.kt b/src/main/kotlin/blackjack/model/Cards.kt index f678b87c39..a2af3cc74d 100644 --- a/src/main/kotlin/blackjack/model/Cards.kt +++ b/src/main/kotlin/blackjack/model/Cards.kt @@ -28,10 +28,10 @@ class Cards( private fun scoreWithAce(): Int { val simpleSum = simpleSumOfScore() - if (simpleSum + ALTERNATIVE_ACE_SCORE_DIFF > HIGHEST_SCORE) { + if (simpleSum + ACE_BONUS_SCORE > HIGHEST_SCORE) { return simpleSum } - return simpleSum + ALTERNATIVE_ACE_SCORE_DIFF + return simpleSum + ACE_BONUS_SCORE } fun count(): Int { @@ -40,7 +40,7 @@ class Cards( companion object { private const val HIGHEST_SCORE: Int = 21 - private const val ALTERNATIVE_ACE_SCORE_DIFF: Int = 11 - 1 + private const val ACE_BONUS_SCORE: Int = 10 fun emptyCards(): Cards { return Cards(mutableListOf()) From 193b74bebb9d7f0690919575cfa8db68ba60cec0 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:20:07 +0900 Subject: [PATCH 07/81] =?UTF-8?q?docs=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B6=84=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 71f85ac028..0262ac73ec 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,23 @@ Player.hit() : 블랙잭에서 카드를 받는 행동은 "히트" 딜러가 - 매직넘버, 매직스트링을 상수로 분리해내기 (특히 view, model) - 어떤 테스트코드가 필요한지 생각하고(뭘 구현해야하지, 뭐가 요구조건인지 리마인드) >> 테스트코드를 작성하고 >> 테스트할수 있도록 리팩토링하기 ``` + +

+ +## 🚀 3단계 - 블랙잭(딜러) + +- 요구사항 분석 +```text +- 딜러 기능을 구현 + - 딜러와 플레이어 중 카드의 합이 21 또는 21에 가장 가까운 숫자를 가지는 쪽이 이기는 기능을 구현 + - 딜러는 처음에 받은 2장의 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 하고, 17점 이상이면 추가로 받을 수 없다 + - 딜러의 히트/스텐드 전략은 자동이라는 의미임. 테스트코드 작성 필요 + +- 심판기능(Referee) : 점수계산 $& 승패를 판단 + - 딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리한다. + - 블랙잭 게임은 딜러와 플레이어 중 카드의 합이 21 또는 21에 가장 가까운 숫자를 가지는 쪽이 이긴다 + +-입출력 기능 + - 게임을 완료한 후 각 플레이어별로 승패를 출력 + +``` From 2e6ed517ceac74be53fb9f4492c9e37bf751ff73 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:20:56 +0900 Subject: [PATCH 08/81] =?UTF-8?q?test=20:=20=EB=94=9C=EB=9F=AC=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EA=B3=A0,=20=EB=94=9C=EB=9F=AC=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=B1=85=EC=9E=84=EC=A0=80=EC=95=BC?= =?UTF-8?q?=ED=95=A0=20=EC=97=AD=ED=95=A0=EC=97=90=20=EB=8C=80=ED=95=B4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 7 +++++++ src/test/kotlin/blackjack/model/DealerTest.kt | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/kotlin/blackjack/model/Dealer.kt create mode 100644 src/test/kotlin/blackjack/model/DealerTest.kt diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt new file mode 100644 index 0000000000..03e417e3cb --- /dev/null +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -0,0 +1,7 @@ +package blackjack.model + +data class Dealer ( + val cards: Cards = Cards.emptyCards(), +){ + +} diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt new file mode 100644 index 0000000000..d4f37e310f --- /dev/null +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -0,0 +1,18 @@ +package blackjack.model + +import io.kotest.core.spec.style.StringSpec + +class DealerTest : StringSpec({ + + "딜러는 처음에 받은 2장의 카드 점수 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 한다" { + TODO() + } + + "딜러는 카드의 점수 합계가 17점 이상이면 추가로 받을 수 없다" { + TODO() + } + + "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리" { + + } +}) From dc3c6f63439335d5d269d99a1778080d6b8edf93 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:21:16 +0900 Subject: [PATCH 09/81] =?UTF-8?q?feat=20:=20=EC=B0=B8=EA=B0=80=EC=9E=90=20?= =?UTF-8?q?=EB=AA=85=EB=8B=A8=EC=97=90=20=EB=94=9C=EB=9F=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Participants.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 6aba24afcb..3fbdbe9317 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -4,6 +4,7 @@ import blackjack.model.pack.Pack class Participants( val participants: Set, + val dealer :Dealer, ) { fun count(): Int { return participants.size From 01dd4cacebed213891dafd703a131c11b99ff59f Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 02:44:10 +0900 Subject: [PATCH 10/81] =?UTF-8?q?refactor=20:=20=ED=94=8C=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=EB=A1=9C=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 2 +- src/main/kotlin/blackjack/model/Participants.kt | 8 ++++---- src/main/kotlin/blackjack/view/OutputView.kt | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index c15bb34ef5..7d363fcfd1 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -18,7 +18,7 @@ fun main() { } fun playingBlackJack(participants: Participants) { - participants.participants.forEach { + participants.players.forEach { it.hitOrStand() } } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 3fbdbe9317..0cced49829 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -3,19 +3,19 @@ package blackjack.model import blackjack.model.pack.Pack class Participants( - val participants: Set, + val players: Set, val dealer :Dealer, ) { fun count(): Int { - return participants.size + return players.size } fun dealing(pack: Pack) { - participants.forEach { it.deal(pack) } + players.forEach { it.deal(pack) } } private fun isGameOver(): Boolean { - return participants.none { Referee.isBlackJack(it) } + return players.none { Referee.isBlackJack(it) } } fun isContinue(): Boolean { diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 24527e6393..14a45d4037 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -29,13 +29,13 @@ object OutputView { } private fun Participants.present(): String { - return this.participants.joinToString(separator = "\n") { it.present() } + return this.players.joinToString(separator = "\n") { it.present() } } private fun Participants.presentWithScore(): String { - return this.participants.joinToString(separator = "\n") { "${it.present()} - 결과: ${it.cards.totalScore()}" } + return this.players.joinToString(separator = "\n") { "${it.present()} - 결과: ${it.cards.totalScore()}" } } private fun Participants.names(): String { - return participants.joinToString(separator = InputView.PARTICIPANTS_PRESENT_SEPARATOR) { it.name } + return players.joinToString(separator = InputView.PARTICIPANTS_PRESENT_SEPARATOR) { it.name } } From c294555d25f5e25d905420b47433e45d0391518a Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 03:02:32 +0900 Subject: [PATCH 11/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 6 +-- .../blackjack/model/ParticipantResults.kt | 14 ++++++ .../kotlin/blackjack/model/Participants.kt | 2 +- src/main/kotlin/blackjack/model/Referee.kt | 4 ++ src/main/kotlin/blackjack/model/Result.kt | 7 +++ src/main/kotlin/blackjack/view/InputView.kt | 4 +- src/test/kotlin/blackjack/model/DealerTest.kt | 4 -- .../kotlin/blackjack/model/RefereeTest.kt | 44 +++++++++++++++++++ 8 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/ParticipantResults.kt create mode 100644 src/main/kotlin/blackjack/model/Result.kt diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 03e417e3cb..5e919c638f 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -1,7 +1,5 @@ package blackjack.model -data class Dealer ( +data class Dealer( val cards: Cards = Cards.emptyCards(), -){ - -} +) diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/ParticipantResults.kt new file mode 100644 index 0000000000..a0529846d4 --- /dev/null +++ b/src/main/kotlin/blackjack/model/ParticipantResults.kt @@ -0,0 +1,14 @@ +package blackjack.model + +class ParticipantResults( + val playerResults: Set>, + val dealerResult: Pair, +) { + fun dealerResult(): Result { + return dealerResult.second + } + + fun findPlayerResult(player: Player): Result { + TODO() + } +} diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 0cced49829..eeb722566f 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -4,7 +4,7 @@ import blackjack.model.pack.Pack class Participants( val players: Set, - val dealer :Dealer, + val dealer: Dealer, ) { fun count(): Int { return players.size diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index 15c30cbe6c..c707b806f3 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -5,4 +5,8 @@ object Referee { fun isBlackJack(it: Player): Boolean { return it.cards.totalScore() == BLACK_JACK_SCORE } + + fun blackJackResult(participants: Participants): ParticipantResults { + TODO("Not yet implemented") + } } diff --git a/src/main/kotlin/blackjack/model/Result.kt b/src/main/kotlin/blackjack/model/Result.kt new file mode 100644 index 0000000000..cdc82fe1fe --- /dev/null +++ b/src/main/kotlin/blackjack/model/Result.kt @@ -0,0 +1,7 @@ +package blackjack.model + +data class Result( + val point: Int, + val winning: Int, + val losing: Int, +) diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 08fd3a1cd6..490cfdfa37 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -1,5 +1,6 @@ package blackjack.view +import blackjack.model.Dealer import blackjack.model.Participants import blackjack.model.Player @@ -13,7 +14,8 @@ object InputView { input.split(PLAYER_NAMES_DELIMITER) .asSequence() .map { Player(it) } - .toSet() + .toSet(), + Dealer() ) } diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index d4f37e310f..b3c13e041d 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -11,8 +11,4 @@ class DealerTest : StringSpec({ "딜러는 카드의 점수 합계가 17점 이상이면 추가로 받을 수 없다" { TODO() } - - "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리" { - - } }) diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index 2da25b0950..2d2bcdb71e 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -31,4 +31,48 @@ class RefereeTest : StringSpec({ ) Referee.isBlackJack(player) shouldBe true } + + "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { + val player1 = Player( + "seoul", + Cards( + listOf( + Card.of(Suit.DIAMOND, CardRank.ACE), + Card.of(Suit.CLOVER, CardRank.KING) + ) + ) + ) + val player2 = Player( + "wonju", + Cards( + listOf( + Card.of(Suit.DIAMOND, CardRank.QUEEN), + Card.of(Suit.CLOVER, CardRank.KING) + ) + ) + ) + val dealer = Dealer( + Cards( + listOf( + Card.of(Suit.DIAMOND, CardRank.FIVE), + Card.of(Suit.CLOVER, CardRank.KING), + Card.of(Suit.HEART, CardRank.SEVEN), + ) + ) + ) + val participants = Participants(setOf(player1, player2), dealer) + val actual = Referee.blackJackResult(participants) + + actual.dealerResult().point shouldBe 22 + actual.dealerResult().winning shouldBe 0 + actual.dealerResult().losing shouldBe 2 + + actual.findPlayerResult(player1).point shouldBe 21 + actual.findPlayerResult(player1).winning shouldBe 1 + actual.findPlayerResult(player1).losing shouldBe 0 + + actual.findPlayerResult(player2).point shouldBe 20 + actual.findPlayerResult(player2).winning shouldBe 1 + actual.findPlayerResult(player2).losing shouldBe 0 + } }) From 2f9e2f2ddf960bfb703e1021ce16f8b26220815b Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 20 Nov 2023 03:09:26 +0900 Subject: [PATCH 12/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=EC=9D=98=20=EC=97=AD=ED=95=A0=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 9 ++++++- src/test/kotlin/blackjack/model/DealerTest.kt | 24 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 5e919c638f..665df18321 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -1,5 +1,12 @@ package blackjack.model +import blackjack.model.pack.Pack + data class Dealer( val cards: Cards = Cards.emptyCards(), -) +) { + fun run(pack: Pack) { + cards.totalScore() > 17 + TODO() + } +} diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index b3c13e041d..dcc50f95a0 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -1,14 +1,34 @@ package blackjack.model +import blackjack.model.pack.ShuffledPack import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe class DealerTest : StringSpec({ "딜러는 처음에 받은 2장의 카드 점수 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 한다" { - TODO() + val dealer = Dealer( + Cards( + listOf( + Card.of(Suit.CLOVER, CardRank.KING), + Card.of(Suit.HEART, CardRank.SIX), + ) + ) + ) + dealer.run(ShuffledPack) + dealer.cards.count() shouldBe 3 } "딜러는 카드의 점수 합계가 17점 이상이면 추가로 받을 수 없다" { - TODO() + val dealer = Dealer( + Cards( + listOf( + Card.of(Suit.CLOVER, CardRank.KING), + Card.of(Suit.HEART, CardRank.SEVEN), + ) + ) + ) + dealer.run(ShuffledPack) + dealer.cards.count() shouldBe 2 } }) From cf0f5f26d2033bd9da03ef15333d42700dd1fe04 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 21 Nov 2023 15:16:29 +0900 Subject: [PATCH 13/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=EC=9D=98=20=EC=97=AD=ED=95=A0=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 4 ++++ src/test/kotlin/blackjack/model/DealerTest.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 665df18321..914a3db1ea 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -9,4 +9,8 @@ data class Dealer( cards.totalScore() > 17 TODO() } + + fun countOfCards(): Int { + return cards.count() + } } diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index dcc50f95a0..79db8ebd4d 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -29,6 +29,6 @@ class DealerTest : StringSpec({ ) ) dealer.run(ShuffledPack) - dealer.cards.count() shouldBe 2 + dealer.countOfCards() shouldBe 2 } }) From c651d719c09a2d84ce9acae1dd34f3aefe011b78 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 21 Nov 2023 15:30:03 +0900 Subject: [PATCH 14/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 15 ++++++++++++--- src/main/kotlin/blackjack/model/Participants.kt | 4 +--- src/test/kotlin/blackjack/model/DealerTest.kt | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 914a3db1ea..0391b38475 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -5,12 +5,21 @@ import blackjack.model.pack.Pack data class Dealer( val cards: Cards = Cards.emptyCards(), ) { - fun run(pack: Pack) { - cards.totalScore() > 17 - TODO() + fun play(pack: Pack) { + if (isDealerHit()) { + cards.add(pack.pickCard()) + } + } + + private fun isDealerHit(): Boolean { + return cards.totalScore() <= DEALER_PICK_THRESHOLD } fun countOfCards(): Int { return cards.count() } + + companion object { + private const val DEALER_PICK_THRESHOLD = 16; + } } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index eeb722566f..b8f6e73526 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -6,12 +6,10 @@ class Participants( val players: Set, val dealer: Dealer, ) { - fun count(): Int { - return players.size - } fun dealing(pack: Pack) { players.forEach { it.deal(pack) } + dealer.play(pack) } private fun isGameOver(): Boolean { diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index 79db8ebd4d..37cd1cc16c 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -15,8 +15,8 @@ class DealerTest : StringSpec({ ) ) ) - dealer.run(ShuffledPack) - dealer.cards.count() shouldBe 3 + dealer.play(ShuffledPack) + dealer.countOfCards() shouldBe 3 } "딜러는 카드의 점수 합계가 17점 이상이면 추가로 받을 수 없다" { @@ -28,7 +28,7 @@ class DealerTest : StringSpec({ ) ) ) - dealer.run(ShuffledPack) + dealer.play(ShuffledPack) dealer.countOfCards() shouldBe 2 } }) From 1f8d48fb6210194fa1d0284b1664024a50fd8401 Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 22 Nov 2023 17:07:08 +0900 Subject: [PATCH 15/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 13 ++++++--- .../model/{Result.kt => DealerResult.kt} | 2 +- .../blackjack/model/ParticipantResults.kt | 27 +++++++++++++++---- .../kotlin/blackjack/model/Participants.kt | 9 ++++++- src/main/kotlin/blackjack/model/Playable.kt | 5 ++++ src/main/kotlin/blackjack/model/Player.kt | 8 ++++-- .../kotlin/blackjack/model/PlayerResult.kt | 6 +++++ src/main/kotlin/blackjack/model/Referee.kt | 26 ++++++++++++++++-- .../blackjack/model/ParticipantsTest.kt | 11 ++++++++ .../kotlin/blackjack/model/RefereeTest.kt | 4 +-- 10 files changed, 94 insertions(+), 17 deletions(-) rename src/main/kotlin/blackjack/model/{Result.kt => DealerResult.kt} (78%) create mode 100644 src/main/kotlin/blackjack/model/Playable.kt create mode 100644 src/main/kotlin/blackjack/model/PlayerResult.kt create mode 100644 src/test/kotlin/blackjack/model/ParticipantsTest.kt diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 0391b38475..abf16b204f 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -2,9 +2,10 @@ package blackjack.model import blackjack.model.pack.Pack -data class Dealer( - val cards: Cards = Cards.emptyCards(), -) { +class Dealer( + val cards: Cards = Cards(), +) : Playable { + fun play(pack: Pack) { if (isDealerHit()) { cards.add(pack.pickCard()) @@ -20,6 +21,10 @@ data class Dealer( } companion object { - private const val DEALER_PICK_THRESHOLD = 16; + private const val DEALER_PICK_THRESHOLD = 16 + } + + override fun score(): Int { + return cards.totalScore() } } diff --git a/src/main/kotlin/blackjack/model/Result.kt b/src/main/kotlin/blackjack/model/DealerResult.kt similarity index 78% rename from src/main/kotlin/blackjack/model/Result.kt rename to src/main/kotlin/blackjack/model/DealerResult.kt index cdc82fe1fe..37848cee10 100644 --- a/src/main/kotlin/blackjack/model/Result.kt +++ b/src/main/kotlin/blackjack/model/DealerResult.kt @@ -1,6 +1,6 @@ package blackjack.model -data class Result( +data class DealerResult( val point: Int, val winning: Int, val losing: Int, diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/ParticipantResults.kt index a0529846d4..1d9e295815 100644 --- a/src/main/kotlin/blackjack/model/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/ParticipantResults.kt @@ -1,14 +1,31 @@ package blackjack.model class ParticipantResults( - val playerResults: Set>, - val dealerResult: Pair, + val playerResults: Set>, + val dealerDealerResult: Pair, ) { - fun dealerResult(): Result { - return dealerResult.second + fun dealerResult(): DealerResult { + return dealerDealerResult.second } - fun findPlayerResult(player: Player): Result { + fun findPlayerResult(player: Player): DealerResult { TODO() } + + companion object { + fun ofDealerLose(participants: Participants): ParticipantResults { + return ParticipantResults( + participants.players.map { this.playerWin(it, participants) }.toSet(), + participants.dealer to DealerResult(participants.dealer.score(), 0, participants.count() - 1) + ) + } + + private fun playerWin(player: Player, participants: Participants): Pair { + return player to PlayerResult.WIN + } + + fun of(participants: Participants) { + ParticipantResults + } + } } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index b8f6e73526..fb8eaaa991 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -6,6 +6,9 @@ class Participants( val players: Set, val dealer: Dealer, ) { + init { + require(players.map { it.name }.distinct().size == players.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } + } fun dealing(pack: Pack) { players.forEach { it.deal(pack) } @@ -13,10 +16,14 @@ class Participants( } private fun isGameOver(): Boolean { - return players.none { Referee.isBlackJack(it) } + return (players.any { Referee.isGameOver(it) }) || Referee.isGameOver(dealer) } fun isContinue(): Boolean { return !isGameOver() } + + fun count(): Int { + return players.size + 1 + } } diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt new file mode 100644 index 0000000000..62c38408e7 --- /dev/null +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -0,0 +1,5 @@ +package blackjack.model + +interface Playable { + fun score(): Int +} diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 23f4c92504..4966575c39 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -2,10 +2,10 @@ package blackjack.model import blackjack.model.pack.Pack -data class Player( +class Player( val name: String, val cards: Cards = Cards.emptyCards(), -) { +) : Playable { fun deal(pack: Pack) { cards.add(pack.pickCard()) cards.add(pack.pickCard()) @@ -14,4 +14,8 @@ data class Player( fun hit(pack: Pack) { cards.add(pack.pickCard()) } + + override fun score(): Int { + return this.cards.totalScore() + } } diff --git a/src/main/kotlin/blackjack/model/PlayerResult.kt b/src/main/kotlin/blackjack/model/PlayerResult.kt new file mode 100644 index 0000000000..2d93745f43 --- /dev/null +++ b/src/main/kotlin/blackjack/model/PlayerResult.kt @@ -0,0 +1,6 @@ +package blackjack.model + +enum class PlayerResult { + WIN, + LOSE, +} diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index c707b806f3..08f2f83e3f 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -1,12 +1,34 @@ package blackjack.model object Referee { + private const val BLACK_JACK_SCORE: Int = 21 - fun isBlackJack(it: Player): Boolean { - return it.cards.totalScore() == BLACK_JACK_SCORE + + fun isGameOver(playable: Playable): Boolean { + return playable.score() >= BLACK_JACK_SCORE } + fun blackJackResult(participants: Participants): ParticipantResults { + if (isBlackJackScoreOver(participants.dealer)) { + // 1) 딜러가 21을 넘어 모든 플레이어가 승리한 상황 + ParticipantResults.ofDealerLose(participants) + } + if (isWinDealer()) { + // 2) 딜러가 승리한 상황 + //return ParticipantResults + TODO("딜러가 이긴상황") + } + // 3) 플레이어중 하나가 승리하고, 딜러가 패배한 상황 + TODO("플레이어가 이긴상황") + //return ParticipantResults.of(participants) + } + + private fun isWinDealer(): Boolean { TODO("Not yet implemented") } + + private fun isBlackJackScoreOver(dealer: Dealer): Boolean { + return dealer.score() > BLACK_JACK_SCORE + } } diff --git a/src/test/kotlin/blackjack/model/ParticipantsTest.kt b/src/test/kotlin/blackjack/model/ParticipantsTest.kt new file mode 100644 index 0000000000..ee07f8b2d1 --- /dev/null +++ b/src/test/kotlin/blackjack/model/ParticipantsTest.kt @@ -0,0 +1,11 @@ +package blackjack.model + +import io.kotest.core.spec.style.StringSpec + +class ParticipantsTest : StringSpec({ + + "플레이어들의 이름은 중복되지 않아야 한다" { + TODO() + } + +}) diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index 2d2bcdb71e..ce30622578 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -16,7 +16,7 @@ class RefereeTest : StringSpec({ ) ) ) - Referee.isBlackJack(player) shouldBe false + Referee.isGameOver(player) shouldBe false } "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭으로 계산 되어야 한다" { @@ -29,7 +29,7 @@ class RefereeTest : StringSpec({ ) ) ) - Referee.isBlackJack(player) shouldBe true + Referee.isGameOver(player) shouldBe true } "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { From 200875381979565a4b15bbd4c4741e6e2c23b2f2 Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 22 Nov 2023 22:28:30 +0900 Subject: [PATCH 16/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/ParticipantResults.kt | 11 ++++------- src/test/kotlin/blackjack/model/RefereeTest.kt | 9 ++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/ParticipantResults.kt index 1d9e295815..e644595a20 100644 --- a/src/main/kotlin/blackjack/model/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/ParticipantResults.kt @@ -1,21 +1,21 @@ package blackjack.model class ParticipantResults( - val playerResults: Set>, + val playerResults: Map, val dealerDealerResult: Pair, ) { fun dealerResult(): DealerResult { return dealerDealerResult.second } - fun findPlayerResult(player: Player): DealerResult { - TODO() + fun playerResult(player: Player): PlayerResult { + return requireNotNull(playerResults[player]) {"플레이어를 찾을 수 없음"} } companion object { fun ofDealerLose(participants: Participants): ParticipantResults { return ParticipantResults( - participants.players.map { this.playerWin(it, participants) }.toSet(), + participants.players.associate { this.playerWin(it, participants) }, participants.dealer to DealerResult(participants.dealer.score(), 0, participants.count() - 1) ) } @@ -24,8 +24,5 @@ class ParticipantResults( return player to PlayerResult.WIN } - fun of(participants: Participants) { - ParticipantResults - } } } diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index ce30622578..d65e5b286f 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -67,12 +67,7 @@ class RefereeTest : StringSpec({ actual.dealerResult().winning shouldBe 0 actual.dealerResult().losing shouldBe 2 - actual.findPlayerResult(player1).point shouldBe 21 - actual.findPlayerResult(player1).winning shouldBe 1 - actual.findPlayerResult(player1).losing shouldBe 0 - - actual.findPlayerResult(player2).point shouldBe 20 - actual.findPlayerResult(player2).winning shouldBe 1 - actual.findPlayerResult(player2).losing shouldBe 0 + actual.playerResult(player1) shouldBe PlayerResult.WIN + actual.playerResult(player2) shouldBe PlayerResult.WIN } }) From 0cf2ee0fa4f8e540239a1f0801a8fc49fc680c6c Mon Sep 17 00:00:00 2001 From: dong Date: Thu, 23 Nov 2023 09:46:12 +0900 Subject: [PATCH 17/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++ src/main/kotlin/blackjack/Controller.kt | 2 +- src/main/kotlin/blackjack/model/Dealer.kt | 20 ++++----- .../kotlin/blackjack/model/DealerResult.kt | 1 + .../blackjack/model/ParticipantResults.kt | 13 ++---- .../kotlin/blackjack/model/Participants.kt | 13 +++--- src/main/kotlin/blackjack/model/Playable.kt | 3 ++ src/main/kotlin/blackjack/model/Player.kt | 9 ++++ .../kotlin/blackjack/model/PlayerResult.kt | 1 + src/main/kotlin/blackjack/model/Players.kt | 33 ++++++++++++++ .../kotlin/blackjack/model/PlayersResults.kt | 21 +++++++++ src/main/kotlin/blackjack/model/Referee.kt | 45 ++++++++++++++----- src/main/kotlin/blackjack/view/InputView.kt | 11 +++-- src/main/kotlin/blackjack/view/OutputView.kt | 6 +-- src/test/kotlin/blackjack/model/DealerTest.kt | 4 +- .../blackjack/model/ParticipantsTest.kt | 1 - .../kotlin/blackjack/model/RefereeTest.kt | 2 +- 17 files changed, 138 insertions(+), 50 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/Players.kt create mode 100644 src/main/kotlin/blackjack/model/PlayersResults.kt diff --git a/README.md b/README.md index 0262ac73ec..946365e5c6 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,6 @@ Player.hit() : 블랙잭에서 카드를 받는 행동은 "히트" 딜러가 - 게임을 완료한 후 각 플레이어별로 승패를 출력 ``` + + +walkover - 부전승, 낙승 : 상대방(딜러의 몰수패로 이기는) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 7d363fcfd1..00281717fa 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -18,7 +18,7 @@ fun main() { } fun playingBlackJack(participants: Participants) { - participants.players.forEach { + participants.players.values.forEach { it.hitOrStand() } } diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index abf16b204f..ad39f2a121 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -6,12 +6,6 @@ class Dealer( val cards: Cards = Cards(), ) : Playable { - fun play(pack: Pack) { - if (isDealerHit()) { - cards.add(pack.pickCard()) - } - } - private fun isDealerHit(): Boolean { return cards.totalScore() <= DEALER_PICK_THRESHOLD } @@ -20,11 +14,17 @@ class Dealer( return cards.count() } - companion object { - private const val DEALER_PICK_THRESHOLD = 16 - } - override fun score(): Int { return cards.totalScore() } + + override fun playing(pack: Pack) { + if (isDealerHit()) { + cards.add(pack.pickCard()) + } + } + + companion object { + private const val DEALER_PICK_THRESHOLD = 16 + } } diff --git a/src/main/kotlin/blackjack/model/DealerResult.kt b/src/main/kotlin/blackjack/model/DealerResult.kt index 37848cee10..352455eeca 100644 --- a/src/main/kotlin/blackjack/model/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/DealerResult.kt @@ -3,5 +3,6 @@ package blackjack.model data class DealerResult( val point: Int, val winning: Int, + val drawing: Int, val losing: Int, ) diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/ParticipantResults.kt index e644595a20..86c5da7895 100644 --- a/src/main/kotlin/blackjack/model/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/ParticipantResults.kt @@ -1,7 +1,7 @@ package blackjack.model class ParticipantResults( - val playerResults: Map, + val playerResults: PlayersResults, val dealerDealerResult: Pair, ) { fun dealerResult(): DealerResult { @@ -9,20 +9,15 @@ class ParticipantResults( } fun playerResult(player: Player): PlayerResult { - return requireNotNull(playerResults[player]) {"플레이어를 찾을 수 없음"} + return playerResults.resultOfPlayer(player) } companion object { fun ofDealerLose(participants: Participants): ParticipantResults { return ParticipantResults( - participants.players.associate { this.playerWin(it, participants) }, - participants.dealer to DealerResult(participants.dealer.score(), 0, participants.count() - 1) + PlayersResults(participants.players.walkover()), + participants.dealer to DealerResult(participants.dealer.score(), 0, 0, participants.count() - 1) ) } - - private fun playerWin(player: Player, participants: Participants): Pair { - return player to PlayerResult.WIN - } - } } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index fb8eaaa991..e5297254c5 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -3,20 +3,17 @@ package blackjack.model import blackjack.model.pack.Pack class Participants( - val players: Set, + val players: Players, val dealer: Dealer, ) { - init { - require(players.map { it.name }.distinct().size == players.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } - } fun dealing(pack: Pack) { - players.forEach { it.deal(pack) } - dealer.play(pack) + players.deal(pack) + dealer.playing(pack) } private fun isGameOver(): Boolean { - return (players.any { Referee.isGameOver(it) }) || Referee.isGameOver(dealer) + return players.isGameOver() || Referee.isGameOver(dealer) } fun isContinue(): Boolean { @@ -24,6 +21,6 @@ class Participants( } fun count(): Int { - return players.size + 1 + return players.count() + 1 } } diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt index 62c38408e7..dc174cc3f5 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -1,5 +1,8 @@ package blackjack.model +import blackjack.model.pack.Pack + interface Playable { fun score(): Int + fun playing(pack: Pack) } diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 4966575c39..15ebc83db4 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -1,6 +1,8 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.view.InputView +import blackjack.view.OutputView class Player( val name: String, @@ -18,4 +20,11 @@ class Player( override fun score(): Int { return this.cards.totalScore() } + + override fun playing(pack: Pack) { + if (InputView.askHit(this)) { + this.hit(pack) + } + OutputView.playerCardPresent(this) + } } diff --git a/src/main/kotlin/blackjack/model/PlayerResult.kt b/src/main/kotlin/blackjack/model/PlayerResult.kt index 2d93745f43..567d418c1e 100644 --- a/src/main/kotlin/blackjack/model/PlayerResult.kt +++ b/src/main/kotlin/blackjack/model/PlayerResult.kt @@ -3,4 +3,5 @@ package blackjack.model enum class PlayerResult { WIN, LOSE, + DRAW, } diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt new file mode 100644 index 0000000000..da7f5de45e --- /dev/null +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -0,0 +1,33 @@ +package blackjack.model + +import blackjack.model.pack.Pack + +class Players( + val values: Set, +) { + constructor(vararg players: Player) : this(players.toSet()) + + fun deal(pack: Pack) { + values.forEach { it.deal(pack) } + } + + fun isGameOver(): Boolean { + return values.any { Referee.isGameOver(it) } + } + + fun count(): Int { + return values.size + } + + fun scoreBattle(dealerScore: Int): Map { + return values.associateWith { Referee.playerResult(it, dealerScore) } + } + + fun walkover(): Map { + return values.associateWith { PlayerResult.WIN } + } + + init { + require(values.map { it.name }.distinct().size == values.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } + } +} diff --git a/src/main/kotlin/blackjack/model/PlayersResults.kt b/src/main/kotlin/blackjack/model/PlayersResults.kt new file mode 100644 index 0000000000..dce4bb9ac5 --- /dev/null +++ b/src/main/kotlin/blackjack/model/PlayersResults.kt @@ -0,0 +1,21 @@ +package blackjack.model + +class PlayersResults( + private val value: Map, +) { + fun loseCount(): Int { + return value.values.count { it == PlayerResult.LOSE } + } + + fun winningCount(): Int { + return value.values.count { it == PlayerResult.WIN } + } + + fun drawingCount(): Int { + return value.values.count { it == PlayerResult.DRAW } + } + + fun resultOfPlayer(player: Player): PlayerResult { + return requireNotNull(value[player]) { "플레이어를 찾을 수 없음" } + } +} diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index 08f2f83e3f..f5dcd4431f 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -8,27 +8,50 @@ object Referee { return playable.score() >= BLACK_JACK_SCORE } - fun blackJackResult(participants: Participants): ParticipantResults { if (isBlackJackScoreOver(participants.dealer)) { // 1) 딜러가 21을 넘어 모든 플레이어가 승리한 상황 - ParticipantResults.ofDealerLose(participants) - } - if (isWinDealer()) { - // 2) 딜러가 승리한 상황 - //return ParticipantResults - TODO("딜러가 이긴상황") + return ParticipantResults.ofDealerLose(participants) } + val playerResults = getPlayerResults(participants) + return ParticipantResults( + playerResults = playerResults, + dealerDealerResult = getDealerResult(participants, playerResults) + ) + // 2) 딜러가 승리한 상황 // 3) 플레이어중 하나가 승리하고, 딜러가 패배한 상황 - TODO("플레이어가 이긴상황") - //return ParticipantResults.of(participants) + // 4) 플러이어중 하나 승리, 하나 비긴, 하나 패배 딜러 + } + + private fun getDealerResult( + participants: Participants, + playerResults: PlayersResults + ): Pair { + val dealerScore = participants.dealer.score() + return participants.dealer to DealerResult( + dealerScore, + playerResults.winningCount(), + playerResults.drawingCount(), + playerResults.loseCount() + ) } - private fun isWinDealer(): Boolean { - TODO("Not yet implemented") + private fun getPlayerResults(participants: Participants): PlayersResults { + val dealerScore = participants.dealer.score() + return PlayersResults(participants.players.scoreBattle(dealerScore)) } private fun isBlackJackScoreOver(dealer: Dealer): Boolean { return dealer.score() > BLACK_JACK_SCORE } + + fun playerResult(player: Player, dealerScore: Int): PlayerResult { + if (player.score() == dealerScore) { + return PlayerResult.DRAW + } + if (player.score() > dealerScore) { + return PlayerResult.WIN + } + return PlayerResult.LOSE + } } diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 490cfdfa37..d3cc8e16a3 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -3,6 +3,7 @@ package blackjack.view import blackjack.model.Dealer import blackjack.model.Participants import blackjack.model.Player +import blackjack.model.Players object InputView { private const val PLAYER_NAMES_DELIMITER: String = "," @@ -11,10 +12,12 @@ object InputView { private fun joinPlayers(input: String): Participants { return Participants( - input.split(PLAYER_NAMES_DELIMITER) - .asSequence() - .map { Player(it) } - .toSet(), + Players( + input.split(PLAYER_NAMES_DELIMITER) + .asSequence() + .map { Player(it) } + .toSet() + ), Dealer() ) } diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 14a45d4037..6cee35e5bd 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -29,13 +29,13 @@ object OutputView { } private fun Participants.present(): String { - return this.players.joinToString(separator = "\n") { it.present() } + return this.players.values.joinToString(separator = "\n") { it.present() } } private fun Participants.presentWithScore(): String { - return this.players.joinToString(separator = "\n") { "${it.present()} - 결과: ${it.cards.totalScore()}" } + return this.players.values.joinToString(separator = "\n") { "${it.present()} - 결과: ${it.cards.totalScore()}" } } private fun Participants.names(): String { - return players.joinToString(separator = InputView.PARTICIPANTS_PRESENT_SEPARATOR) { it.name } + return players.values.joinToString(separator = InputView.PARTICIPANTS_PRESENT_SEPARATOR) { it.name } } diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index 37cd1cc16c..deb669aadb 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -15,7 +15,7 @@ class DealerTest : StringSpec({ ) ) ) - dealer.play(ShuffledPack) + dealer.playing(ShuffledPack) dealer.countOfCards() shouldBe 3 } @@ -28,7 +28,7 @@ class DealerTest : StringSpec({ ) ) ) - dealer.play(ShuffledPack) + dealer.playing(ShuffledPack) dealer.countOfCards() shouldBe 2 } }) diff --git a/src/test/kotlin/blackjack/model/ParticipantsTest.kt b/src/test/kotlin/blackjack/model/ParticipantsTest.kt index ee07f8b2d1..62d7ac14e9 100644 --- a/src/test/kotlin/blackjack/model/ParticipantsTest.kt +++ b/src/test/kotlin/blackjack/model/ParticipantsTest.kt @@ -7,5 +7,4 @@ class ParticipantsTest : StringSpec({ "플레이어들의 이름은 중복되지 않아야 한다" { TODO() } - }) diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index d65e5b286f..414d72078b 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -60,7 +60,7 @@ class RefereeTest : StringSpec({ ) ) ) - val participants = Participants(setOf(player1, player2), dealer) + val participants = Participants(Players(player1, player2), dealer) val actual = Referee.blackJackResult(participants) actual.dealerResult().point shouldBe 22 From d5d036d0ab934d4d3a447fa544298ecf8d8463cf Mon Sep 17 00:00:00 2001 From: dong Date: Thu, 23 Nov 2023 17:50:16 +0900 Subject: [PATCH 18/81] =?UTF-8?q?test=20:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=B1=85=EC=9E=84=EC=86=8C=EC=9E=AC=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=EC=8B=9C=ED=82=A8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/model/ParticipantsTest.kt | 10 ---------- .../kotlin/blackjack/model/PlayersTest.kt | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) delete mode 100644 src/test/kotlin/blackjack/model/ParticipantsTest.kt create mode 100644 src/test/kotlin/blackjack/model/PlayersTest.kt diff --git a/src/test/kotlin/blackjack/model/ParticipantsTest.kt b/src/test/kotlin/blackjack/model/ParticipantsTest.kt deleted file mode 100644 index 62d7ac14e9..0000000000 --- a/src/test/kotlin/blackjack/model/ParticipantsTest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package blackjack.model - -import io.kotest.core.spec.style.StringSpec - -class ParticipantsTest : StringSpec({ - - "플레이어들의 이름은 중복되지 않아야 한다" { - TODO() - } -}) diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt new file mode 100644 index 0000000000..5d1144d748 --- /dev/null +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -0,0 +1,20 @@ +package blackjack.model + +import io.kotest.assertions.throwables.shouldNotThrow +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.StringSpec + +class PlayersTest : StringSpec({ + + "플레이어들의 이름은 중복을 허용하지 않는다. 중복시 throw IllegalArgumentException" { + shouldThrow { + Players(Player("hana"), Player("hana")) + } + } + + "플레이어들의 이름이 중복되지 않으면 정상 동작 해야한다" { + shouldNotThrow { + Players(Player("hana"), Player("numa")) + } + } +}) From e1a92a3790921529df6e7a1b19920d419a281827 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 06:39:05 +0900 Subject: [PATCH 19/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 8 +++- src/main/kotlin/blackjack/model/Dealer.kt | 4 +- .../blackjack/model/ParticipantResults.kt | 8 ++++ src/main/kotlin/blackjack/model/Playable.kt | 3 -- src/main/kotlin/blackjack/model/Player.kt | 2 +- src/main/kotlin/blackjack/view/Console.kt | 11 +++-- src/main/kotlin/blackjack/view/OutputView.kt | 42 ++++++++++++++----- 7 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 00281717fa..035b6f2f54 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -2,6 +2,7 @@ package blackjack import blackjack.model.Participants import blackjack.model.Player +import blackjack.model.Referee import blackjack.model.pack.ShuffledPack import blackjack.view.InputView import blackjack.view.OutputView @@ -14,13 +15,18 @@ fun main() { while (participants.isContinue()) { playingBlackJack(participants) } - OutputView.result(participants) + OutputView.presentScores(participants) + OutputView.presentResult(Referee.blackJackResult(participants)) } fun playingBlackJack(participants: Participants) { participants.players.values.forEach { it.hitOrStand() } + when (participants.dealer.playing(ShuffledPack)) { + true -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") + false -> println("딜러는 17이상이라 카드를 받지 않았습니다.") + } } private fun Player.hitOrStand() { diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index ad39f2a121..27f3a82d48 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -18,10 +18,12 @@ class Dealer( return cards.totalScore() } - override fun playing(pack: Pack) { + fun playing(pack: Pack): Boolean { if (isDealerHit()) { cards.add(pack.pickCard()) + return true } + return false } companion object { diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/ParticipantResults.kt index 86c5da7895..6b64637a90 100644 --- a/src/main/kotlin/blackjack/model/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/ParticipantResults.kt @@ -12,6 +12,14 @@ class ParticipantResults( return playerResults.resultOfPlayer(player) } + fun dealerWinCount(): Int { + return this.dealerDealerResult.second.winning + } + + fun dealerLoseCount(): Int { + return this.dealerDealerResult.second.losing + } + companion object { fun ofDealerLose(participants: Participants): ParticipantResults { return ParticipantResults( diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt index dc174cc3f5..62c38408e7 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -1,8 +1,5 @@ package blackjack.model -import blackjack.model.pack.Pack - interface Playable { fun score(): Int - fun playing(pack: Pack) } diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 15ebc83db4..52a6d121f6 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -21,7 +21,7 @@ class Player( return this.cards.totalScore() } - override fun playing(pack: Pack) { + fun playing(pack: Pack) { if (InputView.askHit(this)) { this.hit(pack) } diff --git a/src/main/kotlin/blackjack/view/Console.kt b/src/main/kotlin/blackjack/view/Console.kt index a57cba1bfe..1ed90fbc55 100644 --- a/src/main/kotlin/blackjack/view/Console.kt +++ b/src/main/kotlin/blackjack/view/Console.kt @@ -1,15 +1,20 @@ package blackjack.view import blackjack.model.Cards +import blackjack.model.Dealer import blackjack.model.Player object Console { - fun Cards.present(): String { + fun Cards.presentPlayers(): String { return cards.joinToString(separator = ", ") { "${it.cardRank.alias}${it.suit.alias}" } } - fun Player.present(): String { - return "${this.name}카드 : ${this.cards.present()}" + fun Player.presentPlayers(): String { + return "${this.name}카드 : ${this.cards.presentPlayers()}" + } + + fun Dealer.presentDealers(): String { + return "딜러 카드 : ${this.cards.presentPlayers()}" } } diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 6cee35e5bd..4353c5783e 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,39 +1,59 @@ package blackjack.view +import blackjack.model.ParticipantResults import blackjack.model.Participants import blackjack.model.Player -import blackjack.view.Console.present +import blackjack.view.Console.presentDealers +import blackjack.view.Console.presentPlayers object OutputView { fun presentCards(participants: Participants) { - println(participants.present()) + println(participants.presentDealer()) + println(participants.presentPlayers()) } - fun result(participants: Participants) { + fun presentScores(participants: Participants) { presentCardsWitScore(participants) } private fun presentCardsWitScore(participants: Participants) { - println() - println(participants.presentWithScore()) + print(System.lineSeparator()) + println(participants.presentDealerWithScore()) + println(participants.presentPlayerWithScore()) } fun dealing(participants: Participants) { - println("${participants.names()} 에게 2 장씩 나누었습니다.") + println("딜러와 ${participants.names()} 에게 2 장씩 나누었습니다.") } fun playerCardPresent(it: Player) { - println(it.present()) + println(it.presentPlayers()) } + + fun presentResult(blackJackResult: ParticipantResults) { + println("## 최종 승패") + println("딜러 ${blackJackResult.dealerWinCount()}승 ${blackJackResult.dealerLoseCount()}패") + blackJackResult.playerResults + .playerResult() + .forEach { println("${it.first}: ${it.second}") } + } +} + +private fun Participants.presentPlayers(): String { + return this.players.values.joinToString(separator = "\n") { it.presentPlayers() } +} + +private fun Participants.presentDealer(): String { + return this.dealer.presentDealers() } -private fun Participants.present(): String { - return this.players.values.joinToString(separator = "\n") { it.present() } +private fun Participants.presentDealerWithScore(): String { + return "${this.dealer.presentDealers()} - 결과: ${this.dealer.score()}" } -private fun Participants.presentWithScore(): String { - return this.players.values.joinToString(separator = "\n") { "${it.present()} - 결과: ${it.cards.totalScore()}" } +private fun Participants.presentPlayerWithScore(): String { + return this.players.values.joinToString(separator = "\n") { "${it.presentPlayers()} - 결과: ${it.cards.totalScore()}" } } private fun Participants.names(): String { From fd08d2e4eaca2d3918022ea528a7c761ce645cf5 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 06:39:17 +0900 Subject: [PATCH 20/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/PlayersResults.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/blackjack/model/PlayersResults.kt b/src/main/kotlin/blackjack/model/PlayersResults.kt index dce4bb9ac5..501b394758 100644 --- a/src/main/kotlin/blackjack/model/PlayersResults.kt +++ b/src/main/kotlin/blackjack/model/PlayersResults.kt @@ -18,4 +18,12 @@ class PlayersResults( fun resultOfPlayer(player: Player): PlayerResult { return requireNotNull(value[player]) { "플레이어를 찾을 수 없음" } } + + fun playerResult(): List> { + return value.keys.map { playerNameAndResult(it) }.toList() + } + + private fun playerNameAndResult(it: Player): Pair { + return it.name to requireNotNull(value[it]) { "플레이어 ${it.name} 을 찾을 수 없습니다" } + } } From 72c2a9fd8e22d36d47caf3759b146cce8391f779 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 06:42:44 +0900 Subject: [PATCH 21/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=EC=99=80=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EA=B0=84=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20=EB=8F=99=EC=9E=91=EC=9D=84=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EB=AC=B6=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 12 +++++++++--- src/main/kotlin/blackjack/model/Playable.kt | 3 +++ src/main/kotlin/blackjack/model/Player.kt | 16 +++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 27f3a82d48..c3d08ada47 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -6,6 +6,15 @@ class Dealer( val cards: Cards = Cards(), ) : Playable { + override fun score(): Int { + return cards.totalScore() + } + + override fun dealing(pack: Pack) { + this.cards.add(pack.pickCard()) + this.cards.add(pack.pickCard()) + } + private fun isDealerHit(): Boolean { return cards.totalScore() <= DEALER_PICK_THRESHOLD } @@ -14,9 +23,6 @@ class Dealer( return cards.count() } - override fun score(): Int { - return cards.totalScore() - } fun playing(pack: Pack): Boolean { if (isDealerHit()) { diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt index 62c38408e7..da8026127a 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -1,5 +1,8 @@ package blackjack.model +import blackjack.model.pack.Pack + interface Playable { fun score(): Int + fun dealing(pack:Pack) } diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 52a6d121f6..9919ca42fe 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -1,14 +1,12 @@ package blackjack.model import blackjack.model.pack.Pack -import blackjack.view.InputView -import blackjack.view.OutputView class Player( val name: String, val cards: Cards = Cards.emptyCards(), ) : Playable { - fun deal(pack: Pack) { + override fun dealing(pack: Pack) { cards.add(pack.pickCard()) cards.add(pack.pickCard()) } @@ -21,10 +19,10 @@ class Player( return this.cards.totalScore() } - fun playing(pack: Pack) { - if (InputView.askHit(this)) { - this.hit(pack) - } - OutputView.playerCardPresent(this) - } +// fun playing(pack: Pack) { +// if (InputView.askHit(this)) { +// this.hit(pack) +// } +// OutputView.playerCardPresent(this) +// } } From 405c44e3da216ee8455f030105905d4be4dee561 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 06:44:40 +0900 Subject: [PATCH 22/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=EC=99=80=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EA=B0=84=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20=EB=8F=99=EC=9E=91=EC=9D=84=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EB=AC=B6=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 1 - src/main/kotlin/blackjack/model/Participants.kt | 4 ++-- src/main/kotlin/blackjack/model/Playable.kt | 2 +- src/main/kotlin/blackjack/model/Players.kt | 4 ++-- src/test/kotlin/blackjack/model/PlayerTest.kt | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index c3d08ada47..46e350643a 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -23,7 +23,6 @@ class Dealer( return cards.count() } - fun playing(pack: Pack): Boolean { if (isDealerHit()) { cards.add(pack.pickCard()) diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index e5297254c5..9d69443d26 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -8,8 +8,8 @@ class Participants( ) { fun dealing(pack: Pack) { - players.deal(pack) - dealer.playing(pack) + players.dealing(pack) + dealer.dealing(pack) } private fun isGameOver(): Boolean { diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt index da8026127a..f4a0d45855 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -4,5 +4,5 @@ import blackjack.model.pack.Pack interface Playable { fun score(): Int - fun dealing(pack:Pack) + fun dealing(pack: Pack) } diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index da7f5de45e..f7d60231f8 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -7,8 +7,8 @@ class Players( ) { constructor(vararg players: Player) : this(players.toSet()) - fun deal(pack: Pack) { - values.forEach { it.deal(pack) } + fun dealing(pack: Pack) { + values.forEach { it.dealing(pack) } } fun isGameOver(): Boolean { diff --git a/src/test/kotlin/blackjack/model/PlayerTest.kt b/src/test/kotlin/blackjack/model/PlayerTest.kt index 64fd69304b..081d0c43ee 100644 --- a/src/test/kotlin/blackjack/model/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/PlayerTest.kt @@ -9,7 +9,7 @@ class PlayerTest : StringSpec({ "플레이어는 dealing 시 2장의 카드를 받을 수 있다" { shouldNotThrow { val player = Player("구글") - player.deal(ShuffledPack) + player.dealing(ShuffledPack) player.cards.count() shouldBe 2 } } From 3fc2d982bba688ff3560c0aa2f6ab51cd57934e6 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 06:50:19 +0900 Subject: [PATCH 23/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=EC=99=80=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EA=B0=84=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20=EB=8F=99=EC=9E=91=EC=9D=B8=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EB=A5=BC=20=EC=9D=B8=ED=85=8C?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EC=B6=94=EC=83=81?= =?UTF-8?q?=ED=99=94=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Dealer.kt | 13 ++++++++++--- src/main/kotlin/blackjack/model/Playable.kt | 1 + src/main/kotlin/blackjack/model/PlayableReaction.kt | 6 ++++++ src/main/kotlin/blackjack/model/Player.kt | 4 ++++ src/main/kotlin/blackjack/model/PlayingStrategy.kt | 5 +++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/PlayableReaction.kt create mode 100644 src/main/kotlin/blackjack/model/PlayingStrategy.kt diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 46e350643a..4294073698 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -15,14 +15,19 @@ class Dealer( this.cards.add(pack.pickCard()) } - private fun isDealerHit(): Boolean { - return cards.totalScore() <= DEALER_PICK_THRESHOLD - } + fun countOfCards(): Int { return cards.count() } + override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { + TODO("Not yet implemented") + + } + private fun isDealerHit(): Boolean { + return cards.totalScore() <= DEALER_PICK_THRESHOLD + } fun playing(pack: Pack): Boolean { if (isDealerHit()) { cards.add(pack.pickCard()) @@ -30,6 +35,8 @@ class Dealer( } return false } + /// + companion object { private const val DEALER_PICK_THRESHOLD = 16 diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/Playable.kt index f4a0d45855..03a4935b91 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/Playable.kt @@ -5,4 +5,5 @@ import blackjack.model.pack.Pack interface Playable { fun score(): Int fun dealing(pack: Pack) + fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction } diff --git a/src/main/kotlin/blackjack/model/PlayableReaction.kt b/src/main/kotlin/blackjack/model/PlayableReaction.kt new file mode 100644 index 0000000000..4f496a26fb --- /dev/null +++ b/src/main/kotlin/blackjack/model/PlayableReaction.kt @@ -0,0 +1,6 @@ +package blackjack.model + +enum class PlayableReaction { + HIT, + STAND +} diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 9919ca42fe..9c3494b662 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -11,6 +11,10 @@ class Player( cards.add(pack.pickCard()) } + override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { + TODO("Not yet implemented") + } + fun hit(pack: Pack) { cards.add(pack.pickCard()) } diff --git a/src/main/kotlin/blackjack/model/PlayingStrategy.kt b/src/main/kotlin/blackjack/model/PlayingStrategy.kt new file mode 100644 index 0000000000..b8854dcbc5 --- /dev/null +++ b/src/main/kotlin/blackjack/model/PlayingStrategy.kt @@ -0,0 +1,5 @@ +package blackjack.model + +interface PlayingStrategy { + fun isHit(): Boolean +} From 118b83bc011a2317f53c39283246b8569698fcf4 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 07:25:10 +0900 Subject: [PATCH 24/81] =?UTF-8?q?feat=20:=20=EB=94=9C=EB=9F=AC=EC=99=80=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EC=9D=98=20=EB=B8=94?= =?UTF-8?q?=EB=9E=99=EC=A0=9D=20=ED=94=8C=EB=9E=98=EC=9D=B4=EC=9D=98=20?= =?UTF-8?q?=EC=A0=84=EB=9E=B5=EC=9D=84=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=ED=99=94=20=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 19 +++++++++++-------- src/main/kotlin/blackjack/model/Dealer.kt | 17 +++-------------- .../kotlin/blackjack/model/DealerStrategy.kt | 14 ++++++++++++++ src/main/kotlin/blackjack/model/Player.kt | 13 +++++-------- .../blackjack/model/playable/HitStrategy.kt | 9 +++++++++ .../blackjack/model/playable/StandStrategy.kt | 9 +++++++++ src/main/kotlin/blackjack/view/InputView.kt | 10 ++++++++-- 7 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/DealerStrategy.kt create mode 100644 src/main/kotlin/blackjack/model/playable/HitStrategy.kt create mode 100644 src/main/kotlin/blackjack/model/playable/StandStrategy.kt diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 035b6f2f54..453631c91c 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,6 +1,8 @@ package blackjack +import blackjack.model.DealerStrategy import blackjack.model.Participants +import blackjack.model.PlayableReaction import blackjack.model.Player import blackjack.model.Referee import blackjack.model.pack.ShuffledPack @@ -21,17 +23,18 @@ fun main() { fun playingBlackJack(participants: Participants) { participants.players.values.forEach { - it.hitOrStand() + it.playing(InputView.askHit(it), ShuffledPack) } - when (participants.dealer.playing(ShuffledPack)) { - true -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") - false -> println("딜러는 17이상이라 카드를 받지 않았습니다.") + when (participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack)) { + PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") + PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") } } private fun Player.hitOrStand() { - if (InputView.askHit(this)) { - this.hit(ShuffledPack) - } - OutputView.playerCardPresent(this) + +// if () { +// this.hit(ShuffledPack) +// } +// OutputView.playerCardPresent(this) } diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/Dealer.kt index 4294073698..10eea15702 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/Dealer.kt @@ -15,28 +15,17 @@ class Dealer( this.cards.add(pack.pickCard()) } - - fun countOfCards(): Int { return cards.count() } override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { - TODO("Not yet implemented") - - } - private fun isDealerHit(): Boolean { - return cards.totalScore() <= DEALER_PICK_THRESHOLD - } - fun playing(pack: Pack): Boolean { - if (isDealerHit()) { + if (playingStrategy.isHit()) { cards.add(pack.pickCard()) - return true + return PlayableReaction.HIT } - return false + return PlayableReaction.STAND } - /// - companion object { private const val DEALER_PICK_THRESHOLD = 16 diff --git a/src/main/kotlin/blackjack/model/DealerStrategy.kt b/src/main/kotlin/blackjack/model/DealerStrategy.kt new file mode 100644 index 0000000000..11d8ae0a79 --- /dev/null +++ b/src/main/kotlin/blackjack/model/DealerStrategy.kt @@ -0,0 +1,14 @@ +package blackjack.model + +class DealerStrategy( + private val currentScore: Int, +) : PlayingStrategy { + + override fun isHit(): Boolean { + return currentScore <= DEALER_PICK_THRESHOLD + } + + companion object { + private const val DEALER_PICK_THRESHOLD = 16 + } +} diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/Player.kt index 9c3494b662..8c18e76c66 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/Player.kt @@ -12,7 +12,11 @@ class Player( } override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { - TODO("Not yet implemented") + if (playingStrategy.isHit()) { + this.hit(pack) + return PlayableReaction.HIT + } + return PlayableReaction.STAND } fun hit(pack: Pack) { @@ -22,11 +26,4 @@ class Player( override fun score(): Int { return this.cards.totalScore() } - -// fun playing(pack: Pack) { -// if (InputView.askHit(this)) { -// this.hit(pack) -// } -// OutputView.playerCardPresent(this) -// } } diff --git a/src/main/kotlin/blackjack/model/playable/HitStrategy.kt b/src/main/kotlin/blackjack/model/playable/HitStrategy.kt new file mode 100644 index 0000000000..15b0ffefdc --- /dev/null +++ b/src/main/kotlin/blackjack/model/playable/HitStrategy.kt @@ -0,0 +1,9 @@ +package blackjack.model.playable + +import blackjack.model.PlayingStrategy + +object HitStrategy : PlayingStrategy { + override fun isHit(): Boolean { + return true + } +} diff --git a/src/main/kotlin/blackjack/model/playable/StandStrategy.kt b/src/main/kotlin/blackjack/model/playable/StandStrategy.kt new file mode 100644 index 0000000000..924a1bf04b --- /dev/null +++ b/src/main/kotlin/blackjack/model/playable/StandStrategy.kt @@ -0,0 +1,9 @@ +package blackjack.model.playable + +import blackjack.model.PlayingStrategy + +object StandStrategy : PlayingStrategy { + override fun isHit(): Boolean { + return false + } +} diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index d3cc8e16a3..39e324a5e3 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -4,6 +4,9 @@ import blackjack.model.Dealer import blackjack.model.Participants import blackjack.model.Player import blackjack.model.Players +import blackjack.model.PlayingStrategy +import blackjack.model.playable.HitStrategy +import blackjack.model.playable.StandStrategy object InputView { private const val PLAYER_NAMES_DELIMITER: String = "," @@ -31,8 +34,11 @@ object InputView { return (readlnOrNull() ?: "") == HIT_COMMAND } - fun askHit(it: Player): Boolean { + fun askHit(it: Player): PlayingStrategy { println("${it.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") - return this.isHitInput() + if (this.isHitInput()) { + return HitStrategy + } + return StandStrategy } } From bc99f479ac7d70cde50c5244fb2e4b2fe24ac43f Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 07:26:33 +0900 Subject: [PATCH 25/81] =?UTF-8?q?feat=20:=20=EA=B9=A8=EC=A7=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/model/DealerTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index deb669aadb..9bede95b5b 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -15,7 +15,7 @@ class DealerTest : StringSpec({ ) ) ) - dealer.playing(ShuffledPack) + dealer.playing(DealerStrategy(16), ShuffledPack) dealer.countOfCards() shouldBe 3 } @@ -28,7 +28,7 @@ class DealerTest : StringSpec({ ) ) ) - dealer.playing(ShuffledPack) + dealer.playing(DealerStrategy(17), ShuffledPack) dealer.countOfCards() shouldBe 2 } }) From 0e3a932155ab68aeb5dfa0e6abd74124af0816b3 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 14:50:15 +0900 Subject: [PATCH 26/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 6 +++--- src/main/kotlin/blackjack/model/Participants.kt | 1 + src/main/kotlin/blackjack/model/Players.kt | 2 ++ src/main/kotlin/blackjack/model/Referee.kt | 8 ++++++++ src/main/kotlin/blackjack/model/Suit.kt | 12 ------------ src/main/kotlin/blackjack/model/{ => card}/Card.kt | 4 ++-- .../kotlin/blackjack/model/{ => card}/CardRank.kt | 2 +- src/main/kotlin/blackjack/model/{ => card}/Cards.kt | 2 +- src/main/kotlin/blackjack/model/card/Suit.kt | 11 +++++++++++ src/main/kotlin/blackjack/model/{ => card}/Trump.kt | 2 +- src/main/kotlin/blackjack/model/pack/Pack.kt | 2 +- src/main/kotlin/blackjack/model/pack/ShuffledPack.kt | 6 +++--- .../blackjack/model/{ => playable}/Playable.kt | 3 ++- .../model/{ => playable}/PlayableReaction.kt | 2 +- .../blackjack/model/{ => playable/impl}/Dealer.kt | 6 +++++- .../blackjack/model/{ => playable/impl}/Player.kt | 6 +++++- .../model/{ => playblestrategy}/PlayingStrategy.kt | 2 +- .../{ => playblestrategy/impl}/DealerStrategy.kt | 4 +++- .../impl}/HitStrategy.kt | 4 ++-- .../impl}/StandStrategy.kt | 4 ++-- .../blackjack/model/{ => result}/DealerResult.kt | 2 +- .../model/{ => result}/ParticipantResults.kt | 6 +++++- .../blackjack/model/{ => result}/PlayerResult.kt | 2 +- .../blackjack/model/{ => result}/PlayersResults.kt | 4 +++- src/main/kotlin/blackjack/view/Console.kt | 6 +++--- src/main/kotlin/blackjack/view/InputView.kt | 10 +++++----- src/main/kotlin/blackjack/view/OutputView.kt | 4 ++-- src/test/kotlin/blackjack/model/CardsTest.kt | 4 ++++ src/test/kotlin/blackjack/model/DealerTest.kt | 6 ++++++ src/test/kotlin/blackjack/model/PlayerTest.kt | 1 + src/test/kotlin/blackjack/model/PlayersTest.kt | 1 + src/test/kotlin/blackjack/model/RefereeTest.kt | 7 +++++++ 32 files changed, 94 insertions(+), 48 deletions(-) delete mode 100644 src/main/kotlin/blackjack/model/Suit.kt rename src/main/kotlin/blackjack/model/{ => card}/Card.kt (71%) rename src/main/kotlin/blackjack/model/{ => card}/CardRank.kt (91%) rename src/main/kotlin/blackjack/model/{ => card}/Cards.kt (97%) create mode 100644 src/main/kotlin/blackjack/model/card/Suit.kt rename src/main/kotlin/blackjack/model/{ => card}/Trump.kt (70%) rename src/main/kotlin/blackjack/model/{ => playable}/Playable.kt (68%) rename src/main/kotlin/blackjack/model/{ => playable}/PlayableReaction.kt (61%) rename src/main/kotlin/blackjack/model/{ => playable/impl}/Dealer.kt (76%) rename src/main/kotlin/blackjack/model/{ => playable/impl}/Player.kt (74%) rename src/main/kotlin/blackjack/model/{ => playblestrategy}/PlayingStrategy.kt (58%) rename src/main/kotlin/blackjack/model/{ => playblestrategy/impl}/DealerStrategy.kt (72%) rename src/main/kotlin/blackjack/model/{playable => playblestrategy/impl}/HitStrategy.kt (51%) rename src/main/kotlin/blackjack/model/{playable => playblestrategy/impl}/StandStrategy.kt (51%) rename src/main/kotlin/blackjack/model/{ => result}/DealerResult.kt (78%) rename src/main/kotlin/blackjack/model/{ => result}/ParticipantResults.kt (84%) rename src/main/kotlin/blackjack/model/{ => result}/PlayerResult.kt (65%) rename src/main/kotlin/blackjack/model/{ => result}/PlayersResults.kt (91%) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 453631c91c..c38fdb7a0f 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,11 +1,11 @@ package blackjack -import blackjack.model.DealerStrategy import blackjack.model.Participants -import blackjack.model.PlayableReaction -import blackjack.model.Player import blackjack.model.Referee import blackjack.model.pack.ShuffledPack +import blackjack.model.playable.PlayableReaction +import blackjack.model.playable.impl.Player +import blackjack.model.playblestrategy.impl.DealerStrategy import blackjack.view.InputView import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 9d69443d26..4226eda197 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -1,6 +1,7 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.model.playable.impl.Dealer class Participants( val players: Players, diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index f7d60231f8..4f2480617b 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,6 +1,8 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.model.playable.impl.Player +import blackjack.model.result.PlayerResult class Players( val values: Set, diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index f5dcd4431f..fd65ecf16b 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -1,5 +1,13 @@ package blackjack.model +import blackjack.model.playable.Playable +import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.impl.Player +import blackjack.model.result.DealerResult +import blackjack.model.result.ParticipantResults +import blackjack.model.result.PlayerResult +import blackjack.model.result.PlayersResults + object Referee { private const val BLACK_JACK_SCORE: Int = 21 diff --git a/src/main/kotlin/blackjack/model/Suit.kt b/src/main/kotlin/blackjack/model/Suit.kt deleted file mode 100644 index a0e34e2069..0000000000 --- a/src/main/kotlin/blackjack/model/Suit.kt +++ /dev/null @@ -1,12 +0,0 @@ -package blackjack.model - -enum class Suit( - val code: String, - val alias: String, -) { - SPADE("♠", "스페이드"), - HEART("♥", "하트"), - DIAMOND("♦", "다이아"), - CLOVER("♣", "클로버"), - ; -} diff --git a/src/main/kotlin/blackjack/model/Card.kt b/src/main/kotlin/blackjack/model/card/Card.kt similarity index 71% rename from src/main/kotlin/blackjack/model/Card.kt rename to src/main/kotlin/blackjack/model/card/Card.kt index c9a81e6eab..7d17967bf9 100644 --- a/src/main/kotlin/blackjack/model/Card.kt +++ b/src/main/kotlin/blackjack/model/card/Card.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.card class Card private constructor( val suit: Suit, @@ -14,7 +14,7 @@ class Card private constructor( } fun of(suit: Suit, cardRank: CardRank): Card { - return requireNotNull(this.CARDS[Trump(suit to cardRank)]) { "입력된 suit=[$suit] , cardRank=[$cardRank] 는 찾을수 없습니다" } + return requireNotNull(CARDS[Trump(suit to cardRank)]) { "입력된 suit=[$suit] , cardRank=[$cardRank] 는 찾을수 없습니다" } } } } diff --git a/src/main/kotlin/blackjack/model/CardRank.kt b/src/main/kotlin/blackjack/model/card/CardRank.kt similarity index 91% rename from src/main/kotlin/blackjack/model/CardRank.kt rename to src/main/kotlin/blackjack/model/card/CardRank.kt index e900081fad..47d49e94e8 100644 --- a/src/main/kotlin/blackjack/model/CardRank.kt +++ b/src/main/kotlin/blackjack/model/card/CardRank.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.card enum class CardRank( val score: Int, diff --git a/src/main/kotlin/blackjack/model/Cards.kt b/src/main/kotlin/blackjack/model/card/Cards.kt similarity index 97% rename from src/main/kotlin/blackjack/model/Cards.kt rename to src/main/kotlin/blackjack/model/card/Cards.kt index a2af3cc74d..2e919117a8 100644 --- a/src/main/kotlin/blackjack/model/Cards.kt +++ b/src/main/kotlin/blackjack/model/card/Cards.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.card class Cards( cards: List = emptyList(), diff --git a/src/main/kotlin/blackjack/model/card/Suit.kt b/src/main/kotlin/blackjack/model/card/Suit.kt new file mode 100644 index 0000000000..dd83ffda04 --- /dev/null +++ b/src/main/kotlin/blackjack/model/card/Suit.kt @@ -0,0 +1,11 @@ +package blackjack.model.card + +enum class Suit( + val alias: String, +) { + SPADE("스페이드"), + HEART("하트"), + DIAMOND("다이아"), + CLOVER("클로버"), + ; +} diff --git a/src/main/kotlin/blackjack/model/Trump.kt b/src/main/kotlin/blackjack/model/card/Trump.kt similarity index 70% rename from src/main/kotlin/blackjack/model/Trump.kt rename to src/main/kotlin/blackjack/model/card/Trump.kt index fbc8f3139a..a152ad4bc2 100644 --- a/src/main/kotlin/blackjack/model/Trump.kt +++ b/src/main/kotlin/blackjack/model/card/Trump.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.card @JvmInline value class Trump( diff --git a/src/main/kotlin/blackjack/model/pack/Pack.kt b/src/main/kotlin/blackjack/model/pack/Pack.kt index da8925a27a..6befb861e9 100644 --- a/src/main/kotlin/blackjack/model/pack/Pack.kt +++ b/src/main/kotlin/blackjack/model/pack/Pack.kt @@ -1,6 +1,6 @@ package blackjack.model.pack -import blackjack.model.Card +import blackjack.model.card.Card interface Pack { fun pickCard(): Card diff --git a/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt b/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt index 897abc5a71..7260c063ad 100644 --- a/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt +++ b/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt @@ -1,8 +1,8 @@ package blackjack.model.pack -import blackjack.model.Card -import blackjack.model.CardRank -import blackjack.model.Suit +import blackjack.model.card.Card +import blackjack.model.card.CardRank +import blackjack.model.card.Suit import kotlin.random.Random object ShuffledPack : Pack { diff --git a/src/main/kotlin/blackjack/model/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt similarity index 68% rename from src/main/kotlin/blackjack/model/Playable.kt rename to src/main/kotlin/blackjack/model/playable/Playable.kt index 03a4935b91..1e9adc11f8 100644 --- a/src/main/kotlin/blackjack/model/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -1,6 +1,7 @@ -package blackjack.model +package blackjack.model.playable import blackjack.model.pack.Pack +import blackjack.model.playblestrategy.PlayingStrategy interface Playable { fun score(): Int diff --git a/src/main/kotlin/blackjack/model/PlayableReaction.kt b/src/main/kotlin/blackjack/model/playable/PlayableReaction.kt similarity index 61% rename from src/main/kotlin/blackjack/model/PlayableReaction.kt rename to src/main/kotlin/blackjack/model/playable/PlayableReaction.kt index 4f496a26fb..887d5830e2 100644 --- a/src/main/kotlin/blackjack/model/PlayableReaction.kt +++ b/src/main/kotlin/blackjack/model/playable/PlayableReaction.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.playable enum class PlayableReaction { HIT, diff --git a/src/main/kotlin/blackjack/model/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt similarity index 76% rename from src/main/kotlin/blackjack/model/Dealer.kt rename to src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index 10eea15702..f60e3bc7d2 100644 --- a/src/main/kotlin/blackjack/model/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -1,6 +1,10 @@ -package blackjack.model +package blackjack.model.playable.impl +import blackjack.model.card.Cards import blackjack.model.pack.Pack +import blackjack.model.playable.Playable +import blackjack.model.playable.PlayableReaction +import blackjack.model.playblestrategy.PlayingStrategy class Dealer( val cards: Cards = Cards(), diff --git a/src/main/kotlin/blackjack/model/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt similarity index 74% rename from src/main/kotlin/blackjack/model/Player.kt rename to src/main/kotlin/blackjack/model/playable/impl/Player.kt index 8c18e76c66..94d2ce4763 100644 --- a/src/main/kotlin/blackjack/model/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -1,6 +1,10 @@ -package blackjack.model +package blackjack.model.playable.impl +import blackjack.model.card.Cards import blackjack.model.pack.Pack +import blackjack.model.playable.Playable +import blackjack.model.playable.PlayableReaction +import blackjack.model.playblestrategy.PlayingStrategy class Player( val name: String, diff --git a/src/main/kotlin/blackjack/model/PlayingStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt similarity index 58% rename from src/main/kotlin/blackjack/model/PlayingStrategy.kt rename to src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt index b8854dcbc5..0a8aef4e02 100644 --- a/src/main/kotlin/blackjack/model/PlayingStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.playblestrategy interface PlayingStrategy { fun isHit(): Boolean diff --git a/src/main/kotlin/blackjack/model/DealerStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt similarity index 72% rename from src/main/kotlin/blackjack/model/DealerStrategy.kt rename to src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt index 11d8ae0a79..5c70efb46f 100644 --- a/src/main/kotlin/blackjack/model/DealerStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt @@ -1,4 +1,6 @@ -package blackjack.model +package blackjack.model.playblestrategy.impl + +import blackjack.model.playblestrategy.PlayingStrategy class DealerStrategy( private val currentScore: Int, diff --git a/src/main/kotlin/blackjack/model/playable/HitStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt similarity index 51% rename from src/main/kotlin/blackjack/model/playable/HitStrategy.kt rename to src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt index 15b0ffefdc..a638117094 100644 --- a/src/main/kotlin/blackjack/model/playable/HitStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt @@ -1,6 +1,6 @@ -package blackjack.model.playable +package blackjack.model.playblestrategy.impl -import blackjack.model.PlayingStrategy +import blackjack.model.playblestrategy.PlayingStrategy object HitStrategy : PlayingStrategy { override fun isHit(): Boolean { diff --git a/src/main/kotlin/blackjack/model/playable/StandStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt similarity index 51% rename from src/main/kotlin/blackjack/model/playable/StandStrategy.kt rename to src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt index 924a1bf04b..5ca7e758fd 100644 --- a/src/main/kotlin/blackjack/model/playable/StandStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt @@ -1,6 +1,6 @@ -package blackjack.model.playable +package blackjack.model.playblestrategy.impl -import blackjack.model.PlayingStrategy +import blackjack.model.playblestrategy.PlayingStrategy object StandStrategy : PlayingStrategy { override fun isHit(): Boolean { diff --git a/src/main/kotlin/blackjack/model/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt similarity index 78% rename from src/main/kotlin/blackjack/model/DealerResult.kt rename to src/main/kotlin/blackjack/model/result/DealerResult.kt index 352455eeca..dc8ff0362e 100644 --- a/src/main/kotlin/blackjack/model/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.result data class DealerResult( val point: Int, diff --git a/src/main/kotlin/blackjack/model/ParticipantResults.kt b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt similarity index 84% rename from src/main/kotlin/blackjack/model/ParticipantResults.kt rename to src/main/kotlin/blackjack/model/result/ParticipantResults.kt index 6b64637a90..99058f1e36 100644 --- a/src/main/kotlin/blackjack/model/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt @@ -1,4 +1,8 @@ -package blackjack.model +package blackjack.model.result + +import blackjack.model.Participants +import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.impl.Player class ParticipantResults( val playerResults: PlayersResults, diff --git a/src/main/kotlin/blackjack/model/PlayerResult.kt b/src/main/kotlin/blackjack/model/result/PlayerResult.kt similarity index 65% rename from src/main/kotlin/blackjack/model/PlayerResult.kt rename to src/main/kotlin/blackjack/model/result/PlayerResult.kt index 567d418c1e..ce8e660630 100644 --- a/src/main/kotlin/blackjack/model/PlayerResult.kt +++ b/src/main/kotlin/blackjack/model/result/PlayerResult.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.result enum class PlayerResult { WIN, diff --git a/src/main/kotlin/blackjack/model/PlayersResults.kt b/src/main/kotlin/blackjack/model/result/PlayersResults.kt similarity index 91% rename from src/main/kotlin/blackjack/model/PlayersResults.kt rename to src/main/kotlin/blackjack/model/result/PlayersResults.kt index 501b394758..2ef1c1745e 100644 --- a/src/main/kotlin/blackjack/model/PlayersResults.kt +++ b/src/main/kotlin/blackjack/model/result/PlayersResults.kt @@ -1,4 +1,6 @@ -package blackjack.model +package blackjack.model.result + +import blackjack.model.playable.impl.Player class PlayersResults( private val value: Map, diff --git a/src/main/kotlin/blackjack/view/Console.kt b/src/main/kotlin/blackjack/view/Console.kt index 1ed90fbc55..7542750b68 100644 --- a/src/main/kotlin/blackjack/view/Console.kt +++ b/src/main/kotlin/blackjack/view/Console.kt @@ -1,8 +1,8 @@ package blackjack.view -import blackjack.model.Cards -import blackjack.model.Dealer -import blackjack.model.Player +import blackjack.model.card.Cards +import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.impl.Player object Console { diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 39e324a5e3..9881dfcb84 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -1,12 +1,12 @@ package blackjack.view -import blackjack.model.Dealer import blackjack.model.Participants -import blackjack.model.Player import blackjack.model.Players -import blackjack.model.PlayingStrategy -import blackjack.model.playable.HitStrategy -import blackjack.model.playable.StandStrategy +import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.impl.Player +import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.playblestrategy.impl.HitStrategy +import blackjack.model.playblestrategy.impl.StandStrategy object InputView { private const val PLAYER_NAMES_DELIMITER: String = "," diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 4353c5783e..354ff3e498 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,8 +1,8 @@ package blackjack.view -import blackjack.model.ParticipantResults import blackjack.model.Participants -import blackjack.model.Player +import blackjack.model.playable.impl.Player +import blackjack.model.result.ParticipantResults import blackjack.view.Console.presentDealers import blackjack.view.Console.presentPlayers diff --git a/src/test/kotlin/blackjack/model/CardsTest.kt b/src/test/kotlin/blackjack/model/CardsTest.kt index 0bba60f724..7e2a505b7f 100644 --- a/src/test/kotlin/blackjack/model/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/CardsTest.kt @@ -1,5 +1,9 @@ package blackjack.model +import blackjack.model.card.Card +import blackjack.model.card.CardRank +import blackjack.model.card.Cards +import blackjack.model.card.Suit import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/DealerTest.kt index 9bede95b5b..d9ae3c8963 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/DealerTest.kt @@ -1,6 +1,12 @@ package blackjack.model +import blackjack.model.card.Card +import blackjack.model.card.CardRank +import blackjack.model.card.Cards +import blackjack.model.card.Suit import blackjack.model.pack.ShuffledPack +import blackjack.model.playable.impl.Dealer +import blackjack.model.playblestrategy.impl.DealerStrategy import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/PlayerTest.kt b/src/test/kotlin/blackjack/model/PlayerTest.kt index 081d0c43ee..47b8247087 100644 --- a/src/test/kotlin/blackjack/model/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/PlayerTest.kt @@ -1,6 +1,7 @@ package blackjack.model import blackjack.model.pack.ShuffledPack +import blackjack.model.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt index 5d1144d748..d2ed6a1fe1 100644 --- a/src/test/kotlin/blackjack/model/PlayersTest.kt +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -1,5 +1,6 @@ package blackjack.model +import blackjack.model.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index 414d72078b..9a7c8b9986 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -1,5 +1,12 @@ package blackjack.model +import blackjack.model.card.Card +import blackjack.model.card.CardRank +import blackjack.model.card.Cards +import blackjack.model.card.Suit +import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.impl.Player +import blackjack.model.result.PlayerResult import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe From 73c889020bb1e101afc84f69dc969ecac43dbf88 Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 14:53:53 +0900 Subject: [PATCH 27/81] =?UTF-8?q?refactor=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index c38fdb7a0f..3bb4f5c015 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -30,11 +30,3 @@ fun playingBlackJack(participants: Participants) { PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") } } - -private fun Player.hitOrStand() { - -// if () { -// this.hit(ShuffledPack) -// } -// OutputView.playerCardPresent(this) -} From cea03debc0ddff38cd4d3bfe83a624c45e0c7c9d Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 24 Nov 2023 15:00:12 +0900 Subject: [PATCH 28/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 3 +-- .../kotlin/blackjack/model/pack/{ => impl}/ShuffledPack.kt | 5 +++-- src/test/kotlin/blackjack/model/{ => card}/CardsTest.kt | 6 +----- .../blackjack/model/pack/{ => impl}/ShuffledPackTest.kt | 2 +- .../blackjack/model/{ => playable/impl}/DealerTest.kt | 5 ++--- .../blackjack/model/{ => playable/impl}/PlayerTest.kt | 7 ++++--- 6 files changed, 12 insertions(+), 16 deletions(-) rename src/main/kotlin/blackjack/model/pack/{ => impl}/ShuffledPack.kt (83%) rename src/test/kotlin/blackjack/model/{ => card}/CardsTest.kt (89%) rename src/test/kotlin/blackjack/model/pack/{ => impl}/ShuffledPackTest.kt (91%) rename src/test/kotlin/blackjack/model/{ => playable/impl}/DealerTest.kt (91%) rename src/test/kotlin/blackjack/model/{ => playable/impl}/PlayerTest.kt (86%) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 3bb4f5c015..c27179548e 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -2,9 +2,8 @@ package blackjack import blackjack.model.Participants import blackjack.model.Referee -import blackjack.model.pack.ShuffledPack +import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playable.PlayableReaction -import blackjack.model.playable.impl.Player import blackjack.model.playblestrategy.impl.DealerStrategy import blackjack.view.InputView import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt b/src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt similarity index 83% rename from src/main/kotlin/blackjack/model/pack/ShuffledPack.kt rename to src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt index 7260c063ad..9644dded62 100644 --- a/src/main/kotlin/blackjack/model/pack/ShuffledPack.kt +++ b/src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt @@ -1,8 +1,9 @@ -package blackjack.model.pack +package blackjack.model.pack.impl import blackjack.model.card.Card import blackjack.model.card.CardRank import blackjack.model.card.Suit +import blackjack.model.pack.Pack import kotlin.random.Random object ShuffledPack : Pack { @@ -21,6 +22,6 @@ object ShuffledPack : Pack { } private fun randomInRange(range: Int): Int { - return this.random.nextInt(0, Int.MAX_VALUE) % range + return random.nextInt(0, Int.MAX_VALUE) % range } } diff --git a/src/test/kotlin/blackjack/model/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt similarity index 89% rename from src/test/kotlin/blackjack/model/CardsTest.kt rename to src/test/kotlin/blackjack/model/card/CardsTest.kt index 7e2a505b7f..849a5acf33 100644 --- a/src/test/kotlin/blackjack/model/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -1,9 +1,5 @@ -package blackjack.model +package blackjack.model.card -import blackjack.model.card.Card -import blackjack.model.card.CardRank -import blackjack.model.card.Cards -import blackjack.model.card.Suit import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/pack/ShuffledPackTest.kt b/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt similarity index 91% rename from src/test/kotlin/blackjack/model/pack/ShuffledPackTest.kt rename to src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt index 69143f7624..4ea0abf72d 100644 --- a/src/test/kotlin/blackjack/model/pack/ShuffledPackTest.kt +++ b/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt @@ -1,4 +1,4 @@ -package blackjack.model.pack +package blackjack.model.pack.impl import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec diff --git a/src/test/kotlin/blackjack/model/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt similarity index 91% rename from src/test/kotlin/blackjack/model/DealerTest.kt rename to src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index d9ae3c8963..605b16cd48 100644 --- a/src/test/kotlin/blackjack/model/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,11 +1,10 @@ -package blackjack.model +package blackjack.model.playable.impl import blackjack.model.card.Card import blackjack.model.card.CardRank import blackjack.model.card.Cards import blackjack.model.card.Suit -import blackjack.model.pack.ShuffledPack -import blackjack.model.playable.impl.Dealer +import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playblestrategy.impl.DealerStrategy import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt similarity index 86% rename from src/test/kotlin/blackjack/model/PlayerTest.kt rename to src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 47b8247087..f966fddbeb 100644 --- a/src/test/kotlin/blackjack/model/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -1,12 +1,12 @@ -package blackjack.model +package blackjack.model.playable.impl -import blackjack.model.pack.ShuffledPack -import blackjack.model.playable.impl.Player +import blackjack.model.pack.impl.ShuffledPack import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe class PlayerTest : StringSpec({ + "플레이어는 dealing 시 2장의 카드를 받을 수 있다" { shouldNotThrow { val player = Player("구글") @@ -22,4 +22,5 @@ class PlayerTest : StringSpec({ player.cards.count() shouldBe 1 } } + }) From 030b03f2a8fe04b6fa9597ce4f4e7e59a1129fec Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 14:08:38 +0900 Subject: [PATCH 29/81] =?UTF-8?q?refactor=20:=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 4f2480617b..48886bb0da 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -7,6 +7,10 @@ import blackjack.model.result.PlayerResult class Players( val values: Set, ) { + init { + require(values.map { it.name }.distinct().size == values.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } + } + constructor(vararg players: Player) : this(players.toSet()) fun dealing(pack: Pack) { @@ -28,8 +32,4 @@ class Players( fun walkover(): Map { return values.associateWith { PlayerResult.WIN } } - - init { - require(values.map { it.name }.distinct().size == values.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } - } } From f3ce24d71af18e86f787ed1c074c60e0b7d65b78 Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 16:54:27 +0900 Subject: [PATCH 30/81] =?UTF-8?q?refactor=20:=20=ED=94=BD=EC=8A=A4?= =?UTF-8?q?=EC=B3=90=EB=A5=BC=EC=9D=B4=EC=9A=A9=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EB=B0=98=EB=B3=B5=EB=90=98=EB=8A=94=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=83=9D=EC=84=B1=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/RefereeTest.kt | 45 ++++--------------- .../blackjack/model/card/CardFixture.kt | 22 +++++++++ .../model/playable/impl/PlayerTest.kt | 1 - 3 files changed, 31 insertions(+), 37 deletions(-) create mode 100644 src/test/kotlin/blackjack/model/card/CardFixture.kt diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index 9a7c8b9986..61d8693e6f 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -1,9 +1,6 @@ package blackjack.model -import blackjack.model.card.Card -import blackjack.model.card.CardRank -import blackjack.model.card.Cards -import blackjack.model.card.Suit +import blackjack.model.card.CardFixture import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import blackjack.model.result.PlayerResult @@ -15,13 +12,7 @@ class RefereeTest : StringSpec({ "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 블랙잭이 아니어야만 한다" { val player = Player( "kim", - Cards( - listOf( - Card.of(Suit.HEART, CardRank.ACE), - Card.of(Suit.DIAMOND, CardRank.ACE), - Card.of(Suit.CLOVER, CardRank.KING) - ) - ) + CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) ) Referee.isGameOver(player) shouldBe false } @@ -29,12 +20,7 @@ class RefereeTest : StringSpec({ "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭으로 계산 되어야 한다" { val player = Player( "kim", - Cards( - listOf( - Card.of(Suit.DIAMOND, CardRank.ACE), - Card.of(Suit.CLOVER, CardRank.KING) - ) - ) + CardFixture.makeCards(CardFixture.ace1, CardFixture.king) ) Referee.isGameOver(player) shouldBe true } @@ -42,30 +28,17 @@ class RefereeTest : StringSpec({ "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { val player1 = Player( "seoul", - Cards( - listOf( - Card.of(Suit.DIAMOND, CardRank.ACE), - Card.of(Suit.CLOVER, CardRank.KING) - ) - ) + CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + ) val player2 = Player( "wonju", - Cards( - listOf( - Card.of(Suit.DIAMOND, CardRank.QUEEN), - Card.of(Suit.CLOVER, CardRank.KING) - ) - ) + CardFixture.makeCards(CardFixture.queen, CardFixture.king) + ) val dealer = Dealer( - Cards( - listOf( - Card.of(Suit.DIAMOND, CardRank.FIVE), - Card.of(Suit.CLOVER, CardRank.KING), - Card.of(Suit.HEART, CardRank.SEVEN), - ) - ) + CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) + ) val participants = Participants(Players(player1, player2), dealer) val actual = Referee.blackJackResult(participants) diff --git a/src/test/kotlin/blackjack/model/card/CardFixture.kt b/src/test/kotlin/blackjack/model/card/CardFixture.kt new file mode 100644 index 0000000000..29c802fc55 --- /dev/null +++ b/src/test/kotlin/blackjack/model/card/CardFixture.kt @@ -0,0 +1,22 @@ +package blackjack.model.card + +object CardFixture { + fun makeCards(vararg cardArray: Card): Cards { + return Cards(cardArray.toList()) + } + + val ace1 = Card.of(Suit.HEART, CardRank.ACE) + val ace2 = Card.of(Suit.DIAMOND, CardRank.ACE) + val two = Card.of(Suit.DIAMOND, CardRank.TWO) + val three = Card.of(Suit.DIAMOND, CardRank.THREE) + val four = Card.of(Suit.DIAMOND, CardRank.FOUR) + val five = Card.of(Suit.DIAMOND, CardRank.FIVE) + val six = Card.of(Suit.DIAMOND, CardRank.SIX) + val seven = Card.of(Suit.DIAMOND, CardRank.SEVEN) + val eight = Card.of(Suit.DIAMOND, CardRank.EIGHT) + val nine = Card.of(Suit.DIAMOND, CardRank.NINE) + val ten = Card.of(Suit.DIAMOND, CardRank.TEN) + val jack = Card.of(Suit.CLOVER, CardRank.JACK) + val queen = Card.of(Suit.CLOVER, CardRank.QUEEN) + val king = Card.of(Suit.CLOVER, CardRank.KING) +} diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index f966fddbeb..2ba7574290 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -22,5 +22,4 @@ class PlayerTest : StringSpec({ player.cards.count() shouldBe 1 } } - }) From b90b454122351e8b8ac8a422d1b632fb1731799d Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 17:00:32 +0900 Subject: [PATCH 31/81] =?UTF-8?q?refactor=20:=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=8B=A8=EC=96=B8=EB=AC=B8=EC=9D=84=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/impl/DealerTest.kt | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 605b16cd48..698000fdea 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,39 +1,33 @@ package blackjack.model.playable.impl -import blackjack.model.card.Card -import blackjack.model.card.CardRank -import blackjack.model.card.Cards -import blackjack.model.card.Suit +import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playblestrategy.impl.DealerStrategy import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe class DealerTest : StringSpec({ "딜러는 처음에 받은 2장의 카드 점수 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 한다" { val dealer = Dealer( - Cards( - listOf( - Card.of(Suit.CLOVER, CardRank.KING), - Card.of(Suit.HEART, CardRank.SIX), - ) - ) + CardFixture.makeCards(CardFixture.king, CardFixture.six) ) dealer.playing(DealerStrategy(16), ShuffledPack) + + dealer.cards.cards shouldContain CardFixture.king + dealer.cards.cards shouldContain CardFixture.six dealer.countOfCards() shouldBe 3 } "딜러는 카드의 점수 합계가 17점 이상이면 추가로 받을 수 없다" { val dealer = Dealer( - Cards( - listOf( - Card.of(Suit.CLOVER, CardRank.KING), - Card.of(Suit.HEART, CardRank.SEVEN), - ) - ) + CardFixture.makeCards(CardFixture.king, CardFixture.seven) ) dealer.playing(DealerStrategy(17), ShuffledPack) + + dealer.cards.cards shouldContain CardFixture.king + dealer.cards.cards shouldContain CardFixture.seven dealer.countOfCards() shouldBe 2 } }) From 8426423ed61b96dfa5d9a48165b7af280ad8c075 Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 17:07:57 +0900 Subject: [PATCH 32/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=20=EA=B2=8C=EC=9E=84=EC=9C=BC=EB=A1=9C=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EB=B6=84=EB=A6=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 19 +++----------- .../kotlin/blackjack/model/BlackJackGame.kt | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/BlackJackGame.kt diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index c27179548e..725e233cb3 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,10 +1,8 @@ package blackjack -import blackjack.model.Participants +import blackjack.model.BlackJackGame import blackjack.model.Referee import blackjack.model.pack.impl.ShuffledPack -import blackjack.model.playable.PlayableReaction -import blackjack.model.playblestrategy.impl.DealerStrategy import blackjack.view.InputView import blackjack.view.OutputView @@ -13,19 +11,8 @@ fun main() { participants.dealing(ShuffledPack) OutputView.dealing(participants) OutputView.presentCards(participants) - while (participants.isContinue()) { - playingBlackJack(participants) - } + val game = BlackJackGame(participants) + game.start() OutputView.presentScores(participants) OutputView.presentResult(Referee.blackJackResult(participants)) } - -fun playingBlackJack(participants: Participants) { - participants.players.values.forEach { - it.playing(InputView.askHit(it), ShuffledPack) - } - when (participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack)) { - PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") - PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") - } -} diff --git a/src/main/kotlin/blackjack/model/BlackJackGame.kt b/src/main/kotlin/blackjack/model/BlackJackGame.kt new file mode 100644 index 0000000000..fb4c2082bc --- /dev/null +++ b/src/main/kotlin/blackjack/model/BlackJackGame.kt @@ -0,0 +1,26 @@ +package blackjack.model + +import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.playable.PlayableReaction +import blackjack.model.playblestrategy.impl.DealerStrategy +import blackjack.view.InputView + +class BlackJackGame( + private val participants: Participants, +) { + fun start() { + while (participants.isContinue()) { + playingBlackJack(participants) + } + } + + private fun playingBlackJack(participants: Participants) { + participants.players.values.forEach { + it.playing(InputView.askHit(it), ShuffledPack) + } + when (participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack)) { + PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") + PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") + } + } +} From a83a72554f38cb9704ae5e9f75830c53c36d19ce Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 17:09:30 +0900 Subject: [PATCH 33/81] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Participants.kt | 2 +- src/main/kotlin/blackjack/model/Players.kt | 2 +- src/main/kotlin/blackjack/model/Referee.kt | 2 +- src/test/kotlin/blackjack/model/RefereeTest.kt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index 4226eda197..cd5adbd545 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -14,7 +14,7 @@ class Participants( } private fun isGameOver(): Boolean { - return players.isGameOver() || Referee.isGameOver(dealer) + return players.isGameOver() || Referee.isBurst(dealer) } fun isContinue(): Boolean { diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 48886bb0da..e5cd6861b2 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -18,7 +18,7 @@ class Players( } fun isGameOver(): Boolean { - return values.any { Referee.isGameOver(it) } + return values.any { Referee.isBurst(it) } } fun count(): Int { diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index fd65ecf16b..68ddf8af7f 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -12,7 +12,7 @@ object Referee { private const val BLACK_JACK_SCORE: Int = 21 - fun isGameOver(playable: Playable): Boolean { + fun isBurst(playable: Playable): Boolean { return playable.score() >= BLACK_JACK_SCORE } diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index 61d8693e6f..cacd105974 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -14,7 +14,7 @@ class RefereeTest : StringSpec({ "kim", CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) ) - Referee.isGameOver(player) shouldBe false + Referee.isBurst(player) shouldBe false } "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭으로 계산 되어야 한다" { @@ -22,7 +22,7 @@ class RefereeTest : StringSpec({ "kim", CardFixture.makeCards(CardFixture.ace1, CardFixture.king) ) - Referee.isGameOver(player) shouldBe true + Referee.isBurst(player) shouldBe true } "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { From a33565deda6bfb004245d43916a0275c6b122c78 Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 17:18:18 +0900 Subject: [PATCH 34/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=EC=9D=98=20=EA=B2=B0=EA=B3=BC=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=8B=AC=ED=8C=90=EC=9D=B4=20=EC=A0=95=ED=95=98=EB=8A=94?= =?UTF-8?q?=EA=B2=83=EC=9D=B4=20=EC=95=84=EB=8B=8C,=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20=EB=82=B4=EB=B6=80=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=94=9C=EB=9F=AC=EC=9D=98=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Referee.kt | 17 ++--------------- .../blackjack/model/playable/impl/Dealer.kt | 11 +++++++++++ .../blackjack/model/result/DealerResult.kt | 8 ++++---- .../model/result/ParticipantResults.kt | 4 ++-- src/test/kotlin/blackjack/model/RefereeTest.kt | 6 +++--- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index 68ddf8af7f..c7629a7369 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -3,7 +3,6 @@ package blackjack.model import blackjack.model.playable.Playable import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player -import blackjack.model.result.DealerResult import blackjack.model.result.ParticipantResults import blackjack.model.result.PlayerResult import blackjack.model.result.PlayersResults @@ -24,26 +23,14 @@ object Referee { val playerResults = getPlayerResults(participants) return ParticipantResults( playerResults = playerResults, - dealerDealerResult = getDealerResult(participants, playerResults) + // dealerDealerResult = getDealerResult(participants, playerResults) + dealerDealerResult = participants.dealer.result(playerResults) ) // 2) 딜러가 승리한 상황 // 3) 플레이어중 하나가 승리하고, 딜러가 패배한 상황 // 4) 플러이어중 하나 승리, 하나 비긴, 하나 패배 딜러 } - private fun getDealerResult( - participants: Participants, - playerResults: PlayersResults - ): Pair { - val dealerScore = participants.dealer.score() - return participants.dealer to DealerResult( - dealerScore, - playerResults.winningCount(), - playerResults.drawingCount(), - playerResults.loseCount() - ) - } - private fun getPlayerResults(participants: Participants): PlayersResults { val dealerScore = participants.dealer.score() return PlayersResults(participants.players.scoreBattle(dealerScore)) diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index f60e3bc7d2..cc92243693 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -5,6 +5,8 @@ import blackjack.model.pack.Pack import blackjack.model.playable.Playable import blackjack.model.playable.PlayableReaction import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.result.DealerResult +import blackjack.model.result.PlayersResults class Dealer( val cards: Cards = Cards(), @@ -31,6 +33,15 @@ class Dealer( return PlayableReaction.STAND } + fun result(playerResults: PlayersResults): Pair { + return this to DealerResult( + score = this.score(), + dealerWinningCount = playerResults.loseCount(), + dealerDrawingCount = playerResults.drawingCount(), + dealerLosingCount = playerResults.winningCount() + ) + } + companion object { private const val DEALER_PICK_THRESHOLD = 16 } diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index dc8ff0362e..12d465d760 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,8 +1,8 @@ package blackjack.model.result data class DealerResult( - val point: Int, - val winning: Int, - val drawing: Int, - val losing: Int, + val score: Int, + val dealerWinningCount: Int, + val dealerDrawingCount: Int, + val dealerLosingCount: Int, ) diff --git a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt index 99058f1e36..d9af371f99 100644 --- a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt @@ -17,11 +17,11 @@ class ParticipantResults( } fun dealerWinCount(): Int { - return this.dealerDealerResult.second.winning + return this.dealerDealerResult.second.dealerWinningCount } fun dealerLoseCount(): Int { - return this.dealerDealerResult.second.losing + return this.dealerDealerResult.second.dealerLosingCount } companion object { diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index cacd105974..efa3abb803 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -43,9 +43,9 @@ class RefereeTest : StringSpec({ val participants = Participants(Players(player1, player2), dealer) val actual = Referee.blackJackResult(participants) - actual.dealerResult().point shouldBe 22 - actual.dealerResult().winning shouldBe 0 - actual.dealerResult().losing shouldBe 2 + actual.dealerResult().score shouldBe 22 + actual.dealerResult().dealerWinningCount shouldBe 0 + actual.dealerResult().dealerLosingCount shouldBe 2 actual.playerResult(player1) shouldBe PlayerResult.WIN actual.playerResult(player2) shouldBe PlayerResult.WIN From 5267bffc26acb60b64515deaa2d54c18ba074d18 Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 17:39:31 +0900 Subject: [PATCH 35/81] =?UTF-8?q?refactor=20:=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=20=EC=B6=9C=EB=A0=A5=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EB=8B=A4=EB=A5=B8=20=ED=94=8C?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=EB=B8=94=EC=9D=84=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 8 +++--- src/main/kotlin/blackjack/model/Referee.kt | 22 ++++++---------- .../blackjack/model/playable/Playable.kt | 2 ++ .../model/playable/PlayableResult.kt | 7 ++++++ .../blackjack/model/playable/impl/Dealer.kt | 25 ++++++++++++------- .../blackjack/model/playable/impl/Player.kt | 21 ++++++++++++++-- .../model/result/ParticipantResults.kt | 3 ++- .../blackjack/model/result/PlayerResult.kt | 7 ------ .../blackjack/model/result/PlayersResults.kt | 15 +++++------ .../kotlin/blackjack/model/RefereeTest.kt | 6 ++--- 10 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/playable/PlayableResult.kt delete mode 100644 src/main/kotlin/blackjack/model/result/PlayerResult.kt diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index e5cd6861b2..7ff835f3fb 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,8 +1,8 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Player -import blackjack.model.result.PlayerResult class Players( val values: Set, @@ -25,11 +25,11 @@ class Players( return values.size } - fun scoreBattle(dealerScore: Int): Map { + fun scoreBattle(dealerScore: Int): Map { return values.associateWith { Referee.playerResult(it, dealerScore) } } - fun walkover(): Map { - return values.associateWith { PlayerResult.WIN } + fun walkover(): Map { + return values.associateWith { PlayableResult.WIN } } } diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index c7629a7369..52c01efc20 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -1,30 +1,27 @@ package blackjack.model import blackjack.model.playable.Playable -import blackjack.model.playable.impl.Dealer +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Player import blackjack.model.result.ParticipantResults -import blackjack.model.result.PlayerResult import blackjack.model.result.PlayersResults object Referee { - private const val BLACK_JACK_SCORE: Int = 21 + const val BLACK_JACK_SCORE: Int = 21 fun isBurst(playable: Playable): Boolean { return playable.score() >= BLACK_JACK_SCORE } fun blackJackResult(participants: Participants): ParticipantResults { - if (isBlackJackScoreOver(participants.dealer)) { - // 1) 딜러가 21을 넘어 모든 플레이어가 승리한 상황 + if (participants.dealer.isBurst()) { return ParticipantResults.ofDealerLose(participants) } val playerResults = getPlayerResults(participants) return ParticipantResults( playerResults = playerResults, - // dealerDealerResult = getDealerResult(participants, playerResults) - dealerDealerResult = participants.dealer.result(playerResults) + dealerDealerResult = participants.dealer.dealerResult(participants.players) ) // 2) 딜러가 승리한 상황 // 3) 플레이어중 하나가 승리하고, 딜러가 패배한 상황 @@ -36,17 +33,14 @@ object Referee { return PlayersResults(participants.players.scoreBattle(dealerScore)) } - private fun isBlackJackScoreOver(dealer: Dealer): Boolean { - return dealer.score() > BLACK_JACK_SCORE - } - fun playerResult(player: Player, dealerScore: Int): PlayerResult { + fun playerResult(player: Player, dealerScore: Int): PlayableResult { if (player.score() == dealerScore) { - return PlayerResult.DRAW + return PlayableResult.DRAW } if (player.score() > dealerScore) { - return PlayerResult.WIN + return PlayableResult.WIN } - return PlayerResult.LOSE + return PlayableResult.LOSE } } diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt index 1e9adc11f8..1fc3cf632f 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -7,4 +7,6 @@ interface Playable { fun score(): Int fun dealing(pack: Pack) fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction + fun result(playable: Playable): PlayableResult + fun isBurst(): Boolean } diff --git a/src/main/kotlin/blackjack/model/playable/PlayableResult.kt b/src/main/kotlin/blackjack/model/playable/PlayableResult.kt new file mode 100644 index 0000000000..a956e26b4d --- /dev/null +++ b/src/main/kotlin/blackjack/model/playable/PlayableResult.kt @@ -0,0 +1,7 @@ +package blackjack.model.playable + +enum class PlayableResult { + WIN, + LOSE, + DRAW, +} diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index cc92243693..aea5d93ac0 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -1,12 +1,14 @@ package blackjack.model.playable.impl +import blackjack.model.Players +import blackjack.model.Referee import blackjack.model.card.Cards import blackjack.model.pack.Pack import blackjack.model.playable.Playable import blackjack.model.playable.PlayableReaction +import blackjack.model.playable.PlayableResult import blackjack.model.playblestrategy.PlayingStrategy import blackjack.model.result.DealerResult -import blackjack.model.result.PlayersResults class Dealer( val cards: Cards = Cards(), @@ -33,16 +35,21 @@ class Dealer( return PlayableReaction.STAND } - fun result(playerResults: PlayersResults): Pair { + override fun result(playable: Playable): PlayableResult { + TODO("Not yet implemented") + } + + override fun isBurst(): Boolean { + return this.score() > Referee.BLACK_JACK_SCORE + } + + fun dealerResult(players: Players): Pair { + val results = players.values.map { it -> this.result(it) } return this to DealerResult( score = this.score(), - dealerWinningCount = playerResults.loseCount(), - dealerDrawingCount = playerResults.drawingCount(), - dealerLosingCount = playerResults.winningCount() + dealerWinningCount = results.count { it == PlayableResult.WIN }, + dealerDrawingCount = results.count { it == PlayableResult.DRAW }, + dealerLosingCount = results.count { it == PlayableResult.LOSE } ) } - - companion object { - private const val DEALER_PICK_THRESHOLD = 16 - } } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index 94d2ce4763..ed027c6b92 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -1,15 +1,22 @@ package blackjack.model.playable.impl +import blackjack.model.Referee import blackjack.model.card.Cards import blackjack.model.pack.Pack import blackjack.model.playable.Playable import blackjack.model.playable.PlayableReaction +import blackjack.model.playable.PlayableResult import blackjack.model.playblestrategy.PlayingStrategy class Player( val name: String, val cards: Cards = Cards.emptyCards(), ) : Playable { + + override fun score(): Int { + return this.cards.totalScore() + } + override fun dealing(pack: Pack) { cards.add(pack.pickCard()) cards.add(pack.pickCard()) @@ -27,7 +34,17 @@ class Player( cards.add(pack.pickCard()) } - override fun score(): Int { - return this.cards.totalScore() + override fun result(playable: Playable): PlayableResult { + if (this.score() == playable.score()) { + return PlayableResult.DRAW + } + if (this.score() > playable.score()) { + return PlayableResult.WIN + } + return PlayableResult.LOSE + } + + override fun isBurst(): Boolean { + return this.score() > Referee.BLACK_JACK_SCORE } } diff --git a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt index d9af371f99..88aba8c2b2 100644 --- a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt +++ b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt @@ -1,6 +1,7 @@ package blackjack.model.result import blackjack.model.Participants +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player @@ -12,7 +13,7 @@ class ParticipantResults( return dealerDealerResult.second } - fun playerResult(player: Player): PlayerResult { + fun playerResult(player: Player): PlayableResult { return playerResults.resultOfPlayer(player) } diff --git a/src/main/kotlin/blackjack/model/result/PlayerResult.kt b/src/main/kotlin/blackjack/model/result/PlayerResult.kt deleted file mode 100644 index ce8e660630..0000000000 --- a/src/main/kotlin/blackjack/model/result/PlayerResult.kt +++ /dev/null @@ -1,7 +0,0 @@ -package blackjack.model.result - -enum class PlayerResult { - WIN, - LOSE, - DRAW, -} diff --git a/src/main/kotlin/blackjack/model/result/PlayersResults.kt b/src/main/kotlin/blackjack/model/result/PlayersResults.kt index 2ef1c1745e..152aa4d762 100644 --- a/src/main/kotlin/blackjack/model/result/PlayersResults.kt +++ b/src/main/kotlin/blackjack/model/result/PlayersResults.kt @@ -1,31 +1,32 @@ package blackjack.model.result +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Player class PlayersResults( - private val value: Map, + private val value: Map, ) { fun loseCount(): Int { - return value.values.count { it == PlayerResult.LOSE } + return value.values.count { it == PlayableResult.LOSE } } fun winningCount(): Int { - return value.values.count { it == PlayerResult.WIN } + return value.values.count { it == PlayableResult.WIN } } fun drawingCount(): Int { - return value.values.count { it == PlayerResult.DRAW } + return value.values.count { it == PlayableResult.DRAW } } - fun resultOfPlayer(player: Player): PlayerResult { + fun resultOfPlayer(player: Player): PlayableResult { return requireNotNull(value[player]) { "플레이어를 찾을 수 없음" } } - fun playerResult(): List> { + fun playerResult(): List> { return value.keys.map { playerNameAndResult(it) }.toList() } - private fun playerNameAndResult(it: Player): Pair { + private fun playerNameAndResult(it: Player): Pair { return it.name to requireNotNull(value[it]) { "플레이어 ${it.name} 을 찾을 수 없습니다" } } } diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index efa3abb803..d476304e08 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -1,9 +1,9 @@ package blackjack.model import blackjack.model.card.CardFixture +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player -import blackjack.model.result.PlayerResult import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -47,7 +47,7 @@ class RefereeTest : StringSpec({ actual.dealerResult().dealerWinningCount shouldBe 0 actual.dealerResult().dealerLosingCount shouldBe 2 - actual.playerResult(player1) shouldBe PlayerResult.WIN - actual.playerResult(player2) shouldBe PlayerResult.WIN + actual.playerResult(player1) shouldBe PlayableResult.WIN + actual.playerResult(player2) shouldBe PlayableResult.WIN } }) From fb976439b712d510864cb0ea74e2f758a06e8d34 Mon Sep 17 00:00:00 2001 From: dong Date: Sat, 25 Nov 2023 18:00:16 +0900 Subject: [PATCH 36/81] =?UTF-8?q?refactor=20:=20=EA=B3=BC=EB=8F=84?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=B3=B5=EC=9E=A1=ED=95=9C=20result=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=EB=93=A4=EC=9D=84=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 4 +- src/main/kotlin/blackjack/model/Players.kt | 9 --- src/main/kotlin/blackjack/model/Referee.kt | 57 ++++++++----------- .../blackjack/model/playable/impl/Dealer.kt | 6 +- .../blackjack/model/result/DealerResult.kt | 14 +++-- .../model/result/ParticipantResults.kt | 36 ------------ .../blackjack/model/result/PlayersResults.kt | 32 ----------- src/main/kotlin/blackjack/view/OutputView.kt | 24 ++++++-- .../kotlin/blackjack/model/RefereeTest.kt | 52 ++++++++--------- 9 files changed, 82 insertions(+), 152 deletions(-) delete mode 100644 src/main/kotlin/blackjack/model/result/ParticipantResults.kt delete mode 100644 src/main/kotlin/blackjack/model/result/PlayersResults.kt diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 725e233cb3..c3984268a6 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,8 +1,8 @@ package blackjack import blackjack.model.BlackJackGame -import blackjack.model.Referee import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.result.DealerResult import blackjack.view.InputView import blackjack.view.OutputView @@ -14,5 +14,5 @@ fun main() { val game = BlackJackGame(participants) game.start() OutputView.presentScores(participants) - OutputView.presentResult(Referee.blackJackResult(participants)) + OutputView.presentResult(DealerResult.a()) } diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 7ff835f3fb..f5027c30b3 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,7 +1,6 @@ package blackjack.model import blackjack.model.pack.Pack -import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Player class Players( @@ -24,12 +23,4 @@ class Players( fun count(): Int { return values.size } - - fun scoreBattle(dealerScore: Int): Map { - return values.associateWith { Referee.playerResult(it, dealerScore) } - } - - fun walkover(): Map { - return values.associateWith { PlayableResult.WIN } - } } diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt index 52c01efc20..5167d16e9c 100644 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ b/src/main/kotlin/blackjack/model/Referee.kt @@ -1,10 +1,6 @@ package blackjack.model import blackjack.model.playable.Playable -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Player -import blackjack.model.result.ParticipantResults -import blackjack.model.result.PlayersResults object Referee { @@ -14,33 +10,28 @@ object Referee { return playable.score() >= BLACK_JACK_SCORE } - fun blackJackResult(participants: Participants): ParticipantResults { - if (participants.dealer.isBurst()) { - return ParticipantResults.ofDealerLose(participants) - } - val playerResults = getPlayerResults(participants) - return ParticipantResults( - playerResults = playerResults, - dealerDealerResult = participants.dealer.dealerResult(participants.players) - ) - // 2) 딜러가 승리한 상황 - // 3) 플레이어중 하나가 승리하고, 딜러가 패배한 상황 - // 4) 플러이어중 하나 승리, 하나 비긴, 하나 패배 딜러 - } - - private fun getPlayerResults(participants: Participants): PlayersResults { - val dealerScore = participants.dealer.score() - return PlayersResults(participants.players.scoreBattle(dealerScore)) - } - - - fun playerResult(player: Player, dealerScore: Int): PlayableResult { - if (player.score() == dealerScore) { - return PlayableResult.DRAW - } - if (player.score() > dealerScore) { - return PlayableResult.WIN - } - return PlayableResult.LOSE - } +// fun blackJackResult(participants: Participants): DealerResult { +// if (participants.dealer.isBurst()) { +// return DealerResult.burst(participants.dealer, participants) +// } +// +// } + + // val playerResults = getPlayerResults(participants) + +// private fun getPlayerResults(participants: Participants): PlayersResults { +// val dealerScore = participants.dealer.score() +// return PlayersResults(participants.players.scoreBattle(dealerScore)) +// } +// +// +// fun playerResult(player: Player, dealerScore: Int): PlayableResult { +// if (player.score() == dealerScore) { +// return PlayableResult.DRAW +// } +// if (player.score() > dealerScore) { +// return PlayableResult.WIN +// } +// return PlayableResult.LOSE +// } } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index aea5d93ac0..abdbecc171 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -47,9 +47,9 @@ class Dealer( val results = players.values.map { it -> this.result(it) } return this to DealerResult( score = this.score(), - dealerWinningCount = results.count { it == PlayableResult.WIN }, - dealerDrawingCount = results.count { it == PlayableResult.DRAW }, - dealerLosingCount = results.count { it == PlayableResult.LOSE } + winningCount = results.count { it == PlayableResult.WIN }, + drawingCount = results.count { it == PlayableResult.DRAW }, + losingCount = results.count { it == PlayableResult.LOSE } ) } } diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index 12d465d760..325a046f7c 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -2,7 +2,13 @@ package blackjack.model.result data class DealerResult( val score: Int, - val dealerWinningCount: Int, - val dealerDrawingCount: Int, - val dealerLosingCount: Int, -) + val winningCount: Int, + val drawingCount: Int, + val losingCount: Int, +) { + companion object { + fun a(): DealerResult { + TODO("Not yet implemented") + } + } +} diff --git a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt b/src/main/kotlin/blackjack/model/result/ParticipantResults.kt deleted file mode 100644 index 88aba8c2b2..0000000000 --- a/src/main/kotlin/blackjack/model/result/ParticipantResults.kt +++ /dev/null @@ -1,36 +0,0 @@ -package blackjack.model.result - -import blackjack.model.Participants -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player - -class ParticipantResults( - val playerResults: PlayersResults, - val dealerDealerResult: Pair, -) { - fun dealerResult(): DealerResult { - return dealerDealerResult.second - } - - fun playerResult(player: Player): PlayableResult { - return playerResults.resultOfPlayer(player) - } - - fun dealerWinCount(): Int { - return this.dealerDealerResult.second.dealerWinningCount - } - - fun dealerLoseCount(): Int { - return this.dealerDealerResult.second.dealerLosingCount - } - - companion object { - fun ofDealerLose(participants: Participants): ParticipantResults { - return ParticipantResults( - PlayersResults(participants.players.walkover()), - participants.dealer to DealerResult(participants.dealer.score(), 0, 0, participants.count() - 1) - ) - } - } -} diff --git a/src/main/kotlin/blackjack/model/result/PlayersResults.kt b/src/main/kotlin/blackjack/model/result/PlayersResults.kt deleted file mode 100644 index 152aa4d762..0000000000 --- a/src/main/kotlin/blackjack/model/result/PlayersResults.kt +++ /dev/null @@ -1,32 +0,0 @@ -package blackjack.model.result - -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Player - -class PlayersResults( - private val value: Map, -) { - fun loseCount(): Int { - return value.values.count { it == PlayableResult.LOSE } - } - - fun winningCount(): Int { - return value.values.count { it == PlayableResult.WIN } - } - - fun drawingCount(): Int { - return value.values.count { it == PlayableResult.DRAW } - } - - fun resultOfPlayer(player: Player): PlayableResult { - return requireNotNull(value[player]) { "플레이어를 찾을 수 없음" } - } - - fun playerResult(): List> { - return value.keys.map { playerNameAndResult(it) }.toList() - } - - private fun playerNameAndResult(it: Player): Pair { - return it.name to requireNotNull(value[it]) { "플레이어 ${it.name} 을 찾을 수 없습니다" } - } -} diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 354ff3e498..d36f6518e3 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -2,7 +2,7 @@ package blackjack.view import blackjack.model.Participants import blackjack.model.playable.impl.Player -import blackjack.model.result.ParticipantResults +import blackjack.model.result.DealerResult import blackjack.view.Console.presentDealers import blackjack.view.Console.presentPlayers @@ -31,12 +31,24 @@ object OutputView { println(it.presentPlayers()) } - fun presentResult(blackJackResult: ParticipantResults) { + fun presentResult(dealerResult: DealerResult) { println("## 최종 승패") - println("딜러 ${blackJackResult.dealerWinCount()}승 ${blackJackResult.dealerLoseCount()}패") - blackJackResult.playerResults - .playerResult() - .forEach { println("${it.first}: ${it.second}") } + if (hasDraw(dealerResult)) { + presentResultWithDraw(dealerResult) + } + presentResultWithoutDraw(dealerResult) + } + + private fun presentResultWithoutDraw(dealerResult: DealerResult) { + println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.drawingCount}패") + } + + private fun presentResultWithDraw(dealerResult: DealerResult) { + println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}패") + } + + private fun hasDraw(dealerResult: DealerResult): Boolean { + return dealerResult.drawingCount > 0 } } diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt index d476304e08..813a332a44 100644 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ b/src/test/kotlin/blackjack/model/RefereeTest.kt @@ -1,8 +1,6 @@ package blackjack.model import blackjack.model.card.CardFixture -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -25,29 +23,29 @@ class RefereeTest : StringSpec({ Referee.isBurst(player) shouldBe true } - "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { - val player1 = Player( - "seoul", - CardFixture.makeCards(CardFixture.ace1, CardFixture.king) - - ) - val player2 = Player( - "wonju", - CardFixture.makeCards(CardFixture.queen, CardFixture.king) - - ) - val dealer = Dealer( - CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) - - ) - val participants = Participants(Players(player1, player2), dealer) - val actual = Referee.blackJackResult(participants) - - actual.dealerResult().score shouldBe 22 - actual.dealerResult().dealerWinningCount shouldBe 0 - actual.dealerResult().dealerLosingCount shouldBe 2 - - actual.playerResult(player1) shouldBe PlayableResult.WIN - actual.playerResult(player2) shouldBe PlayableResult.WIN - } +// "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { +// val player1 = Player( +// "seoul", +// CardFixture.makeCards(CardFixture.ace1, CardFixture.king) +// +// ) +// val player2 = Player( +// "wonju", +// CardFixture.makeCards(CardFixture.queen, CardFixture.king) +// +// ) +// val dealer = Dealer( +// CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) +// +// ) +// val participants = Participants(Players(player1, player2), dealer) +// val actual = Referee.blackJackResult(participants) +// +// actual.dealerResult().score shouldBe 22 +// actual.dealerResult().dealerWinningCount shouldBe 0 +// actual.dealerResult().dealerLosingCount shouldBe 2 +// +// actual.playerResult(player1) shouldBe PlayableResult.WIN +// actual.playerResult(player2) shouldBe PlayableResult.WIN +// } }) From 7abf5adb2ec1810b00e1f7c772e7395fd2005dad Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:18:34 +0900 Subject: [PATCH 37/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=EC=9D=98=20=EC=A0=90=EC=88=98=EB=A5=BC=20=EB=82=98?= =?UTF-8?q?=ED=83=80=EB=82=B4=EB=8A=94=20=EB=8F=84=EB=A7=A4=EC=9D=B8=20?= =?UTF-8?q?=ED=8F=AC=EC=9E=A5=ED=81=B4=EB=9E=98=EC=8A=A4=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 --- .../model/playable/BlackjackScore.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/kotlin/blackjack/model/playable/BlackjackScore.kt diff --git a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt new file mode 100644 index 0000000000..20a64544a9 --- /dev/null +++ b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt @@ -0,0 +1,26 @@ +package blackjack.model.playable + +import blackjack.model.Referee + +@JvmInline +value class BlackjackScore( + private val value: Int +) { + infix fun vs(other: BlackjackScore): PlayableResult { + if (this.value == other.value) { + return PlayableResult.DRAW + } + if (this.value > other.value) { + return PlayableResult.WIN + } + return PlayableResult.LOSE + } + + fun isBurst(): Boolean { + return this.value > Referee.BLACK_JACK_SCORE + } + + operator fun compareTo(other: BlackjackScore): Int { + return this.value.compareTo(other.value) + } +} From 3ee585d0248b8f9fc6afc4ceeac2a050eff85226 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:19:05 +0900 Subject: [PATCH 38/81] =?UTF-8?q?refactor=20:=20BlackJack()=20=EB=8F=84?= =?UTF-8?q?=EB=A7=A4=EC=9D=B8=20=ED=8F=AC=EC=9E=A5=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=A0=81=EC=9A=A9=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/card/Cards.kt | 8 +++++--- src/test/kotlin/blackjack/model/card/CardsTest.kt | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/blackjack/model/card/Cards.kt b/src/main/kotlin/blackjack/model/card/Cards.kt index 2e919117a8..ae134c9fe6 100644 --- a/src/main/kotlin/blackjack/model/card/Cards.kt +++ b/src/main/kotlin/blackjack/model/card/Cards.kt @@ -1,5 +1,7 @@ package blackjack.model.card +import blackjack.model.playable.BlackjackScore + class Cards( cards: List = emptyList(), ) { @@ -10,11 +12,11 @@ class Cards( _cards.add(card) } - fun totalScore(): Int { + fun totalScore(): BlackjackScore { if (this.isContainsAce()) { - return scoreWithAce() + return BlackjackScore(scoreWithAce()) } - return simpleSumOfScore() + return BlackjackScore(simpleSumOfScore()) } private fun simpleSumOfScore(): Int { diff --git a/src/test/kotlin/blackjack/model/card/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt index 849a5acf33..34608e8715 100644 --- a/src/test/kotlin/blackjack/model/card/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -1,5 +1,6 @@ package blackjack.model.card +import blackjack.model.playable.BlackjackScore import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -14,7 +15,7 @@ class CardsTest : StringSpec({ Card.of(Suit.HEART, CardRank.KING) ) ).totalScore() - actual shouldBe (3 + 5 + 8 + 10) + actual shouldBe BlackjackScore(3 + 5 + 8 + 10) } "합계점수가 21를 초과 하는 경우, ACE 가 1로 인식되어야 한다" { @@ -26,7 +27,7 @@ class CardsTest : StringSpec({ Card.of(Suit.HEART, CardRank.KING) ) ).totalScore() - actual shouldBe (1 + 5 + 8 + 10) + actual shouldBe BlackjackScore(1 + 5 + 8 + 10) } "합계점수가 21를 이하인 경우, ACE 가 11로 인식되어야 한다" { @@ -37,6 +38,6 @@ class CardsTest : StringSpec({ Card.of(Suit.DIAMOND, CardRank.FIVE), ) ).totalScore() - actual shouldBe (11 + 3 + 5) + actual shouldBe BlackjackScore(11 + 3 + 5) } }) From 7c15dae8c032c83596558acc646297f4d3ce25b8 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:20:31 +0900 Subject: [PATCH 39/81] =?UTF-8?q?refactor=20:=20BlackJack()=20=EB=8F=84?= =?UTF-8?q?=EB=A7=A4=EC=9D=B8=20=ED=8F=AC=EC=9E=A5=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=A0=81=EC=9A=A9=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EB=B8=94=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A1=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95=ED=95=98=EC=98=80?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/model/playable/Playable.kt | 2 +- .../blackjack/model/playable/impl/Dealer.kt | 14 ++++++------- .../blackjack/model/playable/impl/Player.kt | 20 +++++++------------ .../playblestrategy/impl/DealerStrategy.kt | 7 ++++--- .../blackjack/model/result/DealerResult.kt | 4 +++- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt index 1fc3cf632f..6af199a345 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -4,7 +4,7 @@ import blackjack.model.pack.Pack import blackjack.model.playblestrategy.PlayingStrategy interface Playable { - fun score(): Int + fun score(): BlackjackScore fun dealing(pack: Pack) fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction fun result(playable: Playable): PlayableResult diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index abdbecc171..a9ab4056fe 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -1,9 +1,9 @@ package blackjack.model.playable.impl import blackjack.model.Players -import blackjack.model.Referee import blackjack.model.card.Cards import blackjack.model.pack.Pack +import blackjack.model.playable.BlackjackScore import blackjack.model.playable.Playable import blackjack.model.playable.PlayableReaction import blackjack.model.playable.PlayableResult @@ -14,7 +14,7 @@ class Dealer( val cards: Cards = Cards(), ) : Playable { - override fun score(): Int { + override fun score(): BlackjackScore { return cards.totalScore() } @@ -35,17 +35,17 @@ class Dealer( return PlayableReaction.STAND } - override fun result(playable: Playable): PlayableResult { - TODO("Not yet implemented") + override fun result(other: Playable): PlayableResult { + return this.score() vs other.score() } override fun isBurst(): Boolean { - return this.score() > Referee.BLACK_JACK_SCORE + return this.score().isBurst() } - fun dealerResult(players: Players): Pair { + fun dealerResult(players: Players): DealerResult { val results = players.values.map { it -> this.result(it) } - return this to DealerResult( + return DealerResult( score = this.score(), winningCount = results.count { it == PlayableResult.WIN }, drawingCount = results.count { it == PlayableResult.DRAW }, diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index ed027c6b92..ffd4e3886a 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -1,8 +1,8 @@ package blackjack.model.playable.impl -import blackjack.model.Referee import blackjack.model.card.Cards import blackjack.model.pack.Pack +import blackjack.model.playable.BlackjackScore import blackjack.model.playable.Playable import blackjack.model.playable.PlayableReaction import blackjack.model.playable.PlayableResult @@ -13,7 +13,7 @@ class Player( val cards: Cards = Cards.emptyCards(), ) : Playable { - override fun score(): Int { + override fun score(): BlackjackScore { return this.cards.totalScore() } @@ -30,21 +30,15 @@ class Player( return PlayableReaction.STAND } - fun hit(pack: Pack) { - cards.add(pack.pickCard()) + override fun result(other: Playable): PlayableResult { + return this.score() vs other.score() } - override fun result(playable: Playable): PlayableResult { - if (this.score() == playable.score()) { - return PlayableResult.DRAW - } - if (this.score() > playable.score()) { - return PlayableResult.WIN - } - return PlayableResult.LOSE + fun hit(pack: Pack) { + cards.add(pack.pickCard()) } override fun isBurst(): Boolean { - return this.score() > Referee.BLACK_JACK_SCORE + return this.score().isBurst() } } diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt index 5c70efb46f..54ed21d4df 100644 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt @@ -1,9 +1,10 @@ package blackjack.model.playblestrategy.impl +import blackjack.model.playable.BlackjackScore import blackjack.model.playblestrategy.PlayingStrategy -class DealerStrategy( - private val currentScore: Int, +data class DealerStrategy( + private val currentScore: BlackjackScore, ) : PlayingStrategy { override fun isHit(): Boolean { @@ -11,6 +12,6 @@ class DealerStrategy( } companion object { - private const val DEALER_PICK_THRESHOLD = 16 + private val DEALER_PICK_THRESHOLD = BlackjackScore(16) } } diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index 325a046f7c..2098732f63 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,7 +1,9 @@ package blackjack.model.result +import blackjack.model.playable.BlackjackScore + data class DealerResult( - val score: Int, + val score: BlackjackScore, val winningCount: Int, val drawingCount: Int, val losingCount: Int, From 73e3a94871f978658e3b9e5fe84cbde1a02c570c Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:21:34 +0900 Subject: [PATCH 40/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=EC=9D=98=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EB=82=98?= =?UTF-8?q?=ED=83=80=EB=82=B4=EB=8A=94=20=EB=B0=A9=EB=B2=95=EC=9D=84=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=ED=95=B4=EC=84=9C=20=EC=9E=85=EB=A0=A5=20arg?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B0=9B=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=A5=BC=20=EB=B3=80=EA=B2=BD=ED=95=98=EC=98=80=EC=8A=B5?= =?UTF-8?q?=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 6 ++---- src/main/kotlin/blackjack/view/OutputView.kt | 12 +++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index c3984268a6..5a715f5f95 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -2,7 +2,6 @@ package blackjack import blackjack.model.BlackJackGame import blackjack.model.pack.impl.ShuffledPack -import blackjack.model.result.DealerResult import blackjack.view.InputView import blackjack.view.OutputView @@ -11,8 +10,7 @@ fun main() { participants.dealing(ShuffledPack) OutputView.dealing(participants) OutputView.presentCards(participants) - val game = BlackJackGame(participants) - game.start() + BlackJackGame(participants).start() OutputView.presentScores(participants) - OutputView.presentResult(DealerResult.a()) + OutputView.presentResult(participants) } diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index d36f6518e3..c59956101a 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,6 +1,7 @@ package blackjack.view import blackjack.model.Participants +import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import blackjack.model.result.DealerResult import blackjack.view.Console.presentDealers @@ -27,11 +28,16 @@ object OutputView { println("딜러와 ${participants.names()} 에게 2 장씩 나누었습니다.") } - fun playerCardPresent(it: Player) { - println(it.presentPlayers()) + fun presentResult(participants: Participants) { + presentDealerResult(participants.dealer.dealerResult(participants.players)) + participants.players.values.forEach { it -> presentPlayerResult(it, participants.dealer) } } - fun presentResult(dealerResult: DealerResult) { + private fun presentPlayerResult(player: Player, dealer: Dealer) { + println("${player.name} : ${player.result(dealer)}") + } + + private fun presentDealerResult(dealerResult: DealerResult) { println("## 최종 승패") if (hasDraw(dealerResult)) { presentResultWithDraw(dealerResult) From 0f0ea7d74e27694763831b01a4d36fcf69d8d527 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:22:57 +0900 Subject: [PATCH 41/81] =?UTF-8?q?refactor=20:=20burst=20=EC=97=AC=EB=B6=80?= =?UTF-8?q?=EB=A5=BC=20=EC=99=B8=EB=B6=80=EC=9D=98=20=EA=B0=9D=EC=B2=B4(Re?= =?UTF-8?q?feree)=20=EA=B0=80=20=EA=B0=92=EC=9D=84=20=EA=BA=BC=EB=82=B4?= =?UTF-8?q?=EC=84=9C=20=ED=8C=90=EB=8B=A8=ED=95=B4=EC=A3=BC=EB=8D=98=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=EB=B0=A9=EC=8B=9D=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=98=EC=98=80=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 객체가 메서드를 이용해서 자체적으로 버스트 여부를 판단하도록 수정하였습니다 --- src/main/kotlin/blackjack/model/Participants.kt | 2 +- src/main/kotlin/blackjack/model/Players.kt | 2 +- src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index cd5adbd545..d75c16e4d0 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -14,7 +14,7 @@ class Participants( } private fun isGameOver(): Boolean { - return players.isGameOver() || Referee.isBurst(dealer) + return players.isGameOver() || dealer.isBurst() } fun isContinue(): Boolean { diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index f5027c30b3..4168d0e6a9 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -17,7 +17,7 @@ class Players( } fun isGameOver(): Boolean { - return values.any { Referee.isBurst(it) } + return values.any { it.isBurst() } } fun count(): Int { diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 698000fdea..08e2c09256 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -2,6 +2,7 @@ package blackjack.model.playable.impl import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.playable.BlackjackScore import blackjack.model.playblestrategy.impl.DealerStrategy import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContain @@ -13,7 +14,7 @@ class DealerTest : StringSpec({ val dealer = Dealer( CardFixture.makeCards(CardFixture.king, CardFixture.six) ) - dealer.playing(DealerStrategy(16), ShuffledPack) + dealer.playing(DealerStrategy(BlackjackScore(16)), ShuffledPack) dealer.cards.cards shouldContain CardFixture.king dealer.cards.cards shouldContain CardFixture.six @@ -24,7 +25,7 @@ class DealerTest : StringSpec({ val dealer = Dealer( CardFixture.makeCards(CardFixture.king, CardFixture.seven) ) - dealer.playing(DealerStrategy(17), ShuffledPack) + dealer.playing(DealerStrategy(BlackjackScore(17)), ShuffledPack) dealer.cards.cards shouldContain CardFixture.king dealer.cards.cards shouldContain CardFixture.seven From 8481f0ef6a8811b4736f3abdc67cd2b78369d316 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:40:46 +0900 Subject: [PATCH 42/81] =?UTF-8?q?refactor=20:=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=EC=9D=84=20=ED=95=98=EB=8B=A4=20=EB=B3=B4?= =?UTF-8?q?=EB=8B=88=20=EC=8B=AC=ED=8C=90=20=EC=97=AD=ED=95=A0=EC=9D=84=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20Referee=20=EB=A5=BC=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=ED=95=A0=EC=88=98=20=EC=9E=88=EA=B2=8C=20=EB=90=98=EC=97=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 생각을 해보니 Referee 클래스는 다른 클래스(player, Dealer) 의 값을 외부로 꺼내서 계산해주는 역할이기 때문에, 외부로 꺼내지 않고, 객체 내부에서 판단할수 있도록 리팩토링한 결과 해당 클래스는 삭제되었습니다 --- src/main/kotlin/blackjack/model/Referee.kt | 37 -------------- .../kotlin/blackjack/model/RefereeTest.kt | 51 ------------------- 2 files changed, 88 deletions(-) delete mode 100644 src/main/kotlin/blackjack/model/Referee.kt delete mode 100644 src/test/kotlin/blackjack/model/RefereeTest.kt diff --git a/src/main/kotlin/blackjack/model/Referee.kt b/src/main/kotlin/blackjack/model/Referee.kt deleted file mode 100644 index 5167d16e9c..0000000000 --- a/src/main/kotlin/blackjack/model/Referee.kt +++ /dev/null @@ -1,37 +0,0 @@ -package blackjack.model - -import blackjack.model.playable.Playable - -object Referee { - - const val BLACK_JACK_SCORE: Int = 21 - - fun isBurst(playable: Playable): Boolean { - return playable.score() >= BLACK_JACK_SCORE - } - -// fun blackJackResult(participants: Participants): DealerResult { -// if (participants.dealer.isBurst()) { -// return DealerResult.burst(participants.dealer, participants) -// } -// -// } - - // val playerResults = getPlayerResults(participants) - -// private fun getPlayerResults(participants: Participants): PlayersResults { -// val dealerScore = participants.dealer.score() -// return PlayersResults(participants.players.scoreBattle(dealerScore)) -// } -// -// -// fun playerResult(player: Player, dealerScore: Int): PlayableResult { -// if (player.score() == dealerScore) { -// return PlayableResult.DRAW -// } -// if (player.score() > dealerScore) { -// return PlayableResult.WIN -// } -// return PlayableResult.LOSE -// } -} diff --git a/src/test/kotlin/blackjack/model/RefereeTest.kt b/src/test/kotlin/blackjack/model/RefereeTest.kt deleted file mode 100644 index 813a332a44..0000000000 --- a/src/test/kotlin/blackjack/model/RefereeTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package blackjack.model - -import blackjack.model.card.CardFixture -import blackjack.model.playable.impl.Player -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe - -class RefereeTest : StringSpec({ - - "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 블랙잭이 아니어야만 한다" { - val player = Player( - "kim", - CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) - ) - Referee.isBurst(player) shouldBe false - } - - "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭으로 계산 되어야 한다" { - val player = Player( - "kim", - CardFixture.makeCards(CardFixture.ace1, CardFixture.king) - ) - Referee.isBurst(player) shouldBe true - } - -// "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { -// val player1 = Player( -// "seoul", -// CardFixture.makeCards(CardFixture.ace1, CardFixture.king) -// -// ) -// val player2 = Player( -// "wonju", -// CardFixture.makeCards(CardFixture.queen, CardFixture.king) -// -// ) -// val dealer = Dealer( -// CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) -// -// ) -// val participants = Participants(Players(player1, player2), dealer) -// val actual = Referee.blackJackResult(participants) -// -// actual.dealerResult().score shouldBe 22 -// actual.dealerResult().dealerWinningCount shouldBe 0 -// actual.dealerResult().dealerLosingCount shouldBe 2 -// -// actual.playerResult(player1) shouldBe PlayableResult.WIN -// actual.playerResult(player2) shouldBe PlayableResult.WIN -// } -}) From 9df4b9787d625881b64babde5bb96232412edc88 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 10:41:30 +0900 Subject: [PATCH 43/81] =?UTF-8?q?refactor=20:=20=EB=8A=98=EC=96=B4?= =?UTF-8?q?=EB=82=9C=20player,=20Dealer=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=9D=98=20=EC=B1=85=EC=9E=84=EA=B3=BC=20=EC=97=AD=ED=95=A0?= =?UTF-8?q?=EC=9D=84=20=EA=B2=80=EC=A6=9D=ED=95=98=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EB=8B=A8=EC=9C=84=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=8F=84=20=EC=B6=94=EA=B0=80=EB=90=98=EC=97=88=EC=8A=B5?= =?UTF-8?q?=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/impl/DealerTest.kt | 26 +++++++++++++++++++ .../model/playable/impl/PlayerTest.kt | 20 ++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 08e2c09256..b4540416ae 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,5 +1,6 @@ package blackjack.model.playable.impl +import blackjack.model.Players import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playable.BlackjackScore @@ -31,4 +32,29 @@ class DealerTest : StringSpec({ dealer.cards.cards shouldContain CardFixture.seven dealer.countOfCards() shouldBe 2 } + + "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { + val player1 = Player( + "seoul", + CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + + ) + val player2 = Player( + "wonju", + CardFixture.makeCards(CardFixture.queen, CardFixture.king) + + ) + val dealer = Dealer( + CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) + ) + + val actualDealerResult = dealer.dealerResult( + Players(player1, player2) + ) + + actualDealerResult.score shouldBe BlackjackScore(22) + actualDealerResult.winningCount shouldBe 0 + actualDealerResult.drawingCount shouldBe 0 + actualDealerResult.losingCount shouldBe 2 + } }) diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 2ba7574290..a5258f5728 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -1,6 +1,8 @@ package blackjack.model.playable.impl +import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.playable.BlackjackScore import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -22,4 +24,22 @@ class PlayerTest : StringSpec({ player.cards.count() shouldBe 1 } } + + "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 스코어가 12 이어야 만 한다" { + val player = Player( + "kim", + CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) + ) + player.isBurst() shouldBe false + player.score() shouldBe BlackjackScore(12) + } + + "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭 점수인 21 로 계산 되어야 한다" { + val player = Player( + "kong", + CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + ) + player.isBurst() shouldBe false + player.score() shouldBe BlackjackScore(21) + } }) From bc61788ef081244fb1fa0edc57f7ac99962ce1af Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 11:00:51 +0900 Subject: [PATCH 44/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=EC=9D=98=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EB=94=9C=EB=9F=AC=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=82=B4=EB=B6=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B2=B0=EC=A0=95=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/playable/BlackjackScore.kt | 8 +++++--- .../kotlin/blackjack/model/playable/impl/Dealer.kt | 8 +------- src/main/kotlin/blackjack/model/result/DealerResult.kt | 10 ++++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt index 20a64544a9..eb059495d7 100644 --- a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt +++ b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt @@ -1,7 +1,5 @@ package blackjack.model.playable -import blackjack.model.Referee - @JvmInline value class BlackjackScore( private val value: Int @@ -17,10 +15,14 @@ value class BlackjackScore( } fun isBurst(): Boolean { - return this.value > Referee.BLACK_JACK_SCORE + return this.value > BLACK_JACK_SCORE } operator fun compareTo(other: BlackjackScore): Int { return this.value.compareTo(other.value) } + + companion object { + private const val BLACK_JACK_SCORE: Int = 21 + } } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index a9ab4056fe..4e1c76dc53 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -44,12 +44,6 @@ class Dealer( } fun dealerResult(players: Players): DealerResult { - val results = players.values.map { it -> this.result(it) } - return DealerResult( - score = this.score(), - winningCount = results.count { it == PlayableResult.WIN }, - drawingCount = results.count { it == PlayableResult.DRAW }, - losingCount = results.count { it == PlayableResult.LOSE } - ) + return DealerResult.of(players.values.map { this.result(it) }, this.score()) } } diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index 2098732f63..cfe6a0d160 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,6 +1,7 @@ package blackjack.model.result import blackjack.model.playable.BlackjackScore +import blackjack.model.playable.PlayableResult data class DealerResult( val score: BlackjackScore, @@ -9,8 +10,13 @@ data class DealerResult( val losingCount: Int, ) { companion object { - fun a(): DealerResult { - TODO("Not yet implemented") + fun of(playerResults: List, score: BlackjackScore): DealerResult { + return DealerResult( + score = score, + winningCount = playerResults.count { it == PlayableResult.LOSE }, + drawingCount = playerResults.count { it == PlayableResult.DRAW }, + losingCount = playerResults.count { it == PlayableResult.WIN } + ) } } } From a0f1238d5ec0f7b48a73884e2749c9474e129804 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 11:16:45 +0900 Subject: [PATCH 45/81] =?UTF-8?q?refactor=20:=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EB=8A=94=20=ED=83=88?= =?UTF-8?q?=EB=9D=BD=ED=95=A0=EB=95=8C=EA=B9=8C=EC=A7=80=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EB=B0=9B=EC=9D=84=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/BlackJackGame.kt | 8 +++----- src/main/kotlin/blackjack/model/Participants.kt | 2 +- src/main/kotlin/blackjack/model/Players.kt | 5 +++-- src/main/kotlin/blackjack/view/OutputView.kt | 8 ++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/blackjack/model/BlackJackGame.kt b/src/main/kotlin/blackjack/model/BlackJackGame.kt index fb4c2082bc..cf0837dcaf 100644 --- a/src/main/kotlin/blackjack/model/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/BlackJackGame.kt @@ -1,9 +1,9 @@ package blackjack.model import blackjack.model.pack.impl.ShuffledPack -import blackjack.model.playable.PlayableReaction import blackjack.model.playblestrategy.impl.DealerStrategy import blackjack.view.InputView +import blackjack.view.OutputView class BlackJackGame( private val participants: Participants, @@ -18,9 +18,7 @@ class BlackJackGame( participants.players.values.forEach { it.playing(InputView.askHit(it), ShuffledPack) } - when (participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack)) { - PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") - PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") - } + val playing = participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack) + OutputView.presentDealerAction(playing) } } diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index d75c16e4d0..b61a66ab63 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -14,7 +14,7 @@ class Participants( } private fun isGameOver(): Boolean { - return players.isGameOver() || dealer.isBurst() + return players.hasAnyAlivePlayer() || dealer.isBurst() } fun isContinue(): Boolean { diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 4168d0e6a9..c236d51583 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -16,8 +16,9 @@ class Players( values.forEach { it.dealing(pack) } } - fun isGameOver(): Boolean { - return values.any { it.isBurst() } + fun hasAnyAlivePlayer(): Boolean { + val burstPlayers: List = values.map { it.isBurst() }.toList() + return !burstPlayers.contains(false) } fun count(): Int { diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index c59956101a..abdb6865c1 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,6 +1,7 @@ package blackjack.view import blackjack.model.Participants +import blackjack.model.playable.PlayableReaction import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import blackjack.model.result.DealerResult @@ -56,6 +57,13 @@ object OutputView { private fun hasDraw(dealerResult: DealerResult): Boolean { return dealerResult.drawingCount > 0 } + + fun presentDealerAction(playableReaction: PlayableReaction) { + when (playableReaction) { + PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") + PlayableReaction.STAND -> println("딜러는 17이상이라 카드를 받지 않았습니다.") + } + } } private fun Participants.presentPlayers(): String { From 57bc00ce16d86da0f5b3cb433b1e3d475d0cb290 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 11:55:17 +0900 Subject: [PATCH 46/81] =?UTF-8?q?refactor=20:=20=EC=9D=B8=ED=85=94?= =?UTF-8?q?=EB=A6=AC=EC=A0=9C=EC=9D=B4=20=EC=9B=8C=EB=8B=9D=EC=9D=B4=20?= =?UTF-8?q?=EB=9C=A8=EC=A7=80=EC=95=8A=EB=8F=84=EB=A1=9D=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=A0=EB=A5=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/playable/impl/Player.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index ffd4e3886a..3682a2be93 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -1,5 +1,6 @@ package blackjack.model.playable.impl +import blackjack.model.BlackJackStatus import blackjack.model.card.Cards import blackjack.model.pack.Pack import blackjack.model.playable.BlackjackScore @@ -11,6 +12,7 @@ import blackjack.model.playblestrategy.PlayingStrategy class Player( val name: String, val cards: Cards = Cards.emptyCards(), + var blackJackStatus: BlackJackStatus = BlackJackStatus.ALIVE, ) : Playable { override fun score(): BlackjackScore { @@ -23,6 +25,7 @@ class Player( } override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { + if (playingStrategy.isHit()) { this.hit(pack) return PlayableReaction.HIT @@ -30,8 +33,8 @@ class Player( return PlayableReaction.STAND } - override fun result(other: Playable): PlayableResult { - return this.score() vs other.score() + override fun result(playable: Playable): PlayableResult { + return this.score() vs playable.score() } fun hit(pack: Pack) { From f96536dd547616a8df1a15e8a9d4b1e7b0afaffb Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:08:03 +0900 Subject: [PATCH 47/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=20=EA=B2=8C=EC=9E=84=EC=9D=98=20=EB=A3=B0=EC=9D=B8,?= =?UTF-8?q?=20=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EC=A4=91=20=EC=B5=9C?= =?UTF-8?q?=ED=9B=84=ED=9D=AC=20=ED=95=9C=EB=AA=85=EC=9D=B4=20=EB=82=A8?= =?UTF-8?q?=EC=9D=84=EB=95=8C=EA=B9=8C=EC=A7=80=20=EC=B9=B4=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EC=9D=84=20=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/BlackJackGame.kt | 23 +++++++++++++------ .../kotlin/blackjack/model/BlackJackStatus.kt | 6 +++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/BlackJackStatus.kt diff --git a/src/main/kotlin/blackjack/model/BlackJackGame.kt b/src/main/kotlin/blackjack/model/BlackJackGame.kt index cf0837dcaf..68177c7d54 100644 --- a/src/main/kotlin/blackjack/model/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/BlackJackGame.kt @@ -1,24 +1,33 @@ package blackjack.model -import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.pack.Pack +import blackjack.model.playblestrategy.PlayingStrategy import blackjack.model.playblestrategy.impl.DealerStrategy import blackjack.view.InputView import blackjack.view.OutputView class BlackJackGame( private val participants: Participants, + private val pack: Pack, ) { fun start() { while (participants.isContinue()) { - playingBlackJack(participants) + playingBlackJackTurn(pack) } } - private fun playingBlackJack(participants: Participants) { - participants.players.values.forEach { - it.playing(InputView.askHit(it), ShuffledPack) - } - val playing = participants.dealer.playing(DealerStrategy(participants.dealer.score()), ShuffledPack) + private fun playingBlackJackTurn(pack: Pack) { + playersTurn(pack) + val dealerScore = participants.dealer.score() + dealerTurn(DealerStrategy(dealerScore), pack) + } + + private fun dealerTurn(playingStrategy: PlayingStrategy, pack: Pack) { + val playing = participants.dealer.playing(playingStrategy, pack) OutputView.presentDealerAction(playing) } + + private fun playersTurn(pack: Pack) { + participants.players.playingTurn(InputView.askHit(), pack) + } } diff --git a/src/main/kotlin/blackjack/model/BlackJackStatus.kt b/src/main/kotlin/blackjack/model/BlackJackStatus.kt new file mode 100644 index 0000000000..a414e3ee4e --- /dev/null +++ b/src/main/kotlin/blackjack/model/BlackJackStatus.kt @@ -0,0 +1,6 @@ +package blackjack.model + +enum class BlackJackStatus { + ALIVE, + DIE, +} From caf5ab42910e6edf94a72af7f484ccc92bbf1570 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:09:12 +0900 Subject: [PATCH 48/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=20=EA=B2=8C=EC=9E=84=EC=97=90=EC=84=9C=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=EB=BD=91=EB=8A=94=20=EC=A0=95=EC=B1=85?= =?UTF-8?q?=EC=9D=84=20=EC=99=B8=EB=B6=80=EC=97=90=EC=84=9C=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 5a715f5f95..8ef261c7ef 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -10,7 +10,7 @@ fun main() { participants.dealing(ShuffledPack) OutputView.dealing(participants) OutputView.presentCards(participants) - BlackJackGame(participants).start() + BlackJackGame(participants, ShuffledPack).start() OutputView.presentScores(participants) OutputView.presentResult(participants) } From d15d30eb877898e4c126df642cff7c375feb16be Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:10:15 +0900 Subject: [PATCH 49/81] =?UTF-8?q?=20=20=20=20refactor=20:=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/view/InputView.kt | 12 ++++++++++-- src/main/kotlin/blackjack/view/OutputView.kt | 15 --------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 9881dfcb84..da92b582f6 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -34,11 +34,19 @@ object InputView { return (readlnOrNull() ?: "") == HIT_COMMAND } - fun askHit(it: Player): PlayingStrategy { - println("${it.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") + fun askHit(): PlayingStrategy { + println("플레이어는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") if (this.isHitInput()) { return HitStrategy } return StandStrategy } + //TODO +// fun askHit(it: Player): PlayingStrategy { +// println("${it.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") +// if (this.isHitInput()) { +// return HitStrategy +// } +// return StandStrategy +// } } diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index abdb6865c1..6ee68b0784 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -40,24 +40,9 @@ object OutputView { private fun presentDealerResult(dealerResult: DealerResult) { println("## 최종 승패") - if (hasDraw(dealerResult)) { - presentResultWithDraw(dealerResult) - } - presentResultWithoutDraw(dealerResult) - } - - private fun presentResultWithoutDraw(dealerResult: DealerResult) { println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.drawingCount}패") } - private fun presentResultWithDraw(dealerResult: DealerResult) { - println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}패") - } - - private fun hasDraw(dealerResult: DealerResult): Boolean { - return dealerResult.drawingCount > 0 - } - fun presentDealerAction(playableReaction: PlayableReaction) { when (playableReaction) { PlayableReaction.HIT -> println("딜러는 16이하라 한장의 카드를 더 받았습니다.") From 149d5491783a7401341394cc7e4d884939264f80 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:10:44 +0900 Subject: [PATCH 50/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=EC=9D=98=20=EC=83=81=ED=83=9C=EB=A5=BC=20=EB=82=98?= =?UTF-8?q?=ED=83=80=EB=82=B4=EB=8A=94=20=EB=B3=80=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 17 +++++++++++++++-- .../blackjack/model/playable/impl/Player.kt | 7 +++++-- .../blackjack/model/playable/impl/PlayerTest.kt | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index c236d51583..72b42973d7 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -2,6 +2,7 @@ package blackjack.model import blackjack.model.pack.Pack import blackjack.model.playable.impl.Player +import blackjack.model.playblestrategy.PlayingStrategy class Players( val values: Set, @@ -17,11 +18,23 @@ class Players( } fun hasAnyAlivePlayer(): Boolean { - val burstPlayers: List = values.map { it.isBurst() }.toList() - return !burstPlayers.contains(false) + val burstPlayers: List = values.map { it.isAlive() == BlackJackStatus.ALIVE }.toList() + return burstPlayers.contains(true) } fun count(): Int { return values.size } + + fun playingTurn(playingStrategy: PlayingStrategy, pack: Pack) { + values.forEach { + if (this.isAlive(it)) { + it.playing(playingStrategy, pack) + } + } + } + + private fun isAlive(player: Player): Boolean { + return player.isAlive() == BlackJackStatus.ALIVE + } } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index 3682a2be93..212eef1fb3 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -41,7 +41,10 @@ class Player( cards.add(pack.pickCard()) } - override fun isBurst(): Boolean { - return this.score().isBurst() + override fun isAlive(): BlackJackStatus { + if (this.score().isBurst()) { + return BlackJackStatus.DIE + } + return BlackJackStatus.ALIVE } } diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index a5258f5728..2f544d9451 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -30,7 +30,7 @@ class PlayerTest : StringSpec({ "kim", CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) ) - player.isBurst() shouldBe false + player.isAlive() shouldBe false player.score() shouldBe BlackjackScore(12) } @@ -39,7 +39,7 @@ class PlayerTest : StringSpec({ "kong", CardFixture.makeCards(CardFixture.ace1, CardFixture.king) ) - player.isBurst() shouldBe false + player.isAlive() shouldBe false player.score() shouldBe BlackjackScore(21) } }) From fd791411a228ace29d82034262c8f447aeb0d0bc Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:11:12 +0900 Subject: [PATCH 51/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=20=EA=B2=8C=EC=9E=84=EC=97=90=EC=84=9C=20=ED=94=8C?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=EC=9D=98=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EB=A5=BC=20=ED=99=95=EC=9D=B8=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Participants.kt | 6 +----- src/main/kotlin/blackjack/model/playable/Playable.kt | 3 ++- .../kotlin/blackjack/model/playable/impl/Dealer.kt | 12 ++++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/Participants.kt index b61a66ab63..a788d65e93 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/Participants.kt @@ -13,12 +13,8 @@ class Participants( dealer.dealing(pack) } - private fun isGameOver(): Boolean { - return players.hasAnyAlivePlayer() || dealer.isBurst() - } - fun isContinue(): Boolean { - return !isGameOver() + return players.hasAnyAlivePlayer() && dealer.isNotBurst() } fun count(): Int { diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt index 6af199a345..8dcd91c1e9 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -1,5 +1,6 @@ package blackjack.model.playable +import blackjack.model.BlackJackStatus import blackjack.model.pack.Pack import blackjack.model.playblestrategy.PlayingStrategy @@ -8,5 +9,5 @@ interface Playable { fun dealing(pack: Pack) fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction fun result(playable: Playable): PlayableResult - fun isBurst(): Boolean + fun isAlive(): BlackJackStatus } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index 4e1c76dc53..0a29354712 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -1,5 +1,6 @@ package blackjack.model.playable.impl +import blackjack.model.BlackJackStatus import blackjack.model.Players import blackjack.model.card.Cards import blackjack.model.pack.Pack @@ -39,11 +40,18 @@ class Dealer( return this.score() vs other.score() } - override fun isBurst(): Boolean { - return this.score().isBurst() + override fun isAlive(): BlackJackStatus { + if (this.score().isBurst()) { + return BlackJackStatus.DIE + } + return BlackJackStatus.ALIVE } fun dealerResult(players: Players): DealerResult { return DealerResult.of(players.values.map { this.result(it) }, this.score()) } + + fun isNotBurst(): Boolean { + return !this.score().isBurst() + } } From 92ec4b58034f4270dbbfe85278d759bb3402cf75 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:35:28 +0900 Subject: [PATCH 52/81] =?UTF-8?q?refactor=20:=20=EB=94=9C=EB=9F=AC?= =?UTF-8?q?=EC=99=80=20=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=EA=B0=80=20?= =?UTF-8?q?=EC=83=9D=EC=A1=B4=EC=97=AC=EB=B6=80=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20=EC=83=81=ED=83=9C=EB=A5=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EC=A7=80=20=EC=95=8A=EA=B3=A0=20=EB=A7=A4?= =?UTF-8?q?=EB=B2=88=20=EA=B3=84=EC=82=B0=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 8 +-- .../blackjack/model/playable/Playable.kt | 3 +- .../blackjack/model/playable/impl/Dealer.kt | 8 ++- .../blackjack/model/playable/impl/Player.kt | 10 ++-- .../model/playable/impl/PlayerTest.kt | 57 ++++++++++++++++++- 5 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 72b42973d7..608b46c72c 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -18,7 +18,7 @@ class Players( } fun hasAnyAlivePlayer(): Boolean { - val burstPlayers: List = values.map { it.isAlive() == BlackJackStatus.ALIVE }.toList() + val burstPlayers: List = values.map { it.status() == BlackJackStatus.ALIVE }.toList() return burstPlayers.contains(true) } @@ -28,13 +28,9 @@ class Players( fun playingTurn(playingStrategy: PlayingStrategy, pack: Pack) { values.forEach { - if (this.isAlive(it)) { + if (it.status() == BlackJackStatus.ALIVE) { it.playing(playingStrategy, pack) } } } - - private fun isAlive(player: Player): Boolean { - return player.isAlive() == BlackJackStatus.ALIVE - } } diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt index 8dcd91c1e9..5c6a222a01 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -9,5 +9,6 @@ interface Playable { fun dealing(pack: Pack) fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction fun result(playable: Playable): PlayableResult - fun isAlive(): BlackJackStatus + fun isBurst(): Boolean + fun status(): BlackJackStatus } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index 0a29354712..a542a9a7c3 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -40,18 +40,22 @@ class Dealer( return this.score() vs other.score() } - override fun isAlive(): BlackJackStatus { + override fun status(): BlackJackStatus { if (this.score().isBurst()) { return BlackJackStatus.DIE } return BlackJackStatus.ALIVE } + override fun isBurst(): Boolean { + return this.score().isBurst() + } + fun dealerResult(players: Players): DealerResult { return DealerResult.of(players.values.map { this.result(it) }, this.score()) } fun isNotBurst(): Boolean { - return !this.score().isBurst() + return !this.isBurst() } } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index 212eef1fb3..7ed29552f4 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -12,7 +12,6 @@ import blackjack.model.playblestrategy.PlayingStrategy class Player( val name: String, val cards: Cards = Cards.emptyCards(), - var blackJackStatus: BlackJackStatus = BlackJackStatus.ALIVE, ) : Playable { override fun score(): BlackjackScore { @@ -25,7 +24,6 @@ class Player( } override fun playing(playingStrategy: PlayingStrategy, pack: Pack): PlayableReaction { - if (playingStrategy.isHit()) { this.hit(pack) return PlayableReaction.HIT @@ -37,12 +35,16 @@ class Player( return this.score() vs playable.score() } + override fun isBurst(): Boolean { + return this.score().isBurst() + } + fun hit(pack: Pack) { cards.add(pack.pickCard()) } - override fun isAlive(): BlackJackStatus { - if (this.score().isBurst()) { + override fun status(): BlackJackStatus { + if (this.isBurst()) { return BlackJackStatus.DIE } return BlackJackStatus.ALIVE diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 2f544d9451..e755d35f09 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -1,8 +1,10 @@ package blackjack.model.playable.impl +import blackjack.model.BlackJackStatus import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playable.BlackjackScore +import blackjack.model.playable.PlayableResult import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -30,7 +32,8 @@ class PlayerTest : StringSpec({ "kim", CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) ) - player.isAlive() shouldBe false + player.status() shouldBe BlackJackStatus.ALIVE + player.isBurst() shouldBe false player.score() shouldBe BlackjackScore(12) } @@ -39,7 +42,57 @@ class PlayerTest : StringSpec({ "kong", CardFixture.makeCards(CardFixture.ace1, CardFixture.king) ) - player.isAlive() shouldBe false + player.status() shouldBe BlackJackStatus.ALIVE + player.isBurst() shouldBe false player.score() shouldBe BlackjackScore(21) } + + "21이 넘는 점수의 카드를 가지고 있는 경우 Burst 상태로써 BlackJackStatus.DIE 상태 이어야한다" { + val player = Player( + "gin-tonic", + CardFixture.makeCards( + CardFixture.two, + CardFixture.three, + CardFixture.four, + CardFixture.eight, + CardFixture.nine + ) + ) + player.status() shouldBe BlackJackStatus.DIE + player.isBurst() shouldBe true + player.score() shouldBe BlackjackScore(2 + 3 + 4 + 8 + 9) + } + + "Burst 상황에서 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + ) + val actual = player.result(dealer) + actual shouldBe PlayableResult.LOSE + } + + + "Burst 가 아닌 상황에서 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.five) + ) + val actual = player.result(dealer) + actual shouldBe PlayableResult.LOSE + } + + "딜러와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + ) + + dealer.score() shouldBe BlackjackScore(21) + player.score() shouldBe BlackjackScore(21) + player.result(dealer) shouldBe PlayableResult.DRAW + } }) From 0bde0c379e7b9655515e55d0163694988b84aa03 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:35:45 +0900 Subject: [PATCH 53/81] style : style formatting --- src/main/kotlin/blackjack/view/InputView.kt | 2 +- src/main/kotlin/blackjack/view/OutputView.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index da92b582f6..93882f2541 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -41,7 +41,7 @@ object InputView { } return StandStrategy } - //TODO + // TODO // fun askHit(it: Player): PlayingStrategy { // println("${it.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") // if (this.isHitInput()) { diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 6ee68b0784..7d70413e02 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -31,7 +31,7 @@ object OutputView { fun presentResult(participants: Participants) { presentDealerResult(participants.dealer.dealerResult(participants.players)) - participants.players.values.forEach { it -> presentPlayerResult(it, participants.dealer) } + participants.players.values.forEach { presentPlayerResult(it, participants.dealer) } } private fun presentPlayerResult(player: Player, dealer: Dealer) { From b58ab33f4c9db930fcd403a51d2ca9169c5add5a Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:49:08 +0900 Subject: [PATCH 54/81] =?UTF-8?q?test=20:=20=EB=B3=80=ED=99=94=EB=90=9C=20?= =?UTF-8?q?=EC=B1=85=EC=9E=84=EA=B3=BC=20=EC=97=AD=ED=95=A0=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=8F=99=20=EB=B0=8F=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/card/CardsTest.kt | 45 +++++++++++++++++ .../model/playable/impl/DealerTest.kt | 50 +++++++++++++++++-- .../model/playable/impl/PlayerTest.kt | 27 ++-------- 3 files changed, 93 insertions(+), 29 deletions(-) diff --git a/src/test/kotlin/blackjack/model/card/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt index 34608e8715..c214f0d044 100644 --- a/src/test/kotlin/blackjack/model/card/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -1,7 +1,10 @@ package blackjack.model.card +import blackjack.model.BlackJackStatus import blackjack.model.playable.BlackjackScore +import blackjack.model.playable.impl.Player import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.shouldBe class CardsTest : StringSpec({ @@ -40,4 +43,46 @@ class CardsTest : StringSpec({ ).totalScore() actual shouldBe BlackjackScore(11 + 3 + 5) } + + "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 스코어가 12 이어야 만 한다" { + val player = Player( + "kim", + CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) + ) + player.status() shouldBe BlackJackStatus.ALIVE + player.isBurst() shouldBe false + player.score() shouldBe BlackjackScore(12) + } + + "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭 점수인 21 로 계산 되어야 한다" { + val player = Player( + "kong", + CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + ) + player.status() shouldBe BlackJackStatus.ALIVE + player.isBurst() shouldBe false + player.score() shouldBe BlackjackScore(21) + } + + "카드가 여러장 들어있는 상황에서도 합계 점수를 정확히 구해낼 수 있어야한다" { + val player = Player( + "kong", + CardFixture.makeCards( + CardFixture.ace1, + CardFixture.two, + CardFixture.three, + CardFixture.four, + CardFixture.five, + CardFixture.six, + CardFixture.seven, + CardFixture.eight, + CardFixture.nine, + CardFixture.ten, + CardFixture.king, + CardFixture.jack, + CardFixture.queen + ) + ) + player.score() shouldBeIn listOf(BlackjackScore(85), BlackjackScore(95)) + } }) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index b4540416ae..cd0872f7a1 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -4,6 +4,7 @@ import blackjack.model.Players import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playable.BlackjackScore +import blackjack.model.playable.PlayableResult import blackjack.model.playblestrategy.impl.DealerStrategy import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContain @@ -34,18 +35,18 @@ class DealerTest : StringSpec({ } "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { + val dealer = Dealer( + CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) + ) + val player1 = Player( "seoul", CardFixture.makeCards(CardFixture.ace1, CardFixture.king) - ) + val player2 = Player( "wonju", CardFixture.makeCards(CardFixture.queen, CardFixture.king) - - ) - val dealer = Dealer( - CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) ) val actualDealerResult = dealer.dealerResult( @@ -57,4 +58,43 @@ class DealerTest : StringSpec({ actualDealerResult.drawingCount shouldBe 0 actualDealerResult.losingCount shouldBe 2 } + + "딜러와 플리어이 모두가 Burst 상황이라면 플레이어 가 WIN(승리) 해야한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) + val player1 = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.four) + ) + val player2 = Player( + "martini", + CardFixture.makeCards(CardFixture.nine, CardFixture.eight, CardFixture.seven) + ) + + player1.result(dealer) shouldBe PlayableResult.WIN + player2.result(dealer) shouldBe PlayableResult.WIN + dealer.result(player1) shouldBe PlayableResult.LOSE + dealer.result(player2) shouldBe PlayableResult.LOSE + } + + "플레이어는 (Burst 가 아닌 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.five) + ) + val actual = player.result(dealer) + actual shouldBe PlayableResult.LOSE + } + + "플레이어는 딜러와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + ) + + dealer.score() shouldBe BlackjackScore(21) + player.score() shouldBe BlackjackScore(21) + player.result(dealer) shouldBe PlayableResult.DRAW + } }) diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index e755d35f09..17fc1c1720 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -27,26 +27,6 @@ class PlayerTest : StringSpec({ } } - "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 스코어가 12 이어야 만 한다" { - val player = Player( - "kim", - CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) - ) - player.status() shouldBe BlackJackStatus.ALIVE - player.isBurst() shouldBe false - player.score() shouldBe BlackjackScore(12) - } - - "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭 점수인 21 로 계산 되어야 한다" { - val player = Player( - "kong", - CardFixture.makeCards(CardFixture.ace1, CardFixture.king) - ) - player.status() shouldBe BlackJackStatus.ALIVE - player.isBurst() shouldBe false - player.score() shouldBe BlackjackScore(21) - } - "21이 넘는 점수의 카드를 가지고 있는 경우 Burst 상태로써 BlackJackStatus.DIE 상태 이어야한다" { val player = Player( "gin-tonic", @@ -63,7 +43,7 @@ class PlayerTest : StringSpec({ player.score() shouldBe BlackjackScore(2 + 3 + 4 + 8 + 9) } - "Burst 상황에서 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + "플레이어는 (Burst 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player = Player( "malibu", @@ -73,8 +53,7 @@ class PlayerTest : StringSpec({ actual shouldBe PlayableResult.LOSE } - - "Burst 가 아닌 상황에서 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + "플레이어는 (Burst 가 아닌 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) val player = Player( "malibu", @@ -84,7 +63,7 @@ class PlayerTest : StringSpec({ actual shouldBe PlayableResult.LOSE } - "딜러와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { + "플레이어는 딜러와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) val player = Player( "malibu", From 57d5ed88c3dca1261d61f5c17c6eb5a9418bad47 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:52:09 +0900 Subject: [PATCH 55/81] =?UTF-8?q?test=20:=20=ED=94=8C=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EA=B0=80=20=EC=9D=B4=EA=B8=B0=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/model/playable/impl/PlayerTest.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 17fc1c1720..41e4fdaf4a 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -38,6 +38,7 @@ class PlayerTest : StringSpec({ CardFixture.nine ) ) + player.status() shouldBe BlackJackStatus.DIE player.isBurst() shouldBe true player.score() shouldBe BlackjackScore(2 + 3 + 4 + 8 + 9) @@ -50,9 +51,20 @@ class PlayerTest : StringSpec({ CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) ) val actual = player.result(dealer) + actual shouldBe PlayableResult.LOSE } + "플레이어는 딜러보다 점수가 높은 경우 Win 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.three)) + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.jack) + ) + + player.result(dealer) shouldBe PlayableResult.WIN + } + "플레이어는 (Burst 가 아닌 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) val player = Player( From ec56d3832247b8b8ed5877de8109717c564c7597 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 12:57:23 +0900 Subject: [PATCH 56/81] =?UTF-8?q?test=20:=20=EB=94=9C=EB=9F=AC=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/impl/DealerTest.kt | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index cd0872f7a1..9fa8091f6e 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -38,17 +38,14 @@ class DealerTest : StringSpec({ val dealer = Dealer( CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) ) - val player1 = Player( "seoul", CardFixture.makeCards(CardFixture.ace1, CardFixture.king) ) - val player2 = Player( "wonju", CardFixture.makeCards(CardFixture.queen, CardFixture.king) ) - val actualDealerResult = dealer.dealerResult( Players(player1, player2) ) @@ -59,7 +56,7 @@ class DealerTest : StringSpec({ actualDealerResult.losingCount shouldBe 2 } - "딜러와 플리어이 모두가 Burst 상황이라면 플레이어 가 WIN(승리) 해야한다" { + "딜러와 플레이어 모두가 Burst 상황이라면 플레이어 가 WIN(승리) 해야한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player1 = Player( "malibu", @@ -75,18 +72,29 @@ class DealerTest : StringSpec({ dealer.result(player1) shouldBe PlayableResult.LOSE dealer.result(player2) shouldBe PlayableResult.LOSE } + "딜러는 플레이어보다 점수가 높은경우 WIN 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) // 20 + val player = Player( + "malibu", + CardFixture.makeCards(CardFixture.ten, CardFixture.five) // 15 + ) + + dealer.result(player) shouldBe PlayableResult.WIN + player.result(dealer) shouldBe PlayableResult.LOSE + } - "플레이어는 (Burst 가 아닌 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { - val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) + "딜러는 플레이어보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + val dealer = Dealer(CardFixture.makeCards(CardFixture.three, CardFixture.four)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.five) + CardFixture.makeCards(CardFixture.seven, CardFixture.five) ) - val actual = player.result(dealer) - actual shouldBe PlayableResult.LOSE + + dealer.result(player) shouldBe PlayableResult.LOSE + player.result(dealer) shouldBe PlayableResult.WIN } - "플레이어는 딜러와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { + "딜러는 플레이어와 점수가 같은 경우 DRAW 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) val player = Player( "malibu", @@ -96,5 +104,6 @@ class DealerTest : StringSpec({ dealer.score() shouldBe BlackjackScore(21) player.score() shouldBe BlackjackScore(21) player.result(dealer) shouldBe PlayableResult.DRAW + dealer.result(player) shouldBe PlayableResult.DRAW } }) From de4eb89b0f29eaf1f96989520395a937b46e76c6 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:04:12 +0900 Subject: [PATCH 57/81] =?UTF-8?q?style=20:=20=EC=8A=A4=ED=83=80=EC=9D=BC?= =?UTF-8?q?=20=ED=8F=AC=EB=A9=94=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/playable/BlackjackScore.kt | 2 +- src/main/kotlin/blackjack/model/playable/impl/Dealer.kt | 4 ++-- src/main/kotlin/blackjack/view/OutputView.kt | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt index eb059495d7..5732642342 100644 --- a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt +++ b/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt @@ -2,7 +2,7 @@ package blackjack.model.playable @JvmInline value class BlackjackScore( - private val value: Int + val value: Int ) { infix fun vs(other: BlackjackScore): PlayableResult { if (this.value == other.value) { diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index a542a9a7c3..8bb4f06fb3 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -36,8 +36,8 @@ class Dealer( return PlayableReaction.STAND } - override fun result(other: Playable): PlayableResult { - return this.score() vs other.score() + override fun result(playable: Playable): PlayableResult { + return this.score() vs playable.score() } override fun status(): BlackJackStatus { diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 7d70413e02..5a024a5f35 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,6 +1,7 @@ package blackjack.view import blackjack.model.Participants +import blackjack.model.Players import blackjack.model.playable.PlayableReaction import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player @@ -31,7 +32,11 @@ object OutputView { fun presentResult(participants: Participants) { presentDealerResult(participants.dealer.dealerResult(participants.players)) - participants.players.values.forEach { presentPlayerResult(it, participants.dealer) } + presentPlayersResult(participants.dealer, participants.players) + } + + private fun presentPlayersResult(dealer: Dealer, players: Players) { + players.values.forEach { presentPlayerResult(it, dealer) } } private fun presentPlayerResult(player: Player, dealer: Dealer) { @@ -60,7 +65,7 @@ private fun Participants.presentDealer(): String { } private fun Participants.presentDealerWithScore(): String { - return "${this.dealer.presentDealers()} - 결과: ${this.dealer.score()}" + return "${this.dealer.presentDealers()} - 결과: ${this.dealer.score().value}" } private fun Participants.presentPlayerWithScore(): String { From f7d07c5c07290046fac966a004cd13481b8d5bde Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:13:00 +0900 Subject: [PATCH 58/81] =?UTF-8?q?refactor=20:=20=EC=A0=95=EC=B1=85?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9E=85=EB=A0=A5=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/blackjack/model/BlackJackGame.kt | 3 +-- .../blackjack/model/ConsoleInputStrategy.kt | 19 ++++++++++++++ src/main/kotlin/blackjack/model/Players.kt | 5 ++-- src/main/kotlin/blackjack/view/InputView.kt | 25 +------------------ 4 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt diff --git a/src/main/kotlin/blackjack/model/BlackJackGame.kt b/src/main/kotlin/blackjack/model/BlackJackGame.kt index 68177c7d54..0a202f3c5c 100644 --- a/src/main/kotlin/blackjack/model/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/BlackJackGame.kt @@ -3,7 +3,6 @@ package blackjack.model import blackjack.model.pack.Pack import blackjack.model.playblestrategy.PlayingStrategy import blackjack.model.playblestrategy.impl.DealerStrategy -import blackjack.view.InputView import blackjack.view.OutputView class BlackJackGame( @@ -28,6 +27,6 @@ class BlackJackGame( } private fun playersTurn(pack: Pack) { - participants.players.playingTurn(InputView.askHit(), pack) + participants.players.playingTurn(pack) } } diff --git a/src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt b/src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt new file mode 100644 index 0000000000..49903dfe15 --- /dev/null +++ b/src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt @@ -0,0 +1,19 @@ +package blackjack.model + +import blackjack.model.playblestrategy.PlayingStrategy + +class ConsoleInputStrategy : PlayingStrategy { + + override fun isHit(): Boolean { + println("플레이어는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") + return this.isHitInput() + } + + private fun isHitInput(): Boolean { + return (readlnOrNull() ?: "") == HIT_COMMAND + } + + companion object { + private const val HIT_COMMAND: String = "y" + } +} diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 608b46c72c..d801a2610d 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -2,7 +2,6 @@ package blackjack.model import blackjack.model.pack.Pack import blackjack.model.playable.impl.Player -import blackjack.model.playblestrategy.PlayingStrategy class Players( val values: Set, @@ -26,10 +25,10 @@ class Players( return values.size } - fun playingTurn(playingStrategy: PlayingStrategy, pack: Pack) { + fun playingTurn(pack: Pack) { values.forEach { if (it.status() == BlackJackStatus.ALIVE) { - it.playing(playingStrategy, pack) + it.playing(ConsoleInputStrategy(), pack) } } } diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 93882f2541..c13dc3b789 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -4,13 +4,10 @@ import blackjack.model.Participants import blackjack.model.Players import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player -import blackjack.model.playblestrategy.PlayingStrategy -import blackjack.model.playblestrategy.impl.HitStrategy -import blackjack.model.playblestrategy.impl.StandStrategy object InputView { private const val PLAYER_NAMES_DELIMITER: String = "," - private const val HIT_COMMAND: String = "y" + const val PARTICIPANTS_PRESENT_SEPARATOR: String = ", " private fun joinPlayers(input: String): Participants { @@ -29,24 +26,4 @@ object InputView { println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)") return joinPlayers(readlnOrNull() ?: "") } - - private fun isHitInput(): Boolean { - return (readlnOrNull() ?: "") == HIT_COMMAND - } - - fun askHit(): PlayingStrategy { - println("플레이어는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") - if (this.isHitInput()) { - return HitStrategy - } - return StandStrategy - } - // TODO -// fun askHit(it: Player): PlayingStrategy { -// println("${it.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") -// if (this.isHitInput()) { -// return HitStrategy -// } -// return StandStrategy -// } } From a2a5e6e923eaee250696f1db4cacbdd51b9f85f4 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:13:51 +0900 Subject: [PATCH 59/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 1 + .../model/{ => playblestrategy/impl}/ConsoleInputStrategy.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename src/main/kotlin/blackjack/model/{ => playblestrategy/impl}/ConsoleInputStrategy.kt (91%) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index d801a2610d..1c27bb1cfe 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,6 +1,7 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.model.playblestrategy.impl.ConsoleInputStrategy import blackjack.model.playable.impl.Player class Players( diff --git a/src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt similarity index 91% rename from src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt rename to src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt index 49903dfe15..bcbfff6a46 100644 --- a/src/main/kotlin/blackjack/model/ConsoleInputStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.playblestrategy.impl import blackjack.model.playblestrategy.PlayingStrategy From 1292c654bd2dfb60fedceeec9baba33eb88ddd08 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:20:40 +0900 Subject: [PATCH 60/81] =?UTF-8?q?refactor=20:=20=ED=94=8C=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 8 ++++---- .../model/playblestrategy/impl/ConsoleInputStrategy.kt | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index 1c27bb1cfe..ce0a09ef79 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,8 +1,8 @@ package blackjack.model import blackjack.model.pack.Pack -import blackjack.model.playblestrategy.impl.ConsoleInputStrategy import blackjack.model.playable.impl.Player +import blackjack.model.playblestrategy.impl.ConsoleInputStrategy class Players( val values: Set, @@ -27,9 +27,9 @@ class Players( } fun playingTurn(pack: Pack) { - values.forEach { - if (it.status() == BlackJackStatus.ALIVE) { - it.playing(ConsoleInputStrategy(), pack) + values.forEach { player -> + if (player.status() == BlackJackStatus.ALIVE) { + player.playing(ConsoleInputStrategy(player), pack) } } } diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt index bcbfff6a46..3de189e411 100644 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt +++ b/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt @@ -1,11 +1,14 @@ package blackjack.model.playblestrategy.impl +import blackjack.model.playable.impl.Player import blackjack.model.playblestrategy.PlayingStrategy -class ConsoleInputStrategy : PlayingStrategy { +class ConsoleInputStrategy( + val player: Player, +) : PlayingStrategy { override fun isHit(): Boolean { - println("플레이어는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") + println("${player.name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") return this.isHitInput() } From 3e17672936fa19d6201982515ef7a936869eb0de Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:36:01 +0900 Subject: [PATCH 61/81] =?UTF-8?q?refactor=20:=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=A0=90=EA=B2=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 6 ++++ src/main/kotlin/blackjack/view/Console.kt | 20 ------------- src/main/kotlin/blackjack/view/OutputView.kt | 30 ++++++++++++++------ 3 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 src/main/kotlin/blackjack/view/Console.kt diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index ce0a09ef79..f1d5f38ef7 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,6 +1,8 @@ package blackjack.model import blackjack.model.pack.Pack +import blackjack.model.playable.PlayableResult +import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import blackjack.model.playblestrategy.impl.ConsoleInputStrategy @@ -33,4 +35,8 @@ class Players( } } } + + fun results(dealer: Dealer): List> { + return this.values.map { it to it.result(dealer) } + } } diff --git a/src/main/kotlin/blackjack/view/Console.kt b/src/main/kotlin/blackjack/view/Console.kt deleted file mode 100644 index 7542750b68..0000000000 --- a/src/main/kotlin/blackjack/view/Console.kt +++ /dev/null @@ -1,20 +0,0 @@ -package blackjack.view - -import blackjack.model.card.Cards -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player - -object Console { - - fun Cards.presentPlayers(): String { - return cards.joinToString(separator = ", ") { "${it.cardRank.alias}${it.suit.alias}" } - } - - fun Player.presentPlayers(): String { - return "${this.name}카드 : ${this.cards.presentPlayers()}" - } - - fun Dealer.presentDealers(): String { - return "딜러 카드 : ${this.cards.presentPlayers()}" - } -} diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 5a024a5f35..ddcad258d9 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,13 +1,12 @@ package blackjack.view import blackjack.model.Participants -import blackjack.model.Players +import blackjack.model.card.Cards import blackjack.model.playable.PlayableReaction +import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import blackjack.model.result.DealerResult -import blackjack.view.Console.presentDealers -import blackjack.view.Console.presentPlayers object OutputView { @@ -31,20 +30,21 @@ object OutputView { } fun presentResult(participants: Participants) { + println("## 최종 승패") presentDealerResult(participants.dealer.dealerResult(participants.players)) - presentPlayersResult(participants.dealer, participants.players) + presentPlayersResult(participants.players.results(participants.dealer)) } - private fun presentPlayersResult(dealer: Dealer, players: Players) { - players.values.forEach { presentPlayerResult(it, dealer) } + private fun presentPlayersResult(playersResult: List>) { + playersResult.forEach { + println("${it.first.name} : ${it.second}") + } } private fun presentPlayerResult(player: Player, dealer: Dealer) { - println("${player.name} : ${player.result(dealer)}") } private fun presentDealerResult(dealerResult: DealerResult) { - println("## 최종 승패") println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.drawingCount}패") } @@ -69,9 +69,21 @@ private fun Participants.presentDealerWithScore(): String { } private fun Participants.presentPlayerWithScore(): String { - return this.players.values.joinToString(separator = "\n") { "${it.presentPlayers()} - 결과: ${it.cards.totalScore()}" } + return this.players.values.joinToString(separator = "\n") { "${it.presentPlayers()} - 결과: ${it.cards.totalScore().value}" } } private fun Participants.names(): String { return players.values.joinToString(separator = InputView.PARTICIPANTS_PRESENT_SEPARATOR) { it.name } } + +fun Cards.presentPlayers(): String { + return cards.joinToString(separator = ", ") { "${it.cardRank.alias}${it.suit.alias}" } +} + +fun Player.presentPlayers(): String { + return "${this.name}카드 : ${this.cards.presentPlayers()}" +} + +fun Dealer.presentDealers(): String { + return "딜러 카드 : ${this.cards.presentPlayers()}" +} From 9a47953a3117ec3cbd03f6aa9473115a94fe9c69 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:48:15 +0900 Subject: [PATCH 62/81] =?UTF-8?q?refactor=20:=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=A0=90=EA=B2=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/BlackjackScoreTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt diff --git a/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt b/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt new file mode 100644 index 0000000000..a52a3d2906 --- /dev/null +++ b/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt @@ -0,0 +1,18 @@ +package blackjack.model.playable + +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class BlackjackScoreTest : StringSpec({ + "이겨야한다" { + BlackjackScore(4) vs BlackjackScore(2) shouldBe PlayableResult.WIN + } + + "져야한다" { + BlackjackScore(1) vs BlackjackScore(2) shouldBe PlayableResult.LOSE + } + + "비겨야한다" { + BlackjackScore(7) vs BlackjackScore(7) shouldBe PlayableResult.DRAW + } +}) From 515e2a968586d808b6d10f354286526f780556f0 Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:50:58 +0900 Subject: [PATCH 63/81] =?UTF-8?q?refactor=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/view/OutputView.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index ddcad258d9..0a81d8891b 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -41,9 +41,6 @@ object OutputView { } } - private fun presentPlayerResult(player: Player, dealer: Dealer) { - } - private fun presentDealerResult(dealerResult: DealerResult) { println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.drawingCount}패") } From cbf46fcb86198dcd6f093bbfc81048af42e559af Mon Sep 17 00:00:00 2001 From: dong Date: Sun, 26 Nov 2023 13:59:36 +0900 Subject: [PATCH 64/81] =?UTF-8?q?feat=20:=20=EA=B2=80=EC=A6=9D=EC=9A=A9=20?= =?UTF-8?q?=ED=95=9C=EC=A4=84,=20=EB=94=94=EB=B2=84=EA=B9=85=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/Players.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index f1d5f38ef7..c5a65da5ea 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -33,6 +33,9 @@ class Players( if (player.status() == BlackJackStatus.ALIVE) { player.playing(ConsoleInputStrategy(player), pack) } +// else { +// println(" ### [검증용/삭제예정] 플레이어 ${player.name} 은 DIE 상태라 카드를 받을수 있는 기회가 주어지지 않습니다, score=${player.cards.totalScore()}") +// } } } From 953086a107076f3eef7a47d842dfaa30b8e3b293 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 27 Nov 2023 23:51:17 +0900 Subject: [PATCH 65/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 2 +- src/main/kotlin/blackjack/model/Players.kt | 5 +++-- .../blackjack/model/{ => blackjack}/BlackJackGame.kt | 3 ++- .../model/{ => blackjack}/BlackJackStatus.kt | 2 +- src/main/kotlin/blackjack/model/playable/Playable.kt | 2 +- .../kotlin/blackjack/model/playable/impl/Dealer.kt | 11 ++++++++++- .../kotlin/blackjack/model/playable/impl/Player.kt | 11 ++++++++++- .../blackjack/model/playable/impl/PlayerTest.kt | 2 +- 8 files changed, 29 insertions(+), 9 deletions(-) rename src/main/kotlin/blackjack/model/{ => blackjack}/BlackJackGame.kt (92%) rename src/main/kotlin/blackjack/model/{ => blackjack}/BlackJackStatus.kt (60%) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 8ef261c7ef..87ec2b56d5 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,6 +1,6 @@ package blackjack -import blackjack.model.BlackJackGame +import blackjack.model.blackjack.BlackJackGame import blackjack.model.pack.impl.ShuffledPack import blackjack.view.InputView import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/Players.kt index c5a65da5ea..37fba0ebfd 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/Players.kt @@ -1,5 +1,6 @@ package blackjack.model +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.pack.Pack import blackjack.model.playable.PlayableResult import blackjack.model.playable.impl.Dealer @@ -39,7 +40,7 @@ class Players( } } - fun results(dealer: Dealer): List> { - return this.values.map { it to it.result(dealer) } + fun results(dealer: Dealer): Map { + return this.values.map { player -> player to player.result(dealer) }.toMap() } } diff --git a/src/main/kotlin/blackjack/model/BlackJackGame.kt b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt similarity index 92% rename from src/main/kotlin/blackjack/model/BlackJackGame.kt rename to src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt index 0a202f3c5c..16ffa6efcf 100644 --- a/src/main/kotlin/blackjack/model/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt @@ -1,5 +1,6 @@ -package blackjack.model +package blackjack.model.blackjack +import blackjack.model.Participants import blackjack.model.pack.Pack import blackjack.model.playblestrategy.PlayingStrategy import blackjack.model.playblestrategy.impl.DealerStrategy diff --git a/src/main/kotlin/blackjack/model/BlackJackStatus.kt b/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt similarity index 60% rename from src/main/kotlin/blackjack/model/BlackJackStatus.kt rename to src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt index a414e3ee4e..d5aea497d9 100644 --- a/src/main/kotlin/blackjack/model/BlackJackStatus.kt +++ b/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt @@ -1,4 +1,4 @@ -package blackjack.model +package blackjack.model.blackjack enum class BlackJackStatus { ALIVE, diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/playable/Playable.kt index 5c6a222a01..9780cc83e3 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/playable/Playable.kt @@ -1,6 +1,6 @@ package blackjack.model.playable -import blackjack.model.BlackJackStatus +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.pack.Pack import blackjack.model.playblestrategy.PlayingStrategy diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt index 8bb4f06fb3..5f0df47603 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt @@ -1,6 +1,6 @@ package blackjack.model.playable.impl -import blackjack.model.BlackJackStatus +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.Players import blackjack.model.card.Cards import blackjack.model.pack.Pack @@ -37,6 +37,15 @@ class Dealer( } override fun result(playable: Playable): PlayableResult { + if (this.isBurst() && playable.isBurst()) { + return PlayableResult.DRAW + } + if (this.isBurst() && !playable.isBurst()) { + return PlayableResult.LOSE + } + if (!this.isBurst() && playable.isBurst()) { + return PlayableResult.WIN + } return this.score() vs playable.score() } diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/playable/impl/Player.kt index 7ed29552f4..b3654d0159 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/playable/impl/Player.kt @@ -1,6 +1,6 @@ package blackjack.model.playable.impl -import blackjack.model.BlackJackStatus +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.Cards import blackjack.model.pack.Pack import blackjack.model.playable.BlackjackScore @@ -32,6 +32,15 @@ class Player( } override fun result(playable: Playable): PlayableResult { + if (this.isBurst() && playable.isBurst()) { + return PlayableResult.DRAW + } + if (this.isBurst() && !playable.isBurst()) { + return PlayableResult.LOSE + } + if (!this.isBurst() && playable.isBurst()) { + return PlayableResult.WIN + } return this.score() vs playable.score() } diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 41e4fdaf4a..07f2b36fe3 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -1,6 +1,6 @@ package blackjack.model.playable.impl -import blackjack.model.BlackJackStatus +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.CardFixture import blackjack.model.pack.impl.ShuffledPack import blackjack.model.playable.BlackjackScore From 9bd27f77f516d38ace5c546281c460010f71758f Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 27 Nov 2023 23:51:33 +0900 Subject: [PATCH 66/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/model/card/CardsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/blackjack/model/card/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt index c214f0d044..9e6dd9b617 100644 --- a/src/test/kotlin/blackjack/model/card/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -1,6 +1,6 @@ package blackjack.model.card -import blackjack.model.BlackJackStatus +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.playable.BlackjackScore import blackjack.model.playable.impl.Player import io.kotest.core.spec.style.StringSpec From f3773b7ff8645deeb27544403c881ba5684d6e7a Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 27 Nov 2023 23:52:08 +0900 Subject: [PATCH 67/81] =?UTF-8?q?test=20:=20=EC=97=90=EB=9F=AC=EA=B0=80=20?= =?UTF-8?q?=EB=82=98=EB=8A=94=20=EB=B6=80=EB=B6=84=EC=9D=98=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/model/PlayersTest.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt index d2ed6a1fe1..2a9db8175a 100644 --- a/src/test/kotlin/blackjack/model/PlayersTest.kt +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -1,5 +1,8 @@ package blackjack.model +import blackjack.model.card.CardFixture +import blackjack.model.card.CardFixture.makeCards +import blackjack.model.playable.impl.Dealer import blackjack.model.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow @@ -18,4 +21,16 @@ class PlayersTest : StringSpec({ Players(Player("hana"), Player("numa")) } } + + "모든 플레이어가 Burst 일때, 딜러는 승리하고 모든 플레이어가 패배해야한다" { + val google = Player("google", makeCards(CardFixture.seven, CardFixture.nine, CardFixture.eight)) + val apple = Player("apple", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.three)) + val microsoft = Player("microsoft", makeCards(CardFixture.king, CardFixture.ten, CardFixture.five)) + val players = Players(setOf(google, apple, microsoft)) + val dealer = Dealer(makeCards(CardFixture.two, CardFixture.five, CardFixture.four)) + val results = players.results(dealer) + + // results shouldContain (google to PlayableResult.LOSE) + println(results) + } }) From a81cff6a484b6eade1c625b012fcdc240eb48058 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 27 Nov 2023 23:52:29 +0900 Subject: [PATCH 68/81] =?UTF-8?q?refactor=20:=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=EC=9D=84=20=EB=8A=98=EB=A6=AC=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=ED=8C=8C=EB=A6=AC=EB=AF=B8=ED=84=B0=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/view/OutputView.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 0a81d8891b..e6bef7a8d6 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -35,10 +35,10 @@ object OutputView { presentPlayersResult(participants.players.results(participants.dealer)) } - private fun presentPlayersResult(playersResult: List>) { - playersResult.forEach { - println("${it.first.name} : ${it.second}") - } + private fun presentPlayersResult(playersResult: Map) { + playersResult + .keys + .forEach { player -> println("${player.name} : ${playersResult[player]}") } } private fun presentDealerResult(dealerResult: DealerResult) { From f0a699cbaaab6ba5d8867ec7843baa1cd9489760 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 27 Nov 2023 23:54:56 +0900 Subject: [PATCH 69/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Controller.kt | 2 +- .../blackjack/model/blackjack/BlackJackGame.kt | 8 ++++---- src/main/kotlin/blackjack/model/card/Cards.kt | 2 +- .../blackjack/model/{ => card}/pack/Pack.kt | 2 +- .../model/{ => card}/pack/impl/ShuffledPack.kt | 4 ++-- .../model/playblestrategy/impl/HitStrategy.kt | 9 --------- .../model/playblestrategy/impl/StandStrategy.kt | 9 --------- .../model/{playable => player}/BlackjackScore.kt | 4 +++- .../blackjack/model/{ => player}/Participants.kt | 7 ++++--- .../{playable => player}/PlayableReaction.kt | 2 +- .../blackjack/model/{ => player}/Players.kt | 12 ++++++------ .../model/{ => player}/playable/Playable.kt | 9 ++++++--- .../model/{ => player}/playable/impl/Dealer.kt | 16 ++++++++-------- .../model/{ => player}/playable/impl/Player.kt | 14 +++++++------- .../playblestrategy/PlayingStrategy.kt | 2 +- .../playblestrategy/impl/ConsoleInputStrategy.kt | 6 +++--- .../playblestrategy/impl/DealerStrategy.kt | 6 +++--- .../player/playblestrategy/impl/HitStrategy.kt | 9 +++++++++ .../player/playblestrategy/impl/StandStrategy.kt | 9 +++++++++ .../blackjack/model/result/DealerResult.kt | 3 +-- .../model/{playable => result}/PlayableResult.kt | 2 +- src/main/kotlin/blackjack/view/InputView.kt | 8 ++++---- src/main/kotlin/blackjack/view/OutputView.kt | 10 +++++----- src/test/kotlin/blackjack/model/PlayersTest.kt | 5 +++-- .../kotlin/blackjack/model/card/CardsTest.kt | 4 ++-- .../model/pack/impl/ShuffledPackTest.kt | 1 + .../model/playable/BlackjackScoreTest.kt | 2 ++ .../blackjack/model/playable/impl/DealerTest.kt | 12 +++++++----- .../blackjack/model/playable/impl/PlayerTest.kt | 8 +++++--- 29 files changed, 100 insertions(+), 87 deletions(-) rename src/main/kotlin/blackjack/model/{ => card}/pack/Pack.kt (69%) rename src/main/kotlin/blackjack/model/{ => card}/pack/impl/ShuffledPack.kt (89%) delete mode 100644 src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt delete mode 100644 src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt rename src/main/kotlin/blackjack/model/{playable => player}/BlackjackScore.kt (88%) rename src/main/kotlin/blackjack/model/{ => player}/Participants.kt (68%) rename src/main/kotlin/blackjack/model/{playable => player}/PlayableReaction.kt (61%) rename src/main/kotlin/blackjack/model/{ => player}/Players.kt (81%) rename src/main/kotlin/blackjack/model/{ => player}/playable/Playable.kt (54%) rename src/main/kotlin/blackjack/model/{ => player}/playable/impl/Dealer.kt (81%) rename src/main/kotlin/blackjack/model/{ => player}/playable/impl/Player.kt (80%) rename src/main/kotlin/blackjack/model/{ => player}/playblestrategy/PlayingStrategy.kt (54%) rename src/main/kotlin/blackjack/model/{ => player}/playblestrategy/impl/ConsoleInputStrategy.kt (72%) rename src/main/kotlin/blackjack/model/{ => player}/playblestrategy/impl/DealerStrategy.kt (64%) create mode 100644 src/main/kotlin/blackjack/model/player/playblestrategy/impl/HitStrategy.kt create mode 100644 src/main/kotlin/blackjack/model/player/playblestrategy/impl/StandStrategy.kt rename src/main/kotlin/blackjack/model/{playable => result}/PlayableResult.kt (64%) diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 87ec2b56d5..9eea178354 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,7 +1,7 @@ package blackjack import blackjack.model.blackjack.BlackJackGame -import blackjack.model.pack.impl.ShuffledPack +import blackjack.model.card.pack.impl.ShuffledPack import blackjack.view.InputView import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt index 16ffa6efcf..7d61de3768 100644 --- a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt @@ -1,9 +1,9 @@ package blackjack.model.blackjack -import blackjack.model.Participants -import blackjack.model.pack.Pack -import blackjack.model.playblestrategy.PlayingStrategy -import blackjack.model.playblestrategy.impl.DealerStrategy +import blackjack.model.player.Participants +import blackjack.model.card.pack.Pack +import blackjack.model.player.playblestrategy.PlayingStrategy +import blackjack.model.player.playblestrategy.impl.DealerStrategy import blackjack.view.OutputView class BlackJackGame( diff --git a/src/main/kotlin/blackjack/model/card/Cards.kt b/src/main/kotlin/blackjack/model/card/Cards.kt index ae134c9fe6..30cf21ddf4 100644 --- a/src/main/kotlin/blackjack/model/card/Cards.kt +++ b/src/main/kotlin/blackjack/model/card/Cards.kt @@ -1,6 +1,6 @@ package blackjack.model.card -import blackjack.model.playable.BlackjackScore +import blackjack.model.player.BlackjackScore class Cards( cards: List = emptyList(), diff --git a/src/main/kotlin/blackjack/model/pack/Pack.kt b/src/main/kotlin/blackjack/model/card/pack/Pack.kt similarity index 69% rename from src/main/kotlin/blackjack/model/pack/Pack.kt rename to src/main/kotlin/blackjack/model/card/pack/Pack.kt index 6befb861e9..beb091ae91 100644 --- a/src/main/kotlin/blackjack/model/pack/Pack.kt +++ b/src/main/kotlin/blackjack/model/card/pack/Pack.kt @@ -1,4 +1,4 @@ -package blackjack.model.pack +package blackjack.model.card.pack import blackjack.model.card.Card diff --git a/src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt b/src/main/kotlin/blackjack/model/card/pack/impl/ShuffledPack.kt similarity index 89% rename from src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt rename to src/main/kotlin/blackjack/model/card/pack/impl/ShuffledPack.kt index 9644dded62..d24f0f1610 100644 --- a/src/main/kotlin/blackjack/model/pack/impl/ShuffledPack.kt +++ b/src/main/kotlin/blackjack/model/card/pack/impl/ShuffledPack.kt @@ -1,9 +1,9 @@ -package blackjack.model.pack.impl +package blackjack.model.card.pack.impl import blackjack.model.card.Card import blackjack.model.card.CardRank import blackjack.model.card.Suit -import blackjack.model.pack.Pack +import blackjack.model.card.pack.Pack import kotlin.random.Random object ShuffledPack : Pack { diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt deleted file mode 100644 index a638117094..0000000000 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/HitStrategy.kt +++ /dev/null @@ -1,9 +0,0 @@ -package blackjack.model.playblestrategy.impl - -import blackjack.model.playblestrategy.PlayingStrategy - -object HitStrategy : PlayingStrategy { - override fun isHit(): Boolean { - return true - } -} diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt b/src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt deleted file mode 100644 index 5ca7e758fd..0000000000 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/StandStrategy.kt +++ /dev/null @@ -1,9 +0,0 @@ -package blackjack.model.playblestrategy.impl - -import blackjack.model.playblestrategy.PlayingStrategy - -object StandStrategy : PlayingStrategy { - override fun isHit(): Boolean { - return false - } -} diff --git a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt b/src/main/kotlin/blackjack/model/player/BlackjackScore.kt similarity index 88% rename from src/main/kotlin/blackjack/model/playable/BlackjackScore.kt rename to src/main/kotlin/blackjack/model/player/BlackjackScore.kt index 5732642342..0bf9ff71e2 100644 --- a/src/main/kotlin/blackjack/model/playable/BlackjackScore.kt +++ b/src/main/kotlin/blackjack/model/player/BlackjackScore.kt @@ -1,4 +1,6 @@ -package blackjack.model.playable +package blackjack.model.player + +import blackjack.model.result.PlayableResult @JvmInline value class BlackjackScore( diff --git a/src/main/kotlin/blackjack/model/Participants.kt b/src/main/kotlin/blackjack/model/player/Participants.kt similarity index 68% rename from src/main/kotlin/blackjack/model/Participants.kt rename to src/main/kotlin/blackjack/model/player/Participants.kt index a788d65e93..6a806316a6 100644 --- a/src/main/kotlin/blackjack/model/Participants.kt +++ b/src/main/kotlin/blackjack/model/player/Participants.kt @@ -1,7 +1,8 @@ -package blackjack.model +package blackjack.model.player -import blackjack.model.pack.Pack -import blackjack.model.playable.impl.Dealer +import blackjack.model.card.pack.Pack +import blackjack.model.player.Players +import blackjack.model.player.playable.impl.Dealer class Participants( val players: Players, diff --git a/src/main/kotlin/blackjack/model/playable/PlayableReaction.kt b/src/main/kotlin/blackjack/model/player/PlayableReaction.kt similarity index 61% rename from src/main/kotlin/blackjack/model/playable/PlayableReaction.kt rename to src/main/kotlin/blackjack/model/player/PlayableReaction.kt index 887d5830e2..07f03c8333 100644 --- a/src/main/kotlin/blackjack/model/playable/PlayableReaction.kt +++ b/src/main/kotlin/blackjack/model/player/PlayableReaction.kt @@ -1,4 +1,4 @@ -package blackjack.model.playable +package blackjack.model.player enum class PlayableReaction { HIT, diff --git a/src/main/kotlin/blackjack/model/Players.kt b/src/main/kotlin/blackjack/model/player/Players.kt similarity index 81% rename from src/main/kotlin/blackjack/model/Players.kt rename to src/main/kotlin/blackjack/model/player/Players.kt index 37fba0ebfd..3464f0f37d 100644 --- a/src/main/kotlin/blackjack/model/Players.kt +++ b/src/main/kotlin/blackjack/model/player/Players.kt @@ -1,11 +1,11 @@ -package blackjack.model +package blackjack.model.player import blackjack.model.blackjack.BlackJackStatus -import blackjack.model.pack.Pack -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player -import blackjack.model.playblestrategy.impl.ConsoleInputStrategy +import blackjack.model.card.pack.Pack +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player +import blackjack.model.player.playblestrategy.impl.ConsoleInputStrategy +import blackjack.model.result.PlayableResult class Players( val values: Set, diff --git a/src/main/kotlin/blackjack/model/playable/Playable.kt b/src/main/kotlin/blackjack/model/player/playable/Playable.kt similarity index 54% rename from src/main/kotlin/blackjack/model/playable/Playable.kt rename to src/main/kotlin/blackjack/model/player/playable/Playable.kt index 9780cc83e3..978931bc9a 100644 --- a/src/main/kotlin/blackjack/model/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/player/playable/Playable.kt @@ -1,8 +1,11 @@ -package blackjack.model.playable +package blackjack.model.player.playable import blackjack.model.blackjack.BlackJackStatus -import blackjack.model.pack.Pack -import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.card.pack.Pack +import blackjack.model.player.playblestrategy.PlayingStrategy +import blackjack.model.player.BlackjackScore +import blackjack.model.player.PlayableReaction +import blackjack.model.result.PlayableResult interface Playable { fun score(): BlackjackScore diff --git a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt similarity index 81% rename from src/main/kotlin/blackjack/model/playable/impl/Dealer.kt rename to src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt index 5f0df47603..788ea129d0 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt @@ -1,14 +1,14 @@ -package blackjack.model.playable.impl +package blackjack.model.player.playable.impl import blackjack.model.blackjack.BlackJackStatus -import blackjack.model.Players +import blackjack.model.player.Players import blackjack.model.card.Cards -import blackjack.model.pack.Pack -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.Playable -import blackjack.model.playable.PlayableReaction -import blackjack.model.playable.PlayableResult -import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.card.pack.Pack +import blackjack.model.player.BlackjackScore +import blackjack.model.player.playable.Playable +import blackjack.model.player.PlayableReaction +import blackjack.model.result.PlayableResult +import blackjack.model.player.playblestrategy.PlayingStrategy import blackjack.model.result.DealerResult class Dealer( diff --git a/src/main/kotlin/blackjack/model/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt similarity index 80% rename from src/main/kotlin/blackjack/model/playable/impl/Player.kt rename to src/main/kotlin/blackjack/model/player/playable/impl/Player.kt index b3654d0159..5e61fa925a 100644 --- a/src/main/kotlin/blackjack/model/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt @@ -1,13 +1,13 @@ -package blackjack.model.playable.impl +package blackjack.model.player.playable.impl import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.Cards -import blackjack.model.pack.Pack -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.Playable -import blackjack.model.playable.PlayableReaction -import blackjack.model.playable.PlayableResult -import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.card.pack.Pack +import blackjack.model.player.BlackjackScore +import blackjack.model.player.playable.Playable +import blackjack.model.player.PlayableReaction +import blackjack.model.result.PlayableResult +import blackjack.model.player.playblestrategy.PlayingStrategy class Player( val name: String, diff --git a/src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt b/src/main/kotlin/blackjack/model/player/playblestrategy/PlayingStrategy.kt similarity index 54% rename from src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt rename to src/main/kotlin/blackjack/model/player/playblestrategy/PlayingStrategy.kt index 0a8aef4e02..4e18ce86b4 100644 --- a/src/main/kotlin/blackjack/model/playblestrategy/PlayingStrategy.kt +++ b/src/main/kotlin/blackjack/model/player/playblestrategy/PlayingStrategy.kt @@ -1,4 +1,4 @@ -package blackjack.model.playblestrategy +package blackjack.model.player.playblestrategy interface PlayingStrategy { fun isHit(): Boolean diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/ConsoleInputStrategy.kt similarity index 72% rename from src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt rename to src/main/kotlin/blackjack/model/player/playblestrategy/impl/ConsoleInputStrategy.kt index 3de189e411..0499e43933 100644 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/ConsoleInputStrategy.kt +++ b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/ConsoleInputStrategy.kt @@ -1,7 +1,7 @@ -package blackjack.model.playblestrategy.impl +package blackjack.model.player.playblestrategy.impl -import blackjack.model.playable.impl.Player -import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.player.playable.impl.Player +import blackjack.model.player.playblestrategy.PlayingStrategy class ConsoleInputStrategy( val player: Player, diff --git a/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/DealerStrategy.kt similarity index 64% rename from src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt rename to src/main/kotlin/blackjack/model/player/playblestrategy/impl/DealerStrategy.kt index 54ed21d4df..19a2e22435 100644 --- a/src/main/kotlin/blackjack/model/playblestrategy/impl/DealerStrategy.kt +++ b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/DealerStrategy.kt @@ -1,7 +1,7 @@ -package blackjack.model.playblestrategy.impl +package blackjack.model.player.playblestrategy.impl -import blackjack.model.playable.BlackjackScore -import blackjack.model.playblestrategy.PlayingStrategy +import blackjack.model.player.BlackjackScore +import blackjack.model.player.playblestrategy.PlayingStrategy data class DealerStrategy( private val currentScore: BlackjackScore, diff --git a/src/main/kotlin/blackjack/model/player/playblestrategy/impl/HitStrategy.kt b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/HitStrategy.kt new file mode 100644 index 0000000000..9458e9ee52 --- /dev/null +++ b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/HitStrategy.kt @@ -0,0 +1,9 @@ +package blackjack.model.player.playblestrategy.impl + +import blackjack.model.player.playblestrategy.PlayingStrategy + +object HitStrategy : PlayingStrategy { + override fun isHit(): Boolean { + return true + } +} diff --git a/src/main/kotlin/blackjack/model/player/playblestrategy/impl/StandStrategy.kt b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/StandStrategy.kt new file mode 100644 index 0000000000..d2a7dbc43a --- /dev/null +++ b/src/main/kotlin/blackjack/model/player/playblestrategy/impl/StandStrategy.kt @@ -0,0 +1,9 @@ +package blackjack.model.player.playblestrategy.impl + +import blackjack.model.player.playblestrategy.PlayingStrategy + +object StandStrategy : PlayingStrategy { + override fun isHit(): Boolean { + return false + } +} diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index cfe6a0d160..ef8c352a22 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,7 +1,6 @@ package blackjack.model.result -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.PlayableResult +import blackjack.model.player.BlackjackScore data class DealerResult( val score: BlackjackScore, diff --git a/src/main/kotlin/blackjack/model/playable/PlayableResult.kt b/src/main/kotlin/blackjack/model/result/PlayableResult.kt similarity index 64% rename from src/main/kotlin/blackjack/model/playable/PlayableResult.kt rename to src/main/kotlin/blackjack/model/result/PlayableResult.kt index a956e26b4d..e2e94cda8f 100644 --- a/src/main/kotlin/blackjack/model/playable/PlayableResult.kt +++ b/src/main/kotlin/blackjack/model/result/PlayableResult.kt @@ -1,4 +1,4 @@ -package blackjack.model.playable +package blackjack.model.result enum class PlayableResult { WIN, diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index c13dc3b789..18e114ccc9 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -1,9 +1,9 @@ package blackjack.view -import blackjack.model.Participants -import blackjack.model.Players -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player +import blackjack.model.player.Participants +import blackjack.model.player.Players +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player object InputView { private const val PLAYER_NAMES_DELIMITER: String = "," diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index e6bef7a8d6..4fae7eebdd 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,11 +1,11 @@ package blackjack.view -import blackjack.model.Participants +import blackjack.model.player.Participants import blackjack.model.card.Cards -import blackjack.model.playable.PlayableReaction -import blackjack.model.playable.PlayableResult -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player +import blackjack.model.player.PlayableReaction +import blackjack.model.result.PlayableResult +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player import blackjack.model.result.DealerResult object OutputView { diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt index 2a9db8175a..0f1600925d 100644 --- a/src/test/kotlin/blackjack/model/PlayersTest.kt +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -2,8 +2,9 @@ package blackjack.model import blackjack.model.card.CardFixture import blackjack.model.card.CardFixture.makeCards -import blackjack.model.playable.impl.Dealer -import blackjack.model.playable.impl.Player +import blackjack.model.player.Players +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec diff --git a/src/test/kotlin/blackjack/model/card/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt index 9e6dd9b617..b4ec42896e 100644 --- a/src/test/kotlin/blackjack/model/card/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -1,8 +1,8 @@ package blackjack.model.card import blackjack.model.blackjack.BlackJackStatus -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.impl.Player +import blackjack.model.player.BlackjackScore +import blackjack.model.player.playable.impl.Player import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt b/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt index 4ea0abf72d..890dd308a2 100644 --- a/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt +++ b/src/test/kotlin/blackjack/model/pack/impl/ShuffledPackTest.kt @@ -1,5 +1,6 @@ package blackjack.model.pack.impl +import blackjack.model.card.pack.impl.ShuffledPack import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec diff --git a/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt b/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt index a52a3d2906..a9d3d002f3 100644 --- a/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt +++ b/src/test/kotlin/blackjack/model/playable/BlackjackScoreTest.kt @@ -1,5 +1,7 @@ package blackjack.model.playable +import blackjack.model.player.BlackjackScore +import blackjack.model.result.PlayableResult import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 9fa8091f6e..d07e07c768 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,11 +1,13 @@ package blackjack.model.playable.impl -import blackjack.model.Players +import blackjack.model.player.Players import blackjack.model.card.CardFixture -import blackjack.model.pack.impl.ShuffledPack -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.PlayableResult -import blackjack.model.playblestrategy.impl.DealerStrategy +import blackjack.model.card.pack.impl.ShuffledPack +import blackjack.model.player.BlackjackScore +import blackjack.model.result.PlayableResult +import blackjack.model.player.playblestrategy.impl.DealerStrategy +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 07f2b36fe3..765ee26744 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -2,9 +2,11 @@ package blackjack.model.playable.impl import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.CardFixture -import blackjack.model.pack.impl.ShuffledPack -import blackjack.model.playable.BlackjackScore -import blackjack.model.playable.PlayableResult +import blackjack.model.card.pack.impl.ShuffledPack +import blackjack.model.player.BlackjackScore +import blackjack.model.result.PlayableResult +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe From d7d3af14891bd0cf468543942d6bd21d207397cd Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:07:54 +0900 Subject: [PATCH 70/81] =?UTF-8?q?refactor=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/model/blackjack/BlackJackGame.kt | 2 +- .../blackjack/model/player/Participants.kt | 1 - .../model/player/playable/Playable.kt | 2 +- .../model/player/playable/impl/Dealer.kt | 18 +++++------------- .../model/player/playable/impl/Player.kt | 16 ++++------------ src/main/kotlin/blackjack/view/OutputView.kt | 4 ++-- src/test/kotlin/blackjack/model/PlayersTest.kt | 15 --------------- .../model/playable/impl/PlayerTest.kt | 8 ++++---- 8 files changed, 17 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt index 7d61de3768..d2c8d78b7b 100644 --- a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt @@ -1,7 +1,7 @@ package blackjack.model.blackjack -import blackjack.model.player.Participants import blackjack.model.card.pack.Pack +import blackjack.model.player.Participants import blackjack.model.player.playblestrategy.PlayingStrategy import blackjack.model.player.playblestrategy.impl.DealerStrategy import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/player/Participants.kt b/src/main/kotlin/blackjack/model/player/Participants.kt index 6a806316a6..a46bd24b72 100644 --- a/src/main/kotlin/blackjack/model/player/Participants.kt +++ b/src/main/kotlin/blackjack/model/player/Participants.kt @@ -1,7 +1,6 @@ package blackjack.model.player import blackjack.model.card.pack.Pack -import blackjack.model.player.Players import blackjack.model.player.playable.impl.Dealer class Participants( diff --git a/src/main/kotlin/blackjack/model/player/playable/Playable.kt b/src/main/kotlin/blackjack/model/player/playable/Playable.kt index 978931bc9a..1de3a8b8fd 100644 --- a/src/main/kotlin/blackjack/model/player/playable/Playable.kt +++ b/src/main/kotlin/blackjack/model/player/playable/Playable.kt @@ -2,9 +2,9 @@ package blackjack.model.player.playable import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.pack.Pack -import blackjack.model.player.playblestrategy.PlayingStrategy import blackjack.model.player.BlackjackScore import blackjack.model.player.PlayableReaction +import blackjack.model.player.playblestrategy.PlayingStrategy import blackjack.model.result.PlayableResult interface Playable { diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt index 788ea129d0..c8f97ea02d 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt @@ -1,15 +1,16 @@ package blackjack.model.player.playable.impl import blackjack.model.blackjack.BlackJackStatus -import blackjack.model.player.Players +import blackjack.model.blackjack.judgment.impl.BlackJackJudgment import blackjack.model.card.Cards import blackjack.model.card.pack.Pack import blackjack.model.player.BlackjackScore -import blackjack.model.player.playable.Playable import blackjack.model.player.PlayableReaction -import blackjack.model.result.PlayableResult +import blackjack.model.player.Players +import blackjack.model.player.playable.Playable import blackjack.model.player.playblestrategy.PlayingStrategy import blackjack.model.result.DealerResult +import blackjack.model.result.PlayableResult class Dealer( val cards: Cards = Cards(), @@ -37,16 +38,7 @@ class Dealer( } override fun result(playable: Playable): PlayableResult { - if (this.isBurst() && playable.isBurst()) { - return PlayableResult.DRAW - } - if (this.isBurst() && !playable.isBurst()) { - return PlayableResult.LOSE - } - if (!this.isBurst() && playable.isBurst()) { - return PlayableResult.WIN - } - return this.score() vs playable.score() + return BlackJackJudgment.sentence(this, playable) } override fun status(): BlackJackStatus { diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt index 5e61fa925a..4a6aab9788 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt @@ -1,13 +1,14 @@ package blackjack.model.player.playable.impl import blackjack.model.blackjack.BlackJackStatus +import blackjack.model.blackjack.judgment.impl.BlackJackJudgment import blackjack.model.card.Cards import blackjack.model.card.pack.Pack import blackjack.model.player.BlackjackScore -import blackjack.model.player.playable.Playable import blackjack.model.player.PlayableReaction -import blackjack.model.result.PlayableResult +import blackjack.model.player.playable.Playable import blackjack.model.player.playblestrategy.PlayingStrategy +import blackjack.model.result.PlayableResult class Player( val name: String, @@ -32,16 +33,7 @@ class Player( } override fun result(playable: Playable): PlayableResult { - if (this.isBurst() && playable.isBurst()) { - return PlayableResult.DRAW - } - if (this.isBurst() && !playable.isBurst()) { - return PlayableResult.LOSE - } - if (!this.isBurst() && playable.isBurst()) { - return PlayableResult.WIN - } - return this.score() vs playable.score() + return BlackJackJudgment.sentence(this, playable) } override fun isBurst(): Boolean { diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 4fae7eebdd..7806cb661f 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -1,12 +1,12 @@ package blackjack.view -import blackjack.model.player.Participants import blackjack.model.card.Cards +import blackjack.model.player.Participants import blackjack.model.player.PlayableReaction -import blackjack.model.result.PlayableResult import blackjack.model.player.playable.impl.Dealer import blackjack.model.player.playable.impl.Player import blackjack.model.result.DealerResult +import blackjack.model.result.PlayableResult object OutputView { diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt index 0f1600925d..542e538528 100644 --- a/src/test/kotlin/blackjack/model/PlayersTest.kt +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -1,9 +1,6 @@ package blackjack.model -import blackjack.model.card.CardFixture -import blackjack.model.card.CardFixture.makeCards import blackjack.model.player.Players -import blackjack.model.player.playable.impl.Dealer import blackjack.model.player.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow @@ -22,16 +19,4 @@ class PlayersTest : StringSpec({ Players(Player("hana"), Player("numa")) } } - - "모든 플레이어가 Burst 일때, 딜러는 승리하고 모든 플레이어가 패배해야한다" { - val google = Player("google", makeCards(CardFixture.seven, CardFixture.nine, CardFixture.eight)) - val apple = Player("apple", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.three)) - val microsoft = Player("microsoft", makeCards(CardFixture.king, CardFixture.ten, CardFixture.five)) - val players = Players(setOf(google, apple, microsoft)) - val dealer = Dealer(makeCards(CardFixture.two, CardFixture.five, CardFixture.four)) - val results = players.results(dealer) - - // results shouldContain (google to PlayableResult.LOSE) - println(results) - } }) diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 765ee26744..17249865f3 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -4,9 +4,9 @@ import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.CardFixture import blackjack.model.card.pack.impl.ShuffledPack import blackjack.model.player.BlackjackScore -import blackjack.model.result.PlayableResult import blackjack.model.player.playable.impl.Dealer import blackjack.model.player.playable.impl.Player +import blackjack.model.result.PlayableResult import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -46,15 +46,15 @@ class PlayerTest : StringSpec({ player.score() shouldBe BlackjackScore(2 + 3 + 4 + 8 + 9) } - "플레이어는 (Burst 상황에서, burst와 관계없이) 딜러보다 점수가 낮은경우 LOSE 결과를 반환 해야 한다" { + "플레이어가 BlackJack 이고, 딜러가 Burst 라면 플레이어가 승리하는 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player = Player( "malibu", CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) ) - val actual = player.result(dealer) - actual shouldBe PlayableResult.LOSE + player.result(dealer) shouldBe PlayableResult.WIN + dealer.result(player) shouldBe PlayableResult.LOSE } "플레이어는 딜러보다 점수가 높은 경우 Win 결과를 반환 해야 한다" { From 1d1e2285ab1c7526c3e0b28243323669f28f99f1 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:08:18 +0900 Subject: [PATCH 71/81] =?UTF-8?q?refactor=20:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EC=9E=AD=EC=9D=98=20=EA=B2=BD=EA=B8=B0=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=95=ED=95=B4=EC=A3=BC=EB=8A=94=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/blackjack/judgment/Judgment.kt | 8 ++++++++ .../judgment/impl/BlackJackJudgment.kt | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/kotlin/blackjack/model/blackjack/judgment/Judgment.kt create mode 100644 src/main/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgment.kt diff --git a/src/main/kotlin/blackjack/model/blackjack/judgment/Judgment.kt b/src/main/kotlin/blackjack/model/blackjack/judgment/Judgment.kt new file mode 100644 index 0000000000..add7ed7b31 --- /dev/null +++ b/src/main/kotlin/blackjack/model/blackjack/judgment/Judgment.kt @@ -0,0 +1,8 @@ +package blackjack.model.blackjack.judgment + +import blackjack.model.player.playable.Playable +import blackjack.model.result.PlayableResult + +interface Judgment { + fun sentence(thisPlayable: Playable, otherPlayable: Playable): PlayableResult +} diff --git a/src/main/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgment.kt b/src/main/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgment.kt new file mode 100644 index 0000000000..5daf703bc7 --- /dev/null +++ b/src/main/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgment.kt @@ -0,0 +1,20 @@ +package blackjack.model.blackjack.judgment.impl + +import blackjack.model.blackjack.judgment.Judgment +import blackjack.model.player.playable.Playable +import blackjack.model.result.PlayableResult + +object BlackJackJudgment : Judgment { + override fun sentence(thisPlayable: Playable, otherPlayable: Playable): PlayableResult { + if (thisPlayable.isBurst() && otherPlayable.isBurst()) { + return PlayableResult.DRAW + } + if (thisPlayable.isBurst() && !otherPlayable.isBurst()) { + return PlayableResult.LOSE + } + if (!thisPlayable.isBurst() && otherPlayable.isBurst()) { + return PlayableResult.WIN + } + return thisPlayable.score() vs otherPlayable.score() + } +} From 043ffcc71ad0a39cc5b9e22797039195823337c0 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:08:45 +0900 Subject: [PATCH 72/81] =?UTF-8?q?test=20:=20=EB=B8=94=EB=9E=99=EC=9E=AD?= =?UTF-8?q?=EC=9D=98=20=EB=A3=B0=EC=9D=84=20=EB=AA=B0=EB=9D=BC=20=EC=9E=91?= =?UTF-8?q?=EC=9C=84=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=A0=95=ED=96=88?= =?UTF-8?q?=EB=8D=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/impl/DealerTest.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index d07e07c768..61c524f5db 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,13 +1,13 @@ package blackjack.model.playable.impl -import blackjack.model.player.Players import blackjack.model.card.CardFixture import blackjack.model.card.pack.impl.ShuffledPack import blackjack.model.player.BlackjackScore -import blackjack.model.result.PlayableResult -import blackjack.model.player.playblestrategy.impl.DealerStrategy +import blackjack.model.player.Players import blackjack.model.player.playable.impl.Dealer import blackjack.model.player.playable.impl.Player +import blackjack.model.player.playblestrategy.impl.DealerStrategy +import blackjack.model.result.PlayableResult import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe @@ -37,28 +37,28 @@ class DealerTest : StringSpec({ } "딜러가 21을 초과하면 그 시점까지 남아 있던 플레이어들은 가지고 있는 패에 상관 없이 승리해야 한다" { - val dealer = Dealer( + val dealer = Dealer( // 22점 CardFixture.makeCards(CardFixture.five, CardFixture.seven, CardFixture.king) ) val player1 = Player( - "seoul", - CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + "seoul", // 13점 + CardFixture.makeCards(CardFixture.ace1, CardFixture.king, CardFixture.two) ) val player2 = Player( - "wonju", - CardFixture.makeCards(CardFixture.queen, CardFixture.king) + "wonju", // 21점 + CardFixture.makeCards(CardFixture.queen, CardFixture.king, CardFixture.ace2) ) val actualDealerResult = dealer.dealerResult( Players(player1, player2) ) actualDealerResult.score shouldBe BlackjackScore(22) - actualDealerResult.winningCount shouldBe 0 + actualDealerResult.winningCount shouldBe 2 actualDealerResult.drawingCount shouldBe 0 - actualDealerResult.losingCount shouldBe 2 + actualDealerResult.losingCount shouldBe 0 } - "딜러와 플레이어 모두가 Burst 상황이라면 플레이어 가 WIN(승리) 해야한다" { + "딜러와 플레이어 모두가 Burst 상황이라면 경기 결과는 DRAW 이어야한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player1 = Player( "malibu", @@ -69,10 +69,10 @@ class DealerTest : StringSpec({ CardFixture.makeCards(CardFixture.nine, CardFixture.eight, CardFixture.seven) ) - player1.result(dealer) shouldBe PlayableResult.WIN - player2.result(dealer) shouldBe PlayableResult.WIN - dealer.result(player1) shouldBe PlayableResult.LOSE - dealer.result(player2) shouldBe PlayableResult.LOSE + player1.result(dealer) shouldBe PlayableResult.DRAW + player2.result(dealer) shouldBe PlayableResult.DRAW + dealer.result(player1) shouldBe PlayableResult.DRAW + dealer.result(player2) shouldBe PlayableResult.DRAW } "딜러는 플레이어보다 점수가 높은경우 WIN 결과를 반환 해야 한다" { val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) // 20 From 930745b0495d06018169325e631715d39aade455 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:15:52 +0900 Subject: [PATCH 73/81] =?UTF-8?q?test=20:=20=EB=B8=94=EB=9E=99=EC=9E=AD?= =?UTF-8?q?=EC=9D=98=20=EA=B2=BD=EA=B8=B0=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=95=ED=95=98=EB=8A=94=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../judgment/impl/BlackJackJudgmentTest.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt diff --git a/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt b/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt new file mode 100644 index 0000000000..2880b4df13 --- /dev/null +++ b/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt @@ -0,0 +1,51 @@ +package blackjack.model.blackjack.judgment.impl + +import blackjack.model.card.CardFixture +import blackjack.model.card.CardFixture.makeCards +import blackjack.model.player.playable.impl.Dealer +import blackjack.model.player.playable.impl.Player +import blackjack.model.result.PlayableResult +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class BlackJackJudgmentTest : StringSpec({ + + "플레이어와 딜러 모두 burst가 아니라면 점수가 높은 쪽이 승리해야 한다" { + val player = Player("pi", makeCards(CardFixture.two)) + val dealer = Dealer(makeCards(CardFixture.three)) + + player.result(dealer) shouldBe PlayableResult.LOSE + dealer.result(player) shouldBe PlayableResult.WIN + } + "플레이어와 딜러 모두 burst 라면 DRAW 이어야한다" { + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five)) + val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.nine)) + + player.result(dealer) shouldBe PlayableResult.DRAW + dealer.result(player) shouldBe PlayableResult.DRAW + } + + "플레이어가 burst 이고, 딜러는 burst 가 아니라면 딜러가 승리해야 한다" { + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five)) + val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.four)) + + player.result(dealer) shouldBe PlayableResult.LOSE + dealer.result(player) shouldBe PlayableResult.WIN + } + + "딜러가 burst 이고, 플레이어는 burst 가 아니라면 플레이어가 승리해야 한다" { + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.two, CardFixture.five)) + val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.nine)) + + player.result(dealer) shouldBe PlayableResult.WIN + dealer.result(player) shouldBe PlayableResult.LOSE + } + + "플레이어와 딜러 모두 BlackJack(21점) 이라면 DRAW 이어야한다" { + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.ace2)) + val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.eight)) + + player.result(dealer) shouldBe PlayableResult.DRAW + dealer.result(player) shouldBe PlayableResult.DRAW + } +}) From 366b2b2fc657c5224b5f97c38a08286d8303323c Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:28:01 +0900 Subject: [PATCH 74/81] =?UTF-8?q?test=20:=20stand=20=EB=A5=BC=20=EC=99=B8?= =?UTF-8?q?=EC=B9=98=EB=A9=B4=20=EC=9E=90=EB=8F=99=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=8D=94=EC=9D=B4=EC=83=81=20=EC=B9=B4=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EC=9D=84=20=EC=88=98=20=EC=97=86=EB=8A=94=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EA=B0=80=20=EB=90=98=EC=96=B4=EC=95=BC=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackjack/model/blackjack/BlackJackStatus.kt | 2 +- .../blackjack/model/player/playable/impl/Dealer.kt | 2 +- .../blackjack/model/player/playable/impl/Player.kt | 12 +++++++++--- src/main/kotlin/blackjack/view/InputView.kt | 3 ++- .../blackjack/model/playable/impl/PlayerTest.kt | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt b/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt index d5aea497d9..8eb40c78b8 100644 --- a/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt +++ b/src/main/kotlin/blackjack/model/blackjack/BlackJackStatus.kt @@ -2,5 +2,5 @@ package blackjack.model.blackjack enum class BlackJackStatus { ALIVE, - DIE, + STOP, } diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt index c8f97ea02d..ecfa634d55 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt @@ -43,7 +43,7 @@ class Dealer( override fun status(): BlackJackStatus { if (this.score().isBurst()) { - return BlackJackStatus.DIE + return BlackJackStatus.STOP } return BlackJackStatus.ALIVE } diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt index 4a6aab9788..d9245dd559 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt @@ -13,6 +13,7 @@ import blackjack.model.result.PlayableResult class Player( val name: String, val cards: Cards = Cards.emptyCards(), + var status: BlackJackStatus = BlackJackStatus.ALIVE, ) : Playable { override fun score(): BlackjackScore { @@ -29,6 +30,7 @@ class Player( this.hit(pack) return PlayableReaction.HIT } + this.status = BlackJackStatus.STOP return PlayableReaction.STAND } @@ -37,7 +39,11 @@ class Player( } override fun isBurst(): Boolean { - return this.score().isBurst() + if (this.score().isBurst()) { + this.status = BlackJackStatus.STOP + return true + } + return false } fun hit(pack: Pack) { @@ -46,8 +52,8 @@ class Player( override fun status(): BlackJackStatus { if (this.isBurst()) { - return BlackJackStatus.DIE + return BlackJackStatus.STOP } - return BlackJackStatus.ALIVE + return this.status } } diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 18e114ccc9..4d8fe43a94 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -1,5 +1,6 @@ package blackjack.view +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.player.Participants import blackjack.model.player.Players import blackjack.model.player.playable.impl.Dealer @@ -15,7 +16,7 @@ object InputView { Players( input.split(PLAYER_NAMES_DELIMITER) .asSequence() - .map { Player(it) } + .map { Player(name = it, status = BlackJackStatus.ALIVE) } .toSet() ), Dealer() diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 17249865f3..19d1837aaa 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -41,8 +41,8 @@ class PlayerTest : StringSpec({ ) ) - player.status() shouldBe BlackJackStatus.DIE player.isBurst() shouldBe true + player.status() shouldBe BlackJackStatus.STOP player.score() shouldBe BlackjackScore(2 + 3 + 4 + 8 + 9) } From be3bc4db51483a589ffa9348e4635adacf05b336 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:28:53 +0900 Subject: [PATCH 75/81] =?UTF-8?q?bugfix=20:=20=EB=B2=84=EA=B7=B8=EA=B0=80?= =?UTF-8?q?=20=EB=82=98=EB=8A=94=20=EB=B6=80=EB=B6=84=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/result/DealerResult.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index ef8c352a22..bead00f45c 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -12,9 +12,9 @@ data class DealerResult( fun of(playerResults: List, score: BlackjackScore): DealerResult { return DealerResult( score = score, - winningCount = playerResults.count { it == PlayableResult.LOSE }, + winningCount = playerResults.count { it == PlayableResult.WIN }, drawingCount = playerResults.count { it == PlayableResult.DRAW }, - losingCount = playerResults.count { it == PlayableResult.WIN } + losingCount = playerResults.count { it == PlayableResult.LOSE } ) } } From b20b5c5ff2a2f2275de0a289db666e029350ed83 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:31:46 +0900 Subject: [PATCH 76/81] =?UTF-8?q?refactor=20:=20=EC=9E=98=EB=AA=BB=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EB=90=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 61c524f5db..6bd18db991 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -53,9 +53,11 @@ class DealerTest : StringSpec({ ) actualDealerResult.score shouldBe BlackjackScore(22) - actualDealerResult.winningCount shouldBe 2 + actualDealerResult.winningCount shouldBe 0 actualDealerResult.drawingCount shouldBe 0 - actualDealerResult.losingCount shouldBe 0 + actualDealerResult.losingCount shouldBe 2 + dealer.result(player1) shouldBe PlayableResult.LOSE + dealer.result(player2) shouldBe PlayableResult.LOSE } "딜러와 플레이어 모두가 Burst 상황이라면 경기 결과는 DRAW 이어야한다" { From 4f07cb375fa3765060c7c3fcc99474d0edc87afb Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 00:57:27 +0900 Subject: [PATCH 77/81] =?UTF-8?q?refactor=20:=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=ED=98=95=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{model/blackjack => }/BlackJackGame.kt | 9 +++++++-- src/main/kotlin/blackjack/Controller.kt | 1 - .../kotlin/blackjack/model/player/Players.kt | 16 ++-------------- .../model/player/playable/impl/Dealer.kt | 8 +++++++- .../blackjack/model/result/DealerResult.kt | 13 +------------ src/main/kotlin/blackjack/view/OutputView.kt | 13 ++++++++++--- 6 files changed, 27 insertions(+), 33 deletions(-) rename src/main/kotlin/blackjack/{model/blackjack => }/BlackJackGame.kt (73%) diff --git a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt b/src/main/kotlin/blackjack/BlackJackGame.kt similarity index 73% rename from src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt rename to src/main/kotlin/blackjack/BlackJackGame.kt index d2c8d78b7b..816de9ecbe 100644 --- a/src/main/kotlin/blackjack/model/blackjack/BlackJackGame.kt +++ b/src/main/kotlin/blackjack/BlackJackGame.kt @@ -1,8 +1,10 @@ -package blackjack.model.blackjack +package blackjack import blackjack.model.card.pack.Pack import blackjack.model.player.Participants +import blackjack.model.player.playable.impl.Player import blackjack.model.player.playblestrategy.PlayingStrategy +import blackjack.model.player.playblestrategy.impl.ConsoleInputStrategy import blackjack.model.player.playblestrategy.impl.DealerStrategy import blackjack.view.OutputView @@ -28,6 +30,9 @@ class BlackJackGame( } private fun playersTurn(pack: Pack) { - participants.players.playingTurn(pack) + participants.players.values.forEach { player: Player -> + player.playing(ConsoleInputStrategy(player), pack) + OutputView.presentPlayer(player) + } } } diff --git a/src/main/kotlin/blackjack/Controller.kt b/src/main/kotlin/blackjack/Controller.kt index 9eea178354..c2c243bdc1 100644 --- a/src/main/kotlin/blackjack/Controller.kt +++ b/src/main/kotlin/blackjack/Controller.kt @@ -1,6 +1,5 @@ package blackjack -import blackjack.model.blackjack.BlackJackGame import blackjack.model.card.pack.impl.ShuffledPack import blackjack.view.InputView import blackjack.view.OutputView diff --git a/src/main/kotlin/blackjack/model/player/Players.kt b/src/main/kotlin/blackjack/model/player/Players.kt index 3464f0f37d..023305c8bc 100644 --- a/src/main/kotlin/blackjack/model/player/Players.kt +++ b/src/main/kotlin/blackjack/model/player/Players.kt @@ -4,7 +4,6 @@ import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.pack.Pack import blackjack.model.player.playable.impl.Dealer import blackjack.model.player.playable.impl.Player -import blackjack.model.player.playblestrategy.impl.ConsoleInputStrategy import blackjack.model.result.PlayableResult class Players( @@ -29,18 +28,7 @@ class Players( return values.size } - fun playingTurn(pack: Pack) { - values.forEach { player -> - if (player.status() == BlackJackStatus.ALIVE) { - player.playing(ConsoleInputStrategy(player), pack) - } -// else { -// println(" ### [검증용/삭제예정] 플레이어 ${player.name} 은 DIE 상태라 카드를 받을수 있는 기회가 주어지지 않습니다, score=${player.cards.totalScore()}") -// } - } - } - - fun results(dealer: Dealer): Map { - return this.values.map { player -> player to player.result(dealer) }.toMap() + fun results(dealer: Dealer): List> { + return this.values.map { player -> player to player.result(dealer) } } } diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt index ecfa634d55..809cab34e5 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt @@ -53,7 +53,13 @@ class Dealer( } fun dealerResult(players: Players): DealerResult { - return DealerResult.of(players.values.map { this.result(it) }, this.score()) + val results = players.values.map { this.result(it) } + return DealerResult( + score = this.score(), + winningCount = results.count { it == PlayableResult.WIN }, + drawingCount = results.count { it == PlayableResult.DRAW }, + losingCount = results.count { it == PlayableResult.LOSE }, + ) } fun isNotBurst(): Boolean { diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index bead00f45c..841378beb8 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -7,15 +7,4 @@ data class DealerResult( val winningCount: Int, val drawingCount: Int, val losingCount: Int, -) { - companion object { - fun of(playerResults: List, score: BlackjackScore): DealerResult { - return DealerResult( - score = score, - winningCount = playerResults.count { it == PlayableResult.WIN }, - drawingCount = playerResults.count { it == PlayableResult.DRAW }, - losingCount = playerResults.count { it == PlayableResult.LOSE } - ) - } - } -} +) diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 7806cb661f..303e1c19db 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -35,10 +35,17 @@ object OutputView { presentPlayersResult(participants.players.results(participants.dealer)) } - private fun presentPlayersResult(playersResult: Map) { + private fun presentPlayersResult(playersResult: List>) { playersResult - .keys - .forEach { player -> println("${player.name} : ${playersResult[player]}") } + .forEach { presentPlayerResult(it.first, it.second) } + } + + private fun presentPlayerResult(player: Player, result: PlayableResult) { + println("${player.name}: ${result.name}") + } + + fun presentPlayer(player: Player) { + println(player.presentPlayers()) } private fun presentDealerResult(dealerResult: DealerResult) { From e4a59a028bec943d4283a1f90b547fb71ef6befb Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 01:11:06 +0900 Subject: [PATCH 78/81] =?UTF-8?q?bugfix=20:=20=EB=94=9C=EB=9F=AC=EC=9D=98?= =?UTF-8?q?=20=EC=8A=B9=ED=8C=A8=20=EC=B6=9C=EB=A0=A5=20=EB=B2=84=EA=B7=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/model/player/Participants.kt | 7 ++++++- src/main/kotlin/blackjack/model/player/Players.kt | 4 ++-- .../kotlin/blackjack/model/player/playable/impl/Dealer.kt | 7 +------ src/main/kotlin/blackjack/model/result/DealerResult.kt | 3 --- src/main/kotlin/blackjack/view/InputView.kt | 2 +- src/main/kotlin/blackjack/view/OutputView.kt | 2 +- .../kotlin/blackjack/model/playable/impl/DealerTest.kt | 1 - 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/blackjack/model/player/Participants.kt b/src/main/kotlin/blackjack/model/player/Participants.kt index a46bd24b72..c0e15db1b1 100644 --- a/src/main/kotlin/blackjack/model/player/Participants.kt +++ b/src/main/kotlin/blackjack/model/player/Participants.kt @@ -2,6 +2,7 @@ package blackjack.model.player import blackjack.model.card.pack.Pack import blackjack.model.player.playable.impl.Dealer +import blackjack.model.result.DealerResult class Participants( val players: Players, @@ -14,10 +15,14 @@ class Participants( } fun isContinue(): Boolean { - return players.hasAnyAlivePlayer() && dealer.isNotBurst() + return players.hasAnyAlivePlayer() && (!dealer.isBurst()) } fun count(): Int { return players.count() + 1 } + + fun dealerResult(): DealerResult { + return this.dealer.dealerResult(this.players) + } } diff --git a/src/main/kotlin/blackjack/model/player/Players.kt b/src/main/kotlin/blackjack/model/player/Players.kt index 023305c8bc..3448af29d4 100644 --- a/src/main/kotlin/blackjack/model/player/Players.kt +++ b/src/main/kotlin/blackjack/model/player/Players.kt @@ -7,13 +7,13 @@ import blackjack.model.player.playable.impl.Player import blackjack.model.result.PlayableResult class Players( - val values: Set, + val values: List, ) { init { require(values.map { it.name }.distinct().size == values.size) { "Player 들의 이름은 중복이 허용되지 않습니다" } } - constructor(vararg players: Player) : this(players.toSet()) + constructor(vararg players: Player) : this(players.toList()) fun dealing(pack: Pack) { values.forEach { it.dealing(pack) } diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt index 809cab34e5..e1bcb0ba15 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Dealer.kt @@ -53,16 +53,11 @@ class Dealer( } fun dealerResult(players: Players): DealerResult { - val results = players.values.map { this.result(it) } + val results = players.values.map { player -> this.result(player) } return DealerResult( - score = this.score(), winningCount = results.count { it == PlayableResult.WIN }, drawingCount = results.count { it == PlayableResult.DRAW }, losingCount = results.count { it == PlayableResult.LOSE }, ) } - - fun isNotBurst(): Boolean { - return !this.isBurst() - } } diff --git a/src/main/kotlin/blackjack/model/result/DealerResult.kt b/src/main/kotlin/blackjack/model/result/DealerResult.kt index 841378beb8..db8f13cd0f 100644 --- a/src/main/kotlin/blackjack/model/result/DealerResult.kt +++ b/src/main/kotlin/blackjack/model/result/DealerResult.kt @@ -1,9 +1,6 @@ package blackjack.model.result -import blackjack.model.player.BlackjackScore - data class DealerResult( - val score: BlackjackScore, val winningCount: Int, val drawingCount: Int, val losingCount: Int, diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt index 4d8fe43a94..bec3904164 100644 --- a/src/main/kotlin/blackjack/view/InputView.kt +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -17,7 +17,7 @@ object InputView { input.split(PLAYER_NAMES_DELIMITER) .asSequence() .map { Player(name = it, status = BlackJackStatus.ALIVE) } - .toSet() + .toList() ), Dealer() ) diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index 303e1c19db..b4ff4154c0 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -31,7 +31,7 @@ object OutputView { fun presentResult(participants: Participants) { println("## 최종 승패") - presentDealerResult(participants.dealer.dealerResult(participants.players)) + presentDealerResult(participants.dealerResult()) presentPlayersResult(participants.players.results(participants.dealer)) } diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index 6bd18db991..e632f366c3 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -52,7 +52,6 @@ class DealerTest : StringSpec({ Players(player1, player2) ) - actualDealerResult.score shouldBe BlackjackScore(22) actualDealerResult.winningCount shouldBe 0 actualDealerResult.drawingCount shouldBe 0 actualDealerResult.losingCount shouldBe 2 From 9632f364979a55e7466ad4190fa829ee32f92051 Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 01:16:44 +0900 Subject: [PATCH 79/81] =?UTF-8?q?test=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/playable/impl/DealerTest.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index e632f366c3..e15fe7ed53 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -109,4 +109,29 @@ class DealerTest : StringSpec({ player.result(dealer) shouldBe PlayableResult.DRAW dealer.result(player) shouldBe PlayableResult.DRAW } + + "딜러가 2승1패인 경우 경기결과가 잘 표현되어야한다" { + val dealer = Dealer( // 15점 + CardFixture.makeCards(CardFixture.two, CardFixture.two, CardFixture.eight, CardFixture.three) + ) + val player1 = Player( + "saml", // 21점 + CardFixture.makeCards(CardFixture.five, CardFixture.king, CardFixture.six) + ) + val player2 = Player( + "ldap", // 18점 + CardFixture.makeCards(CardFixture.eight, CardFixture.queen, CardFixture.ace2) + ) + val player3 = Player( + "oauth", // 10점 + CardFixture.makeCards(CardFixture.two, CardFixture.eight) + ) + val actual = dealer.dealerResult( + Players(player1, player2, player3) + ) + + actual.winningCount shouldBe 1 + actual.drawingCount shouldBe 0 + actual.losingCount shouldBe 2 + } }) From 53faf165bd948a85302497c6fde0f56258ec962f Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 01:21:42 +0900 Subject: [PATCH 80/81] =?UTF-8?q?refactor=20:=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/player/playable/impl/Player.kt | 2 +- .../kotlin/blackjack/model/PlayersTest.kt | 5 ++-- .../judgment/impl/BlackJackJudgmentTest.kt | 11 +++++---- .../kotlin/blackjack/model/card/CardsTest.kt | 9 +++++--- .../model/playable/impl/DealerTest.kt | 23 +++++++++++-------- .../model/playable/impl/PlayerTest.kt | 15 ++++++------ 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt index d9245dd559..1acf47a52b 100644 --- a/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt +++ b/src/main/kotlin/blackjack/model/player/playable/impl/Player.kt @@ -13,7 +13,7 @@ import blackjack.model.result.PlayableResult class Player( val name: String, val cards: Cards = Cards.emptyCards(), - var status: BlackJackStatus = BlackJackStatus.ALIVE, + var status: BlackJackStatus, ) : Playable { override fun score(): BlackjackScore { diff --git a/src/test/kotlin/blackjack/model/PlayersTest.kt b/src/test/kotlin/blackjack/model/PlayersTest.kt index 542e538528..127ae76dd0 100644 --- a/src/test/kotlin/blackjack/model/PlayersTest.kt +++ b/src/test/kotlin/blackjack/model/PlayersTest.kt @@ -1,5 +1,6 @@ package blackjack.model +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.player.Players import blackjack.model.player.playable.impl.Player import io.kotest.assertions.throwables.shouldNotThrow @@ -10,13 +11,13 @@ class PlayersTest : StringSpec({ "플레이어들의 이름은 중복을 허용하지 않는다. 중복시 throw IllegalArgumentException" { shouldThrow { - Players(Player("hana"), Player("hana")) + Players(Player("hana", status = BlackJackStatus.ALIVE), Player("hana", status = BlackJackStatus.ALIVE)) } } "플레이어들의 이름이 중복되지 않으면 정상 동작 해야한다" { shouldNotThrow { - Players(Player("hana"), Player("numa")) + Players(Player("hana", status = BlackJackStatus.ALIVE), Player("numa", status = BlackJackStatus.ALIVE)) } } }) diff --git a/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt b/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt index 2880b4df13..7c165e00ad 100644 --- a/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt +++ b/src/test/kotlin/blackjack/model/blackjack/judgment/impl/BlackJackJudgmentTest.kt @@ -1,5 +1,6 @@ package blackjack.model.blackjack.judgment.impl +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.CardFixture import blackjack.model.card.CardFixture.makeCards import blackjack.model.player.playable.impl.Dealer @@ -11,14 +12,14 @@ import io.kotest.matchers.shouldBe class BlackJackJudgmentTest : StringSpec({ "플레이어와 딜러 모두 burst가 아니라면 점수가 높은 쪽이 승리해야 한다" { - val player = Player("pi", makeCards(CardFixture.two)) + val player = Player("pi", makeCards(CardFixture.two), status = BlackJackStatus.ALIVE) val dealer = Dealer(makeCards(CardFixture.three)) player.result(dealer) shouldBe PlayableResult.LOSE dealer.result(player) shouldBe PlayableResult.WIN } "플레이어와 딜러 모두 burst 라면 DRAW 이어야한다" { - val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five)) + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five), status = BlackJackStatus.ALIVE) val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.nine)) player.result(dealer) shouldBe PlayableResult.DRAW @@ -26,7 +27,7 @@ class BlackJackJudgmentTest : StringSpec({ } "플레이어가 burst 이고, 딜러는 burst 가 아니라면 딜러가 승리해야 한다" { - val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five)) + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.five), status = BlackJackStatus.ALIVE) val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.four)) player.result(dealer) shouldBe PlayableResult.LOSE @@ -34,7 +35,7 @@ class BlackJackJudgmentTest : StringSpec({ } "딜러가 burst 이고, 플레이어는 burst 가 아니라면 플레이어가 승리해야 한다" { - val player = Player("pi", makeCards(CardFixture.jack, CardFixture.two, CardFixture.five)) + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.two, CardFixture.five), status = BlackJackStatus.ALIVE) val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.nine)) player.result(dealer) shouldBe PlayableResult.WIN @@ -42,7 +43,7 @@ class BlackJackJudgmentTest : StringSpec({ } "플레이어와 딜러 모두 BlackJack(21점) 이라면 DRAW 이어야한다" { - val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.ace2)) + val player = Player("pi", makeCards(CardFixture.jack, CardFixture.queen, CardFixture.ace2), status = BlackJackStatus.ALIVE) val dealer = Dealer(makeCards(CardFixture.three, CardFixture.ten, CardFixture.eight)) player.result(dealer) shouldBe PlayableResult.DRAW diff --git a/src/test/kotlin/blackjack/model/card/CardsTest.kt b/src/test/kotlin/blackjack/model/card/CardsTest.kt index b4ec42896e..392415f1db 100644 --- a/src/test/kotlin/blackjack/model/card/CardsTest.kt +++ b/src/test/kotlin/blackjack/model/card/CardsTest.kt @@ -47,7 +47,8 @@ class CardsTest : StringSpec({ "ACE+ACE+KING 이 들어온 경우 ACE 를 1로 인식해, 스코어가 12 이어야 만 한다" { val player = Player( "kim", - CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king) + CardFixture.makeCards(CardFixture.ace1, CardFixture.ace2, CardFixture.king), + status = BlackJackStatus.ALIVE ) player.status() shouldBe BlackJackStatus.ALIVE player.isBurst() shouldBe false @@ -57,7 +58,8 @@ class CardsTest : StringSpec({ "ACE+KING 이 들어온 경우 ACE 를 11로 인식해, 블랙잭 점수인 21 로 계산 되어야 한다" { val player = Player( "kong", - CardFixture.makeCards(CardFixture.ace1, CardFixture.king) + CardFixture.makeCards(CardFixture.ace1, CardFixture.king), + status = BlackJackStatus.ALIVE ) player.status() shouldBe BlackJackStatus.ALIVE player.isBurst() shouldBe false @@ -81,7 +83,8 @@ class CardsTest : StringSpec({ CardFixture.king, CardFixture.jack, CardFixture.queen - ) + ), + status = BlackJackStatus.ALIVE ) player.score() shouldBeIn listOf(BlackjackScore(85), BlackjackScore(95)) } diff --git a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt index e15fe7ed53..b77c9361b9 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/DealerTest.kt @@ -1,5 +1,6 @@ package blackjack.model.playable.impl +import blackjack.model.blackjack.BlackJackStatus import blackjack.model.card.CardFixture import blackjack.model.card.pack.impl.ShuffledPack import blackjack.model.player.BlackjackScore @@ -42,11 +43,11 @@ class DealerTest : StringSpec({ ) val player1 = Player( "seoul", // 13점 - CardFixture.makeCards(CardFixture.ace1, CardFixture.king, CardFixture.two) + CardFixture.makeCards(CardFixture.ace1, CardFixture.king, CardFixture.two), status = BlackJackStatus.ALIVE ) val player2 = Player( "wonju", // 21점 - CardFixture.makeCards(CardFixture.queen, CardFixture.king, CardFixture.ace2) + CardFixture.makeCards(CardFixture.queen, CardFixture.king, CardFixture.ace2), status = BlackJackStatus.ALIVE ) val actualDealerResult = dealer.dealerResult( Players(player1, player2) @@ -63,11 +64,12 @@ class DealerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player1 = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.four) + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.four), status = BlackJackStatus.ALIVE ) val player2 = Player( "martini", - CardFixture.makeCards(CardFixture.nine, CardFixture.eight, CardFixture.seven) + CardFixture.makeCards(CardFixture.nine, CardFixture.eight, CardFixture.seven), + status = BlackJackStatus.ALIVE ) player1.result(dealer) shouldBe PlayableResult.DRAW @@ -79,7 +81,8 @@ class DealerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) // 20 val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.five) // 15 + CardFixture.makeCards(CardFixture.ten, CardFixture.five), // 15 + status = BlackJackStatus.ALIVE ) dealer.result(player) shouldBe PlayableResult.WIN @@ -90,7 +93,7 @@ class DealerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.three, CardFixture.four)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.seven, CardFixture.five) + CardFixture.makeCards(CardFixture.seven, CardFixture.five), status = BlackJackStatus.ALIVE ) dealer.result(player) shouldBe PlayableResult.LOSE @@ -101,7 +104,7 @@ class DealerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2), status = BlackJackStatus.ALIVE ) dealer.score() shouldBe BlackjackScore(21) @@ -116,15 +119,15 @@ class DealerTest : StringSpec({ ) val player1 = Player( "saml", // 21점 - CardFixture.makeCards(CardFixture.five, CardFixture.king, CardFixture.six) + CardFixture.makeCards(CardFixture.five, CardFixture.king, CardFixture.six), status = BlackJackStatus.ALIVE ) val player2 = Player( "ldap", // 18점 - CardFixture.makeCards(CardFixture.eight, CardFixture.queen, CardFixture.ace2) + CardFixture.makeCards(CardFixture.eight, CardFixture.queen, CardFixture.ace2), status = BlackJackStatus.ALIVE ) val player3 = Player( "oauth", // 10점 - CardFixture.makeCards(CardFixture.two, CardFixture.eight) + CardFixture.makeCards(CardFixture.two, CardFixture.eight), status = BlackJackStatus.ALIVE ) val actual = dealer.dealerResult( Players(player1, player2, player3) diff --git a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt index 19d1837aaa..86b1073f4f 100644 --- a/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt +++ b/src/test/kotlin/blackjack/model/playable/impl/PlayerTest.kt @@ -15,7 +15,7 @@ class PlayerTest : StringSpec({ "플레이어는 dealing 시 2장의 카드를 받을 수 있다" { shouldNotThrow { - val player = Player("구글") + val player = Player("구글", status = BlackJackStatus.ALIVE) player.dealing(ShuffledPack) player.cards.count() shouldBe 2 } @@ -23,7 +23,7 @@ class PlayerTest : StringSpec({ "플레이어는 hit 시 1장의 카드를 받을 수 있다" { shouldNotThrow { - val player = Player("애플") + val player = Player("애플", status = BlackJackStatus.ALIVE) player.hit(ShuffledPack) player.cards.count() shouldBe 1 } @@ -38,7 +38,8 @@ class PlayerTest : StringSpec({ CardFixture.four, CardFixture.eight, CardFixture.nine - ) + ), + status = BlackJackStatus.ALIVE ) player.isBurst() shouldBe true @@ -50,7 +51,7 @@ class PlayerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.three)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2), status = BlackJackStatus.ALIVE ) player.result(dealer) shouldBe PlayableResult.WIN @@ -61,7 +62,7 @@ class PlayerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.three)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.jack) + CardFixture.makeCards(CardFixture.ten, CardFixture.jack), status = BlackJackStatus.ALIVE ) player.result(dealer) shouldBe PlayableResult.WIN @@ -71,7 +72,7 @@ class PlayerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.ten)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.five) + CardFixture.makeCards(CardFixture.ten, CardFixture.five), status = BlackJackStatus.ALIVE ) val actual = player.result(dealer) actual shouldBe PlayableResult.LOSE @@ -81,7 +82,7 @@ class PlayerTest : StringSpec({ val dealer = Dealer(CardFixture.makeCards(CardFixture.queen, CardFixture.nine, CardFixture.two)) val player = Player( "malibu", - CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2) + CardFixture.makeCards(CardFixture.ten, CardFixture.jack, CardFixture.ace2), status = BlackJackStatus.ALIVE ) dealer.score() shouldBe BlackjackScore(21) From 4769e26bab4fa9b09a873170a52e366d3792074a Mon Sep 17 00:00:00 2001 From: dong Date: Tue, 28 Nov 2023 01:25:21 +0900 Subject: [PATCH 81/81] =?UTF-8?q?bugfix:=20=EB=B2=84=EA=B7=B8=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/view/OutputView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt index b4ff4154c0..2adba6969c 100644 --- a/src/main/kotlin/blackjack/view/OutputView.kt +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -49,7 +49,7 @@ object OutputView { } private fun presentDealerResult(dealerResult: DealerResult) { - println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.drawingCount}패") + println("딜러 ${dealerResult.winningCount}승 ${dealerResult.drawingCount}무 ${dealerResult.losingCount}패") } fun presentDealerAction(playableReaction: PlayableReaction) {