fix percentage bar fill

This commit is contained in:
Joseph Montanaro 2021-10-22 10:34:43 -07:00
parent 29e3e70712
commit ef134a9a6e
2 changed files with 5 additions and 4 deletions

View File

@ -7,11 +7,12 @@ when isMainModule:
b.init b.init
b.setState(config.state, []) b.setState(config.state, [])
b.diceRolled = config.diceRolled b.diceRolled = config.diceRolled
echo b.showSpaces(1, 16)
let legScores = b.getLegScores let legScores = b.getLegScores
let gameScores = b.randomGames(1_000_000)
echo b.showSpaces(1, 16)
echo "\nCurrent leg probabilities:" echo "\nCurrent leg probabilities:"
echo legScores.showPercents() echo legScores.showPercents()
let gameScores = b.randomGames(1_000_000)
echo "\nFull game probabilities (1M simulations):" echo "\nFull game probabilities (1M simulations):"
echo gameScores.showPercents() echo gameScores.showPercents()

2
ui.nim
View File

@ -112,7 +112,7 @@ proc showPercents*(scores: ScoreSet): string =
var bar = repeat(" ", 20) var bar = repeat(" ", 20)
let percentage = round(pct * 100, 2) let percentage = round(pct * 100, 2)
# populate the progress bar # populate the progress bar
let barFill = int(round(pct * 100 / 20)) let barFill = int(round(pct * 20))
for i in 0 ..< barFill: for i in 0 ..< barFill:
bar[i] = '=' bar[i] = '='