-
Notifications
You must be signed in to change notification settings - Fork 550
[π μ¬μ΄ν΄2 - λ―Έμ (λΈλμ λ² ν )] λ°λ λ―Έμ μ μΆν©λλ€. #1103
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
base: frombunny
Are you sure you want to change the base?
Changes from all commits
4a53628
045dc35
9018e64
177d7f2
e1a792c
cc97a30
c561832
3de16ad
b4200f5
29ddc2f
5831766
f9de3da
655ae0d
3f1bfc6
1bc1525
4e2335d
1d31d46
3dddaa6
06d5182
7aab304
1d7d3d0
9553464
6bbf0b6
9cce391
e688417
49b1638
2a266d6
d90de0e
f28f3c1
871df97
3935817
02313df
e757312
af15cb2
ee641a5
74d3f41
7e1d730
016eee1
4478ad6
b252ca8
e6ba404
26a8bd0
3abcaee
803446e
53de135
907c9d8
deba9b4
12a6a7a
8111a98
9b83197
f31f43d
439ed40
543030e
9fb4070
bcd3028
7e52ef0
6b95dc1
3a70643
3b36f8e
055878a
1be0dd0
2671cb0
c7b94b8
a68d9a0
8d7d9c1
ab26a90
175f494
3ed8f3a
c4681f6
89a28ba
1137dea
689d625
4e52c38
018bcb0
5e7c895
fefcf5b
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,45 +1,34 @@ | ||
| package domain.game; | ||
|
|
||
| import domain.participant.Dealer; | ||
| import domain.participant.Participant; | ||
| import domain.participant.Player; | ||
| import domain.participant.Players; | ||
| import dto.DealerResultInfo; | ||
| import dto.PlayerResultInfo; | ||
| import dto.ParticipantResultInfo; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.math.BigDecimal; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static java.util.Collections.frequency; | ||
| import static domain.game.ProfitCalculator.calculatePlayerProfit; | ||
|
|
||
| public class GameResult { | ||
| private final Map<Player, WinningStatus> playerWinningStatus = new LinkedHashMap<>(); | ||
| private final Map<Participant, BigDecimal> participantsProfits = new HashMap<>(); | ||
|
|
||
| public GameResult(Players players, Dealer dealer) { | ||
| for (Player player : players.getPlayers()) { | ||
| playerWinningStatus.put(player, WinningStatus.of(player, dealer)); | ||
| } | ||
| } | ||
|
|
||
| public List<PlayerResultInfo> getPlayersResult() { | ||
| List<PlayerResultInfo> result = new ArrayList<>(); | ||
| BigDecimal playersProfitSum = BigDecimal.ZERO; | ||
|
Member
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. BigDecimalμ μ¬μ©ν΄μ£Όμ
¨κ΅°μ!
Author
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. float, double κ°μ κ²½μ°λ λΆλμμμ μ μ΄μ©ν΄ μλ₯Ό μ μ₯νλλ°, μ΄ κ³Όμ μμ μ€μ°¨κ° λ°μν μ μλ€κ³ μκ³ μμ΅λλ€. λμ λ―ΈμΈν μ€μ°¨λ νμ©λλ©΄ μλλ€κ³ νλ¨νμ¬, BigDecimalλ₯Ό μ¬μ©νμμ΅λλ€ π° |
||
|
|
||
| for (Map.Entry<Player, WinningStatus> entry : playerWinningStatus.entrySet()) { | ||
| String name = entry.getKey().name(); | ||
| WinningStatus status = entry.getValue(); | ||
| for (Player player : players.getPlayers()) { | ||
| BigDecimal profit = calculatePlayerProfit(player, dealer); | ||
| playersProfitSum = playersProfitSum.add(profit); | ||
|
|
||
| result.add(new PlayerResultInfo(name, status)); | ||
| participantsProfits.put(player, profit); | ||
| } | ||
|
|
||
| return result; | ||
| participantsProfits.put(dealer, playersProfitSum.negate()); | ||
| } | ||
|
|
||
| public DealerResultInfo getDealerResult() { | ||
| int winCount = frequency(playerWinningStatus.values(), WinningStatus.LOSE); | ||
| int tieCount = frequency(playerWinningStatus.values(), WinningStatus.TIE); | ||
| int loseCount = frequency(playerWinningStatus.values(), WinningStatus.WIN); | ||
|
|
||
| return new DealerResultInfo(winCount, tieCount, loseCount); | ||
| public ParticipantResultInfo participantResultInfo(Participant participant) { | ||
| return new ParticipantResultInfo(participant.name(), participantsProfits.get(participant)); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package domain.game; | ||
|
|
||
| import domain.participant.Dealer; | ||
| import domain.participant.Player; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class ProfitCalculator { | ||
| public static BigDecimal calculatePlayerProfit(Player player, Dealer dealer) { | ||
| WinningStatus winningStatus = WinningStatus.of(player, dealer); | ||
| BigDecimal betAmount = player.betAmount(); | ||
|
|
||
| if (player.isBlackjack() && winningStatus == WinningStatus.WIN) { | ||
| return betAmount.multiply(BigDecimal.valueOf(1.5)); | ||
| } | ||
|
|
||
| if (winningStatus == WinningStatus.WIN) { | ||
| return betAmount; | ||
| } | ||
|
|
||
| if (winningStatus == WinningStatus.TIE) { | ||
| return BigDecimal.ZERO; | ||
| } | ||
|
|
||
| return betAmount.negate(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,26 @@ | ||
| package domain.participant; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import static domain.BlackjackRule.BLACK_JACK; | ||
|
|
||
| public class Player extends Participant { | ||
| private BigDecimal betAmount = BigDecimal.ZERO; | ||
|
Member
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.
μ’μ κΈ°μ€μ΄λΌκ³ μκ°ν©λλ€! μ λ λ°λμ μ견μ λμν΄μ :) μ΄κ±΄ μ κ°μΈμ μΈ μ견μ΄κ³ , λ°λμ μ£Όμ₯κ³Ό κ·Όκ±°λ νλΉνλ€κ³ μκ°ν©λλ€!
Author
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. μ¬μ€ μ΄μ κΉμ§λ νμμ μμ κ΅³μ΄ λμ λνν΄μΌ ν κΉ νλ μκ°μ΄ μμλλ°, |
||
|
|
||
| public Player(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canDraw() { | ||
| return super.score() <= BLACK_JACK; | ||
| return super.score() < BLACK_JACK; | ||
| } | ||
|
|
||
| public void bet(BigDecimal betAmount) { | ||
| this.betAmount = betAmount; | ||
| } | ||
|
|
||
| public BigDecimal betAmount() { | ||
| return betAmount; | ||
| } | ||
| } | ||
This file was deleted.
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.
μΌκΈμ»¬λ μ μμμ μμλ₯Ό λ°μ λ€ κ·Έ μμκ° playerκ° λ³κ²½λλ ꡬ쑰λ€μ!
ꡬ쑰μ μΌλ‘ λΆμμ ν ννκ° λλ κ² κ°μλ° μ΄λ»κ² μμ μ μΈ ννλ‘λ§λ€μ΄ λ³Ό μ μμκΉμ?
λ°©μ΄μ 볡μ¬λ₯Ό μ μ©ν΄λ³΄μμ£ !
Uh oh!
There was an error while loading. Please reload this page.
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.
λ§μν΄μ£Όμ λ΄μ©μ λ°νμΌλ‘ playersλ₯Ό λ°ννλ λΆλΆμμ λ°©μ΄μ 볡μ¬λ₯Ό μ μ©νμμ΅λλ€!
κ·Έλ°λ° κ°λ°μ νλ€κ° ν κ°μ§ κ³ λ―Όνλ λΆλΆμ΄ μκ°λ¬μ΅λλ€.
[μ΄λ¦μ μ λ ₯ λ°μ Player κ°μ²΄λ₯Ό μμ±ν ν, λ² ν κΈμ‘μ μ λ ₯ λ°λ λ°©μ] VS [μ΄λ¦κ³Ό λ² ν κΈμ‘μ λͺ¨λ μ λ ₯ λ°μ ν Player κ°μ²΄λ₯Ό μμ±νλ λ°©μ] μ€ λ¬΄μμ΄ λ μ μ ν μ§ κ³ λ―Όλμμ΅λλ€..!
κ°μΈμ μΌλ‘ μ½λλ₯Ό μμ±ν λΉμμλ μ΄λ¦μ μ λ ₯λ°μ Player κ°μ²΄λ₯Ό μμ±ν ν λ² ν κΈμ‘μ μ λ ₯ λ°λ κ²μ΄ μ€μ κ²μ νλ¦κ³Ό λ μ μ¬νλ€κ³ μκ°ν΄μ μ΄λ κ² μμ±νλλ°, κ·Έλ‘ μΈν΄ μ λ° μ½λκ° λμ€κ² λ κ² κ°μμ!
νΉμ μ΄λ¦κ³Ό λ² ν κΈμ‘μ λͺ¨λ μ λ ₯λ°μ λ€ Player κ°μ²΄λ₯Ό μμ±νλ λ°©μμ΄ λ μ μ ν μ€κ³μΌμ§ κΆκΈν©λλ€!