From d997dfc6b7235c49c29cfb19762f496e8fcacb10 Mon Sep 17 00:00:00 2001 From: "Brandon C. Irizarry" Date: Thu, 23 Apr 2026 16:41:12 -0400 Subject: feat: rename Score struct to Player Also make appropriate renames of related variables. --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5d0829e..92e9b22 100644 --- a/main.go +++ b/main.go @@ -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!") } -- cgit v1.2.3