Skip to content

Commit

Permalink
extract currentMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Aug 25, 2020
1 parent 9703291 commit cbd685d
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions src/Main.elm
Expand Up @@ -241,78 +241,83 @@ view model =
, newPlayerForm model
, Html.button [ Events.onClick KeeperWantsToSaveStandings ] [ Html.text "Save Standings" ]
, Html.button [ Events.onClick KeeperWantsToLoadStandings ] [ Html.text "Load Standings" ]
, case model.currentMatch of
Just ( playerA, playerB ) ->
let
chanceAWins =
Elo.odds playerA.rating playerB.rating
, currentMatch model
]
|> Html.toUnstyled
]
}


currentMatch : Model -> Html Msg
currentMatch model =
case model.currentMatch of
Just ( playerA, playerB ) ->
let
chanceAWins =
Elo.odds playerA.rating playerB.rating

chanceBWins =
1 - chanceAWins
chanceBWins =
1 - chanceAWins

( ratingAWins, _ ) =
newRating playerA.rating Elo.WonAgainst playerB.rating
( ratingAWins, _ ) =
newRating playerA.rating Elo.WonAgainst playerB.rating

( ratingBWins, _ ) =
newRating playerB.rating Elo.WonAgainst playerA.rating
( ratingBWins, _ ) =
newRating playerB.rating Elo.WonAgainst playerA.rating

upsideA =
ratingAWins - playerA.rating
upsideA =
ratingAWins - playerA.rating

upsideB =
ratingBWins - playerB.rating
in
Html.section
upsideB =
ratingBWins - playerB.rating
in
Html.section
[ css
[ Css.maxWidth (Css.px 1024)
, Css.margin2 Css.zero Css.auto
]
]
[ Html.div
[ css [ Css.backgroundColor (Css.hex "#EEE"), Css.displayFlex ] ]
[ Html.p
[ css
[ Css.maxWidth (Css.px 1024)
, Css.margin2 Css.zero Css.auto
[ Css.flexGrow (Css.num chanceAWins)
, Css.paddingRight (Css.px 5)
, Css.textAlign Css.right
, Css.backgroundColor (Css.hex "#1E90FF")
, Css.lineHeight (Css.px 50)
, Css.margin Css.zero
]
]
[ Html.div
[ css [ Css.backgroundColor (Css.hex "#EEE"), Css.displayFlex ] ]
[ Html.p
[ css
[ Css.flexGrow (Css.num chanceAWins)
, Css.paddingRight (Css.px 5)
, Css.textAlign Css.right
, Css.backgroundColor (Css.hex "#1E90FF")
, Css.lineHeight (Css.px 50)
, Css.margin Css.zero
]
]
[ Html.text (percent chanceAWins) ]
, Html.p
[ css
[ Css.flexGrow (Css.num (1 - chanceAWins))
, Css.paddingLeft (Css.px 5)
, Css.lineHeight (Css.px 50)
, Css.margin Css.zero
]
]
[ Html.text (percent (1 - chanceAWins)) ]
]
, Html.div
[ css
[ Css.displayFlex
, Css.justifyContent Css.spaceAround
, Css.width (Css.pct 100)
]
]
[ activePlayer chanceAWins playerA upsideA (MatchFinished playerA Elo.WonAgainst playerB)
, Html.div []
[ Html.p [] [ Html.text "vs." ]
, Html.button [ Events.onClick (MatchFinished playerA Elo.DrewWith playerB) ] [ Html.text "It's a tie!" ]
]
, activePlayer (1 - chanceAWins) playerB upsideB (MatchFinished playerB Elo.WonAgainst playerA)
[ Html.text (percent chanceAWins) ]
, Html.p
[ css
[ Css.flexGrow (Css.num (1 - chanceAWins))
, Css.paddingLeft (Css.px 5)
, Css.lineHeight (Css.px 50)
, Css.margin Css.zero
]
]
[ Html.text (percent (1 - chanceAWins)) ]
]
, Html.div
[ css
[ Css.displayFlex
, Css.justifyContent Css.spaceAround
, Css.width (Css.pct 100)
]
]
[ activePlayer chanceAWins playerA upsideA (MatchFinished playerA Elo.WonAgainst playerB)
, Html.div []
[ Html.p [] [ Html.text "vs." ]
, Html.button [ Events.onClick (MatchFinished playerA Elo.DrewWith playerB) ] [ Html.text "It's a tie!" ]
]
, activePlayer (1 - chanceAWins) playerB upsideB (MatchFinished playerB Elo.WonAgainst playerA)
]
]

Nothing ->
Html.text "no match right now... add some players, maybe?"
]
|> Html.toUnstyled
]
}
Nothing ->
Html.text "no match right now... add some players, maybe?"


activePlayer : Float -> Player -> Int -> Msg -> Html Msg
Expand Down

0 comments on commit cbd685d

Please sign in to comment.