|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectgameLogic.GameState
public class GameState
The GameState is a representation of the game at a given moment in time. It contains references to the game board (containing a matrix of Squares, which in turn contain all game objects), the current Metadata (turns until growth/spawning of fruit, among other things), all snakes participating in this game session, and an ErrorState enum.
Method Summary | |
---|---|
static Position |
calculateNextPosition(Direction direction,
Position oldPosition)
Gets the next position a snake would end up in if it continues in this direction. |
static int |
distanceBetween(Position from,
Position to)
This method can be used to calculate the distance between two positions. |
Board |
getBoard()
Returns a Board object, which constists of a 2D-array of Square objects. |
ErrorState |
getErrorState()
Returns the ErrorState for the previous turn, for example telling a brain it took too long to decide last turn. |
java.util.ArrayList<Position> |
getFruits()
Gets a list containing the positions of all the fruits currently on the board. |
Metadata |
getMetadata()
Method for getting the current game metadata, containing (among other things) time until the next fruit spawns and time until snake growth. |
static java.util.ArrayList<Direction> |
getRelativeDirections(Position from,
Position to)
Returns in which direction one has to move in order to reach one position from another one. |
java.util.Set<Snake> |
getSnakes()
Returns a Set containing all snakes in the game, both dead ones and alive ones. |
java.util.ArrayList<Position> |
getWalls()
Gets a list containing the positions of all the walls currently on the board. |
boolean |
willCollide(Snake snake,
Direction dir)
This method can be used to help calculate whether or not a given snake will collide next turn if it continues in a given direction. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public java.util.Set<Snake> getSnakes()
Snake
public Board getBoard()
Board
public Metadata getMetadata()
Metadata
public ErrorState getErrorState()
ErrorState
public boolean willCollide(Snake snake, Direction dir)
snake
- The snake you wish you perform the check for.dir
- The hypothetical direction in which the snake moves.
public static Position calculateNextPosition(Direction direction, Position oldPosition)
direction
- The current direction of the snake.oldPosition
- The current position of the snake.
public java.util.ArrayList<Position> getFruits()
public java.util.ArrayList<Position> getWalls()
public static java.util.ArrayList<Direction> getRelativeDirections(Position from, Position to)
WEST
if the destination postion is directly west of the starting position, or it
may contain both WEST
and NORTH
if
the destination is towards the northwest.
from
- The starting position.to
- The destination position.
public static int distanceBetween(Position from, Position to)
from
- The position from which you wish to calculate the distance.to
- The position to which you wish to calculate the distance.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |