DEV-765 pipeline refactor (#64)
Refactor rulesets into smaller composable operations In order to mix up the functionality from different rulesets like Solo, Royale, etc. the code in these classes needs to be broken up into small functions that can be composed in a pipeline to make a custom game mode.
This commit is contained in:
parent
5e629e9e93
commit
397d925110
25 changed files with 1475 additions and 222 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package client
|
||||
|
||||
import "github.com/BattlesnakeOfficial/rules"
|
||||
|
||||
func exampleSnakeRequest() SnakeRequest {
|
||||
return SnakeRequest{
|
||||
Game: Game{
|
||||
|
|
@ -72,18 +74,18 @@ func exampleSnakeRequest() SnakeRequest {
|
|||
}
|
||||
}
|
||||
|
||||
var exampleRulesetSettings = RulesetSettings{
|
||||
var exampleRulesetSettings = rules.Settings{
|
||||
FoodSpawnChance: 10,
|
||||
MinimumFood: 20,
|
||||
HazardDamagePerTurn: 30,
|
||||
HazardMap: "hz_spiral",
|
||||
HazardMapAuthor: "altersaddle",
|
||||
|
||||
RoyaleSettings: RoyaleSettings{
|
||||
RoyaleSettings: rules.RoyaleSettings{
|
||||
ShrinkEveryNTurns: 40,
|
||||
},
|
||||
|
||||
SquadSettings: SquadSettings{
|
||||
SquadSettings: rules.SquadSettings{
|
||||
AllowBodyCollisions: true,
|
||||
SharedElimination: true,
|
||||
SharedHealth: true,
|
||||
|
|
|
|||
|
|
@ -48,31 +48,19 @@ type Customizations struct {
|
|||
}
|
||||
|
||||
type Ruleset struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Settings RulesetSettings `json:"settings"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Settings rules.Settings `json:"settings"`
|
||||
}
|
||||
|
||||
type RulesetSettings struct {
|
||||
FoodSpawnChance int32 `json:"foodSpawnChance"`
|
||||
MinimumFood int32 `json:"minimumFood"`
|
||||
HazardDamagePerTurn int32 `json:"hazardDamagePerTurn"`
|
||||
HazardMap string `json:"hazardMap"`
|
||||
HazardMapAuthor string `json:"hazardMapAuthor"`
|
||||
RoyaleSettings RoyaleSettings `json:"royale"`
|
||||
SquadSettings SquadSettings `json:"squad"`
|
||||
}
|
||||
// RulesetSettings is deprecated: use rules.Settings instead
|
||||
type RulesetSettings rules.Settings
|
||||
|
||||
type RoyaleSettings struct {
|
||||
ShrinkEveryNTurns int32 `json:"shrinkEveryNTurns"`
|
||||
}
|
||||
// RoyaleSettings is deprecated: use rules.RoyaleSettings instead
|
||||
type RoyaleSettings rules.RoyaleSettings
|
||||
|
||||
type SquadSettings struct {
|
||||
AllowBodyCollisions bool `json:"allowBodyCollisions"`
|
||||
SharedElimination bool `json:"sharedElimination"`
|
||||
SharedHealth bool `json:"sharedHealth"`
|
||||
SharedLength bool `json:"sharedLength"`
|
||||
}
|
||||
// SquadSettings is deprecated: use rules.SquadSettings instead
|
||||
type SquadSettings rules.SquadSettings
|
||||
|
||||
// Coord represents a point on the board
|
||||
type Coord struct {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/BattlesnakeOfficial/rules"
|
||||
"github.com/BattlesnakeOfficial/rules/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -18,7 +19,7 @@ func TestBuildSnakeRequestJSON(t *testing.T) {
|
|||
|
||||
func TestBuildSnakeRequestJSONEmptyRulesetSettings(t *testing.T) {
|
||||
snakeRequest := exampleSnakeRequest()
|
||||
snakeRequest.Game.Ruleset.Settings = RulesetSettings{}
|
||||
snakeRequest.Game.Ruleset.Settings = rules.Settings{}
|
||||
data, err := json.MarshalIndent(snakeRequest, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue