Skip to content

Commit

Permalink
Not offered insurance if you can't afford it
Browse files Browse the repository at this point in the history
  • Loading branch information
Qluxzz committed Nov 2, 2024
1 parent 7651de8 commit 8137973
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,18 @@ view model =
]
)
++ [ if model.state == HitOrStand && canBuyInsurance model.dealer then
insuranceView
let
currentPlayer =
model.players |> Tuple.first

currentBet =
currentPlayer.hands |> Tuple.first |> .bet
in
if currentPlayer.money > currentBet // 2 then
insuranceView

else
Html.text ""

else
Html.text ""
Expand Down
19 changes: 16 additions & 3 deletions tests/GameTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,20 @@ suite =
|> ProgramTest.advanceTime 4
-- Deal four cards
|> ProgramTest.expectViewHas
[ Selector.exactText "Buy insurance?", Selector.exactText "Yes", Selector.exactText "No" ]
[ Selector.exactText "Buy insurance?" ]
, test "You're not offered insurance if you can't afford it" <|
\_ ->
start
(defaultSettings
|> withDeck [ Card.Card Card.Ten Card.Spades, Card.Card Card.Ace Card.Spades, Card.Card Card.King Card.Diamonds, Card.Card Card.King Card.Clubs ]
|> withDelay
|> withPlayers ( { money = 100 }, [] )
)
|> clickMarker 100
|> ProgramTest.advanceTime 5
-- Deal four cards
|> ProgramTest.expectViewHasNot
[ Selector.exactText "Buy insurance?" ]
, test "If you buy insurance and the dealer has a blackjack, it pays out 2 to 1, so you get back your initial bet" <|
\_ ->
start
Expand All @@ -482,7 +495,7 @@ suite =
|> ProgramTest.advanceTime 4
-- Deal four cards
|> ProgramTest.ensureViewHas
[ Selector.exactText "Buy insurance?", Selector.exactText "Yes", Selector.exactText "No" ]
[ Selector.exactText "Buy insurance?" ]
|> ProgramTest.clickButton "Yes"
|> ProgramTest.advanceTime 2
|> ProgramTest.ensureView (toastHasMessage "You got your bet back!")
Expand All @@ -498,7 +511,7 @@ suite =
|> ProgramTest.advanceTime 4
-- Deal four cards
|> ProgramTest.ensureViewHas
[ Selector.exactText "Buy insurance?", Selector.exactText "Yes", Selector.exactText "No" ]
[ Selector.exactText "Buy insurance?" ]
|> ProgramTest.clickButton "No"
|> ProgramTest.clickButton "Stand"
|> ProgramTest.advanceTime 2
Expand Down

0 comments on commit 8137973

Please sign in to comment.