-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEV-1558-healing-pools-map #94
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package maps | ||
|
||
import ( | ||
"github.com/BattlesnakeOfficial/rules" | ||
) | ||
|
||
type HealingPoolsMap struct{} | ||
|
||
func init() { | ||
globalRegistry.RegisterMap("healing_pools", HealingPoolsMap{}) | ||
} | ||
|
||
func (m HealingPoolsMap) ID() string { | ||
return "healing_pools" | ||
} | ||
|
||
func (m HealingPoolsMap) Meta() Metadata { | ||
return Metadata{ | ||
Name: "Healing Pools", | ||
Description: "A simple map that spawns fixed single cell hazard areas based on the map size.", | ||
Author: "Battlesnake", | ||
Version: 1, | ||
MinPlayers: 1, | ||
MaxPlayers: 8, | ||
BoardSizes: FixedSizes(Dimensions{7, 7}, Dimensions{11, 11}, Dimensions{19, 19}), | ||
} | ||
} | ||
|
||
func (m HealingPoolsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error { | ||
if err := (StandardMap{}).SetupBoard(initialBoardState, settings, editor); err != nil { | ||
return err | ||
} | ||
|
||
rand := settings.GetRand(0) | ||
|
||
options, ok := poolLocationOptions[rules.Point{X: initialBoardState.Width, Y: initialBoardState.Height}] | ||
if !ok { | ||
return rules.RulesetError("board size is not supported by this map") | ||
} | ||
|
||
i := rand.Intn(len(options)) | ||
|
||
for _, p := range options[i] { | ||
editor.AddHazard(p) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m HealingPoolsMap) UpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error { | ||
return StandardMap{}.UpdateBoard(lastBoardState, settings, editor) | ||
} | ||
|
||
var poolLocationOptions = map[rules.Point][][]rules.Point{ | ||
{X: 7, Y: 7}: { | ||
{ | ||
{X: 3, Y: 3}, | ||
}, | ||
}, | ||
{X: 11, Y: 11}: { | ||
{ | ||
{X: 3, Y: 3}, | ||
{X: 7, Y: 7}, | ||
}, | ||
{ | ||
{X: 3, Y: 7}, | ||
{X: 7, Y: 3}, | ||
}, | ||
{ | ||
{X: 3, Y: 5}, | ||
{X: 7, Y: 5}, | ||
}, | ||
{ | ||
{X: 5, Y: 7}, | ||
{X: 5, Y: 3}, | ||
}, | ||
}, | ||
{X: 19, Y: 19}: { | ||
{ | ||
{X: 5, Y: 5}, | ||
{X: 13, Y: 13}, | ||
{X: 5, Y: 13}, | ||
{X: 13, Y: 5}, | ||
}, | ||
{ | ||
{X: 5, Y: 10}, | ||
{X: 13, Y: 10}, | ||
{X: 10, Y: 13}, | ||
{X: 10, Y: 5}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package maps_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/BattlesnakeOfficial/rules" | ||
"github.com/BattlesnakeOfficial/rules/maps" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHealingPoolsMap(t *testing.T) { | ||
|
||
tests := []struct { | ||
boardSize int | ||
expectedHazards int | ||
allowableHazards []rules.Point | ||
}{ | ||
{7, 1, []rules.Point{{X: 3, Y: 3}}}, | ||
{11, 2, []rules.Point{{X: 3, Y: 3}, | ||
{X: 7, Y: 7}, | ||
{X: 3, Y: 7}, | ||
{X: 7, Y: 3}, | ||
{X: 3, Y: 5}, | ||
{X: 7, Y: 5}, | ||
{X: 5, Y: 7}, | ||
{X: 5, Y: 3}}}, | ||
{19, 4, []rules.Point{{X: 5, Y: 5}, | ||
{X: 13, Y: 13}, | ||
{X: 5, Y: 13}, | ||
{X: 13, Y: 5}, | ||
{X: 5, Y: 10}, | ||
{X: 13, Y: 10}, | ||
{X: 10, Y: 13}, | ||
{X: 10, Y: 5}}}, | ||
} | ||
|
||
for _, tc := range tests { | ||
|
||
t.Run(fmt.Sprintf("%dx%d", tc.boardSize, tc.boardSize), func(t *testing.T) { | ||
m := maps.HealingPoolsMap{} | ||
state := rules.NewBoardState(tc.boardSize, tc.boardSize) | ||
settings := rules.Settings{} | ||
|
||
// ensure the ring of hazards is added to the board at setup | ||
editor := maps.NewBoardStateEditor(state) | ||
require.Empty(t, state.Hazards) | ||
err := m.SetupBoard(state, settings, editor) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, state.Hazards) | ||
require.Len(t, state.Hazards, tc.expectedHazards) | ||
|
||
for _, p := range state.Hazards { | ||
require.Contains(t, tc.allowableHazards, p) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this set of locations deliberately skewed, or is it supposed to be a box like the other one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One set should look like the corners of a box and the other set are supposed to be cardinal locations unless I got the coords wrong