diff options
| author | Brandon C. Irizarry <brandon.irizarry@gmail.com> | 2026-04-23 16:41:12 -0400 |
|---|---|---|
| committer | Brandon C. Irizarry <brandon.irizarry@gmail.com> | 2026-04-23 16:41:12 -0400 |
| commit | d997dfc6b7235c49c29cfb19762f496e8fcacb10 (patch) | |
| tree | f7b1d15fd3bedbf58a07bed621264fe7037a2b38 | |
| parent | 340c72e61917d1029ca45f6c5ca91f4c4c4b987d (diff) | |
feat: rename Score struct to Player
Also make appropriate renames of related variables.
| -rw-r--r-- | main.go | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -29,7 +29,7 @@ func main() { game(*numPlayers, *sides) } -type Score struct { +type Player struct { id int score int } @@ -40,9 +40,9 @@ func game(numPlayers, faces int) { winningNumber := throwDie(faces) fmt.Printf("Winning number is %d\n", winningNumber) - // The scores channel communicates the number of turns a + // The finishedPlayers channel communicates the number of turns a // player took to hit the winning number. - scores := make(chan Score) + finishedPlayers := make(chan Player) var wg sync.WaitGroup for i := range numPlayers { @@ -60,7 +60,7 @@ func game(numPlayers, faces int) { if outcome == winningNumber { fmt.Printf("Player %d threw the winning number! Their score is %d\n", id, score) - scores <- Score{id: id, score: score} + finishedPlayers <- Player{id: id, score: score} return } @@ -71,18 +71,18 @@ func game(numPlayers, faces int) { go func() { wg.Wait() - close(scores) + close(finishedPlayers) }() - minScore := Score{score: math.MaxInt} + minFinishedPlayer := Player{score: math.MaxInt} - for score := range scores { - if score.score < minScore.score { - minScore = score + for score := range finishedPlayers { + if score.score < minFinishedPlayer.score { + minFinishedPlayer = score } } - fmt.Printf("Player %d won with a score of %d\n", minScore.id, minScore.score) + fmt.Printf("Player %d won with a score of %d\n", minFinishedPlayer.id, minFinishedPlayer.score) fmt.Println("Thanks for playing!") } |
