summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 10 insertions, 10 deletions
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!")
}