class BattleSnake::Context


A BattleSnake::Context is the representation of the game as it arrives from the Webhook API request to src/ endpoints.

The context's key method is #valid_moves

Included Modules

Defined in:



Instance Method Summary

Constructor Detail

def : JSON::PullParser) #

[View source]

Instance Method Detail

def board : Board #

[View source]
def board=(board : Board) #

[View source]
def check_collisions #

Checks collisions from snakes on the board and removes snakes that die

[View source]
def dup #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.

[View source]
def enemies #

[View source]
def game : Game #

[View source]
def game=(game : Game) #

[View source]
def move(snake_id, direction) #

Simulate a move of a snake in some direction

[View source]
def turn : Int32 #

[View source]
def turn=(turn : Int32) #

[View source]
def valid_moves(point : Point) #

Returns a hash with all the valid :moves and :neighbors available from a given BattleSnake::Point.

:moves is an Array(BattleSnake::Point) that containts the directions from the given #point that are valid to move without dying ("up"/"left"/"down"/"right").

:neighbors is a {} of String => BattleSnake::Point that contains those directions' coordinates.


=> {
  moves: [ "up", "right" ],
  neighbors: {,1),,2) }

NOTE A common method to help manipulate the results is BattleSnake::Point#move?. An example of this in practice is the Strategy::Utils.a_star method implementation.

TODO Take into account the last point of snakes that will move on next turn, which would be in fact valid moves (not counted at the moment).

[View source]
def you : Snake #

[View source]
def you=(you : Snake) #

[View source]