-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
step4: 블랙잭(베팅) #700
base: yoonnyeong
Are you sure you want to change the base?
step4: 블랙잭(베팅) #700
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package blackjack.domain | ||
|
||
abstract class BlackjackParticipant(val name: String) { | ||
abstract class BlackjackParticipant(val name: String, var bettingAmount: Int = 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bettingAmount도 외부에서 변경할 수 없도록 변경해주세요. |
||
private var _cards = Cards(mutableListOf()) | ||
|
||
var profit = 0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 외부에서 값을 바꿀수 없도록 가시성을 제한해주세요. |
||
val isBusted get() = getScore() > Score.BLACKJACK | ||
|
||
val isBlackjack get() = this.getScore() == Score.BLACKJACK | ||
val cards: Cards | ||
get() = _cards | ||
|
||
|
@@ -13,7 +13,8 @@ abstract class BlackjackParticipant(val name: String) { | |
} | ||
|
||
fun getFirstDealCards(twoCards: List<Card>) { | ||
twoCards.forEach { cards.addCard(it) } | ||
twoCards.forEach { _cards.addCard(it) } | ||
|
||
} | ||
|
||
fun hit(card: Card) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
package blackjack.domain | ||
|
||
class GameResult(private val dealer: Dealer, private val players: List<Player>) { | ||
fun getMatchCount(resultMap: List<Map<Player, MatchResult>>): List<Map<MatchResult, Int>> = | ||
resultMap.map { playerMap -> playerMap.values.groupingBy { it }.eachCount() } | ||
|
||
fun getResultMap(): List<Map<Player, MatchResult>> { | ||
var resultMap: MutableList<Map<Player, MatchResult>> = mutableListOf() | ||
for (player in players) { | ||
|
@@ -12,4 +9,18 @@ class GameResult(private val dealer: Dealer, private val players: List<Player>) | |
} | ||
return resultMap | ||
} | ||
|
||
fun setProfit(): List<Player> { | ||
val resultMapList = getResultMap() | ||
|
||
for (resultMap in resultMapList) { | ||
for ((player, matchResult) in resultMap) { | ||
val profit = matchResult.rate * player.bettingAmount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 프로퍼티를 get해서 사용하지 말고 메세지를 주고받도록 해주시면 좋을것 같습니다. |
||
player.profit = profit | ||
dealer.calculateProfit(profit.toInt()) | ||
} | ||
} | ||
Comment on lines
+16
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. depth가 2가 넘는것 같습니다. 객체의 값을 외부에서 set할수 없도록 하고 메세지를 던지도록 변경해주시면 좋을것 같습니다. |
||
|
||
return players | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package blackjack.domain | ||
|
||
enum class MatchResult(val text: String) { | ||
WIN("승"), | ||
LOSS("패"), | ||
TIE("무") | ||
enum class MatchResult(val text: String, val rate: Double) { | ||
BLACKJACK_WIN("승", 1.5), | ||
WIN("승", 1.0), | ||
LOSS("패", -1.0), | ||
TIE("무", 1.0) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package blackjack.domain | ||
|
||
class Player(name: String) : BlackjackParticipant(name) { | ||
class Player(name: String, bettingAmount: Int) : BlackjackParticipant(name, bettingAmount) { | ||
constructor(name: String) : this(name, bettingAmount = 0) | ||
|
||
override val canHit: Boolean = (getScore() < Score.BLACKJACK) | ||
override val canHit: Boolean = (getScore() < Score.BLACKJACK && !isBusted) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#693 (comment)