DEV 1303: Add empty and royale maps and update game map interface (#72)

* move random generator into Settings

* add empty and royale maps

* place snakes on either cardinal or corner positions first
This commit is contained in:
Rob O'Dwyer 2022-05-17 15:45:56 -07:00 committed by GitHub
parent 6fa2da2f01
commit e94d758a9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 479 additions and 52 deletions

View file

@ -30,14 +30,22 @@ type Settings struct {
SquadSettings SquadSettings `json:"squad"`
rand Rand
seed int64
}
func (settings Settings) Rand() Rand {
// Default to global random number generator if none is set.
if settings.rand == nil {
return GlobalRand
// Get a random number generator initialized based on the seed and current turn.
func (settings Settings) GetRand(turn int32) Rand {
// Allow overriding the random generator for testing
if settings.rand != nil {
return settings.rand
}
return settings.rand
if settings.seed != 0 {
return NewSeedRand(settings.seed + int64(turn+1))
}
// Default to global random number generator if neither seed or rand are set.
return GlobalRand
}
func (settings Settings) WithRand(rand Rand) Settings {
@ -45,6 +53,15 @@ func (settings Settings) WithRand(rand Rand) Settings {
return settings
}
func (settings Settings) Seed() int64 {
return settings.seed
}
func (settings Settings) WithSeed(seed int64) Settings {
settings.seed = seed
return settings
}
// RoyaleSettings contains settings that are specific to the "royale" game mode
type RoyaleSettings struct {
seed int64
@ -92,12 +109,14 @@ func (rb *rulesetBuilder) WithParams(params map[string]string) *rulesetBuilder {
return rb
}
// Deprecated: WithSeed sets the seed used for randomisation by certain game modes.
// WithSeed sets the seed used for randomisation by certain game modes.
func (rb *rulesetBuilder) WithSeed(seed int64) *rulesetBuilder {
rb.seed = seed
return rb
}
// WithRandom overrides the random number generator with a specific instance
// instead of a Rand initialized from the seed.
func (rb *rulesetBuilder) WithRand(rand Rand) *rulesetBuilder {
rb.rand = rand
return rb
@ -190,6 +209,7 @@ func (rb rulesetBuilder) PipelineRuleset(name string, p Pipeline) PipelineRulese
SharedLength: paramsBool(rb.params, ParamSharedLength, false),
},
rand: rb.rand,
seed: rb.seed,
},
}
}