Proposed API Updates (January 2023) #227
Replies: 2 comments
-
Copying my comments over from the gist Chatted through this with myself on Stream! Leaving my notes here, but I will try to add a link to the VOD when I finish streaming! Corey's Thoughts: Proposed Battlesnake API Changes Jan 20231. TTL for Food and Hazard
2. Allow maps to vary the amount healed and damage received by individual Food and Hazards.
3. Replace game.ruleset with a new game.rules object
4. Convert game.map from a string to an objectGeneral thoughts about rules vs maps is above
Do these changes warrant a new API version?Yes I'm a big fan of Semver, and would love at least a semver inspired version here. So if this isn't be a breaking change to
Oh ya this feels like a breaking change... If we can come up with a 'renamed' key, I feel like doing a
This would obv be more work... But do we want some kinda of 'grace-period' where snakes can opt into the new or older 'schema's? If we do something like that do we maybe want to ship a Other ThoughtsPut new
|
Beta Was this translation helpful? Give feedback.
-
Copy of my previous comments on Discord and the Gist: From Discord #general-chat
From the Gist
|
Beta Was this translation helpful? Give feedback.
-
Proposed API Changes (January 2023)
As part of our move to competitive Leaderboards we're proposing the following updates to the Battlesnake API.
This post and design brief serves as a discussion point for community feedback.
1. Allow Maps to indicate when Food and Hazards will be automatically removed
We'd like to encourage more Maps that remove Food and Hazards as part of their core mechanics. Ideally this is communicated to Battlesnakes in advance, to avoid the frustration of Food randomly disappearing.
We propose adding a
ttl
property ("turns to live") to Food and Hazard objects.Questions and Considerations
What about food and hazards that will never be removed automatically?
This is a required use case, in order to support the current Map behavior. This design document proposes that in thoses cases, the
ttl
property is omitted entirely (rather than setting it tonull
or some other special value), making this new property optional.Are objects removed when
ttl
is 1 or 0?Removing after
ttl
is 0 seems to make the most sense.This is best stated by @coreyja: "Objects with a
ttl
of 0 will NOT be on the board next turn".What happens if a Battlesnake moves on to Food/Hazard the same turn it's removed?
The current engine allows Battlesnakes to consume food on turns their health would naturally reach zero. This sets an interesting precedent of siding in the favor of the Battlesnake in these situations, and likely one that we should continue.
@chillfox stated this as: "Once you take the greater context into account it's consistent to always 'lean' in favor of the snake."
For those reasons, we're proposing the following:
2. Allow Maps to vary the amount healed and damage received by individual Food and Hazards.
In 2022 we experimented heavily with stacked Hazards (placing multiple Hazards on the same location, causing an increase in damage for that particular square). The results were a lot of fun, and since then we've heard a few awesome Map ideas that would expand on this.
One reasonable concern about this approach is that it means Hazard and Food coordinates are not unique on the board, meaning API requests could potentially be of unbounded size. This is not great for highly optimized Battlesnakes.
Rather than encourage object stacking, we'd like to propose adding variability to individual Food and Hazards in the form of new properties for each.
Food.heal
will indicate the maximum amount of health restored by consuming this particular food.Hazard.damage
will indicate the amount of additional damage received by entering this location.Examples:
It's generally expected that these values will not change over the lifetime of the object on the game board, however this will ultimately be up to the Map to decide. There may be particularly interesting use cases for Maps that modify this value between turns, such as Food or Hazards that decay over time.
Questions and Considerations
Are these properties optional?
No, it's proposed that these properties will be required on all Food and Hazard definitions. The alternative would require some additional global default being set and subsequently read and applied by Battlesnakes, which is more cumbersome and error-prone than just making it a required property.
Why
Food.heal
andHazard.damage
?We had considered something more generic, such as
value
, that would allow both object types to be parsed by the same definition. One reason to not take that approach is that these objects may naturally diverge over time and we'd be okay with that. Another is something generic likevalue
still requires interpretation.Ultimately we prefered the semantic value and readability provided by context-specific
heal
anddamage
.Can these values be negative? What about zero?
Sure! Why not. It's easy enough to code for on both the engine and Battlesnake side, and could open doors for creative Maps in the future.
How is the current behavior represented (food always heals to full)?
To start, we'll use the max health value to indicate fodo that heals Battlesnakes to full. This follows the healing algorithm of
snake.health = max(snake.health + food.heal, MAX_HEALTH)
. In the future we could provide the maximum health value as a game configuration property.3. Replace
game.ruleset
with a newgame.rules
objectBattlesnake "rulesets" are a legacy concept that are no longer used by the game engine (which is now based on Maps and pipelines). Additionally, over time the
ruleset
object has been expanded rather hap-hazardly.We propose replacing it with something more appropriate.
Current Behavior
A lot of these properties are deprecated, now controlled by individual Maps.
Proposed Behavior
A new
game.rules
object that holds configuration coming from the game rules (rather than the Map). Note that we'd call itrules
and notruleset
in an effort to match the rules repo name.Beyond version information, we don't have much else to add to this object right now.
Open Questions
4. Convert
game.map
from a string to an objectMaps are the future. Over time we'd like to push more game control into Map definitions, including out of bounds handling, food and hazard ttls, and even special elimination conditions. Eventually challenges could/will be written as Maps as well.
Providing more Map-specific information in the API is going to become increasingly important. Right now this information is provided rather hap-hazardly as part of the
games.ruleset
object (see above), andmap
is simply a string id. We'd like to change this to support additional Map meta information.Current Behavior
Map information is constrained to a single string identifier.
Proposed Behavior
Convert
game.map
into an object that includes metadata about the Map and its configuration for this particular game.Open Questions
map.author
actually useful here?map.name
?5. Do these changes warrant a new API version?
Technically all proposed changes are additive (and most likely non-breaking), with the one exception of
game.map
becoming an object instead of a string. Does this warrant a full version bump?If so, this would be the first major bump we've done during active play. How do we handle API version
"1"
?Beta Was this translation helpful? Give feedback.
All reactions