go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/matchmaker/pkg/sim/game.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package sim
     9  
    10  import (
    11  	"time"
    12  
    13  	"go.charczuk.com/sdk/uuid"
    14  )
    15  
    16  type Game struct {
    17  	ID          uuid.UUID
    18  	TeamA       PlayerLookup
    19  	RatingTeamA int
    20  	TeamB       PlayerLookup
    21  	RatingTeamB int
    22  	StartedAt   time.Time
    23  	FinishedAt  time.Time
    24  	Outcome     Team
    25  }
    26  
    27  func (g Game) Done(currentTimestamp time.Time) bool {
    28  	return g.FinishedAt.Before(currentTimestamp)
    29  }
    30  
    31  func (g Game) PlayerTeam(id uuid.UUID) Team {
    32  	if ok := g.TeamA.HasKey(id); ok {
    33  		return TeamA
    34  	}
    35  	if ok := g.TeamB.HasKey(id); ok {
    36  		return TeamB
    37  	}
    38  	return TeamUnknown
    39  }