Skip to content

Commit

Permalink
Added guessedOn.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdangle committed Jul 13, 2023
1 parent 9f35428 commit 73d8ec1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hw8/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ type player struct {
gameCh chan round
}
type guess struct {
roundId int
playerId int
number int
roundId int
playerId int
number int
guessedOn time.Time
}
type winner struct {
roundId int
Expand Down Expand Up @@ -101,7 +102,7 @@ func refereeRtn(ctx context.Context, players []*player, guessChan chan guess, re
}
fmt.Printf("\nThe winners for round %d are players %v !", prevRound, winners)
// TODO: remove 0
winnerCh <- winner{roundId: prevRound, playerId:0}
winnerCh <- winner{roundId: prevRound, playerId: 0}
}
}
}
Expand Down Expand Up @@ -154,7 +155,7 @@ func playerRtn(ctx context.Context, p *player, guesses chan guess, wg *sync.Wait
fmt.Printf("\nGorutine for player %d is shutting down...", p.id)
return
case round := <-p.gameCh:
guess := guess{roundId: round.id, playerId: p.id, number: rand.Intn(5)}
guess := guess{roundId: round.id, playerId: p.id, number: rand.Intn(4), guessedOn: time.Now()}
time.Sleep(time.Duration(guess.number) * time.Second)
guesses <- guess
fmt.Printf("\nPlayer %d for round number %d sent guess %d", p.id, round.id, guess.number)
Expand Down

0 comments on commit 73d8ec1

Please sign in to comment.