Skip to content
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

Castle Wall Hazard Map #101

Merged
merged 15 commits into from
Aug 26, 2022
Merged

Conversation

bcambl
Copy link
Contributor

@bcambl bcambl commented Aug 14, 2022

Castle Wall Map

Gameplay Notes

  • All snakes start outside of the walls.
  • Food only spawns on the bridges and only one food can spawn per bridge at a time on larger boards (double walls)
  • Crossing bridges should be handled with caution as the hazard on either side is double layered.
  • Food does not spawn for the first 10 turns with only 2-4 food thereafter based on board size.
  • --hazardDamagePerTurn 50 will require snakes to commit to crossing the bridges and/or collecting food.

Support Matrix

Board Size Max Snakes Max Food
11x11 8 2 (turn 10+)
19x19 8 2 (turn 10+)
25x25 12 4 (turn 10+)

Board Examples

11x11

19x19

25x25

Thoughts/Concerns/Discussions

  • All maps will spawn snakes in the corner positions first. Should the first 4 snakes be placed near the bridges first instead?
  • Map could support more snakes by adding spawns inside the castle but deviates from the idea of all snakes starting outside.
  • All starting positions, hazards, and food are static and therefore opted for static assignment (with help from community developed tools) for performance vs generated by code.

Open to any/all suggestions or feedback from the team and community.

EDIT: Removed uninteresting map sizes and refactored PR to align with work completed in #103

Wall of hazards around the board with dangerous bridges.

- add support for all standard board sizes
- hazard placement for all board sizes
support 12 snakes on XLarge and XXLarge board sizes
@bvanvugt
Copy link
Member

@bcambl Ooooo, this is a fun one!

@bcambl bcambl changed the title Castle wall map wip - Castle wall map Aug 22, 2022
@bcambl
Copy link
Contributor Author

bcambl commented Aug 22, 2022

Marked as wip while reorganizing into individual map sizes.

@bcambl bcambl changed the title wip - Castle wall map Castle Wall Hazard Map Aug 24, 2022
}

// only support 8 or less snakes on boards smaller than XLarge
if (len(initialBoardState.Snakes) > 8) && (initialBoardState.Width < rules.BoardSizeXLarge) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could pass in the maximum allowed snakes as a parameter for the function and just do one check and then have each map provide a value that is associated with the map. I would try my best to keep setupCastleWallBoard relatively independent of board size, you can handle that logic in the different maps themselves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can just have one check that returns ErrorTooManySnakes

}

// add positions 9-12 for xlarge board size
if (initialBoardState.Width >= rules.BoardSizeXLarge) && (len(initialBoardState.Snakes) > 8) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much like above, could you pass in the set of starting positions to use into this function and have the CastleWallExtraLargeHazardsMap do this check and pass in the expanded set of starting positions? That way this function just has to use the start positions it is given

return nil
}

// max of 2 food on medium & large board
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concept as above, pass in the max food as a parameter since it seems to be linked to map size, and just do one if statement


rand := settings.GetRand(lastBoardState.Turn)

rand.Shuffle(len(castleWallMediumFood), func(i int, j int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misreading it, but i'm unsure why you are using the castleWallMediumFood constant here, is it supposed to be the food array provided as a parameter to the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most definitely was supposed to be food. An unfortunate side effect of a late night refactor of a refactor.

@bcambl
Copy link
Contributor Author

bcambl commented Aug 25, 2022

@chris-bsnake Thank you for taking time to review this PR. I have made changes based on your feedback. Please re-review and let me know if the latest commit resolves your concerns.

@bcambl bcambl requested review from chris-bsnake and removed request for robbles and bvanvugt August 25, 2022 06:04
Copy link
Contributor

@robbles robbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcambl Thanks for making those changes!

I've got a couple of optional suggestions, but otherwise this is looking good! LMK what you think - I'm happy to merge this if you don't want to spend any more time on it 😄

break snakeLoop
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like if a food overlaps with a snake body, this will still check all the existing food for collisions as well, right?
It's not a huge deal since the lists of food are relatively short and you've already made it break early when food is placed. I think this could be simplified a bit though by dropping the tileIsOccupied var and replacing the break statements with a continue to the outermost (food) loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and you are correct. I will re-work this section.
Same issue may also exist in arcade_maze as that is where I copied from in attempt to match the project:

for _, food := range foodPositions {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I'm not that surprised that this logic came from one of the other maps 😅
We're hoping to move a lot of this common repetitive logic into the Editor object in the near future, and we can standardize on the right way to do it at that point.

if err != nil {
return err
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny style nitpick: This could just be

return setupCastleWallBoard(...)

(same for the other Setup/Update methods)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Funnily enough, I actually switched to the long-hand version in my previous commit for the update func to match the style of the latest rivers_and_bridges refactor.


"github.com/stretchr/testify/require"
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally optional as these tests work just fine:
These 3 tests all seem to have the same logic, just different values for the map, sizes, and start positions. They could probably be a single table-driven test using

t.Run(m.ID(), func(t *testing.T) {

for each map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I will re-write this.

- fixes forced food spawning infront of snake issue on large & xlarge maps with double walls
@bcambl
Copy link
Contributor Author

bcambl commented Aug 26, 2022

@robbles @chris-bsnake this PR should be ready for another look.
Please let me know if either of you have any additional concerns as I am happy to make the changes.

Copy link
Contributor

@robbles robbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks again @bcambl!

@robbles robbles merged commit ba3b882 into BattlesnakeOfficial:main Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants