Documentation ¶
Overview ¶
This file contains state structures for a Tron game. These tron games are a 2-dimensional grid with arbitrary numbers of players.
Index ¶
Constants ¶
const ( DirectionNorth = "north" DirectionEast = "east" DirectionSouth = "south" DirectionWest = "west" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TronState ¶
type TronState struct { // A map of x, y coordinates to player indices, indicating which cells are // part of which player's "trail". The keys are strings due to those being // the only supported type by the JSON library. Cells map[string]map[string]int `json:"cells"` // The players slice is simply a lookup of a player's position, where each // player is tracked by its index in this list. If the player's position is // (-1, -1) then the player is dead. Players []TronCoord `json:"players"` // track the current direction the players are traveling in Directions []string // The width and height of the game grid. Width int `json:"w"` Height int `json:"h"` }
The state of the tron world, holds lists of coordinates for an arbitrary number of players. The top left cell is coordinate (0,0) like screen coords.
func NewTwoPlayerTron ¶
Build a blank tron world with 2 players.
func (*TronState) Actions ¶
Returns the possible actions an agent can make given the current state. Each action is a unit tuple of directions that the player can travel in.
func (*TronState) Do ¶
Commit an action for a player. The direction will be sent as a generic interface, and casted into the expected string
func (*TronState) Finished ¶
Check if the game is over. This happens if all but one player is dead. TODO: Currently this assumes only a 2 player game
func (*TronState) Result ¶
Collect the result of the game TODO: Currently this assumes a 2-player game.