Documentation ¶
Overview ¶
=========================================================================== > Game of Life and War ___________________________________________________________________________
Grid Square Types ¶
0 = Neutral 1 = Player 1 2 = Player 2 3 = Red 4 = Pink [5 - 10] = Red, in different
Credits ¶
- Joshua Fan - The Idea for the "Game of War" - Golang.org - Code Snippets for Implementation of Conway's Game of Life - John Horton Conway - For inventing the "Game of Life" ___________________________________________________________________________ ===========================================================================
Index ¶
- Constants
- func Abundance(neighborhood map[uint8]uint8) ([]uint8, uint8)
- type Field
- type GameInstance
- type GridState
- type Life
- type Neighborhood
- func (n *Neighborhood) Count(cellValue uint8) uint8
- func (n *Neighborhood) East() uint8
- func (n *Neighborhood) North() uint8
- func (n *Neighborhood) NorthEast() uint8
- func (n *Neighborhood) NorthWest() uint8
- func (n *Neighborhood) South() uint8
- func (n *Neighborhood) SouthEast() uint8
- func (n *Neighborhood) SouthWest() uint8
- func (n *Neighborhood) West() uint8
Constants ¶
const ( MIN_GAME_SPEED = 1 MAX_GAME_SPEED = 2 )
Variables ¶
This section is empty.
Functions ¶
func Abundance ¶
WhoEatsMe returns the color that consumes the specified color, if nearby. If will only return a 0 if it passes through all of the cases.
func WhoEatsMe(myColor uint8) uint8 { switch myColor { case 0: return 3 // empty <- red case 1: return 2 // 1 <- 2 case 2: return 1 // 2 <- 1 case 3: return 4 case 4: return 5 case 5: return 6 case 6: return 3 } return 0 // empty eaten by empty // uint8(rand.Intn(5)) }
Abundance the color(s), which corresponds to a value [1-3], and the number of counted neighbors of that color [0-8]. Since there could be a tie for the highest count, multiple colors are returned in an array.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a two-dimensional field of cells.
type GameInstance ¶
type GameInstance struct {
// contains filtered or unexported fields
}
GameInstance contains all the information that would be found in the game: including the map, game state, players, and settings.
func NewGameInstance ¶
func NewGameInstance(w, h int) *GameInstance
NewGameInstance initializes a fresh game, only asking for a map size. All of the other settings start at default.
func (*GameInstance) ChangeAt ¶
func (g *GameInstance) ChangeAt(x, y int, val uint8)
func (*GameInstance) DropBomb ¶
func (g *GameInstance) DropBomb(x, y int) bool
DropBomb takes a player number (1 or 2), and a position on the grid. If that action is allowed, then it will do that action
func (*GameInstance) FreshGameBoard ¶
func (g *GameInstance) FreshGameBoard()
func (*GameInstance) LifeStateMessage ¶
func (g *GameInstance) LifeStateMessage() []byte
LifeStateMessage returns an encoded Json message, ready to be sent.
func (*GameInstance) LifeUpdate ¶
func (g *GameInstance) LifeUpdate()
func (*GameInstance) RandomizeGameBoard ¶
func (g *GameInstance) RandomizeGameBoard(numberToMake int)
ResetGameInstance will randomly create player squares. The amount of player squares to make is specified by the "numberToMake".
type Life ¶
type Life struct {
// contains filtered or unexported fields
}
Life stores the state of a round of Conway's Game of Life.
type Neighborhood ¶
type Neighborhood struct {
// contains filtered or unexported fields
}
Neighborhood stores 2 useful maps: 1. The cell values based on location, 2. The total number of cells found nearby, based on a specific cell value.
func NewMooreNeighborhood ¶
func NewMooreNeighborhood(f *Field, x, y int) *Neighborhood
NewMooreNeighborhood returns a neighborhood of cells that include the 4 cardinal directions and the 4 diagonals, for a total of 8 nearby cells.
func (*Neighborhood) Count ¶
func (n *Neighborhood) Count(cellValue uint8) uint8
Count returns the total number of cells in the neighborhood that contain the specified value.
func (*Neighborhood) East ¶
func (n *Neighborhood) East() uint8
East returns the value at coordinate (+1, +0) relative to center.
func (*Neighborhood) North ¶
func (n *Neighborhood) North() uint8
North returns the value at coordinate (+0, -1) relative to center.
func (*Neighborhood) NorthEast ¶
func (n *Neighborhood) NorthEast() uint8
NorthEast returns the value at coordinate (+1, -1) relative to center.
func (*Neighborhood) NorthWest ¶
func (n *Neighborhood) NorthWest() uint8
NorthWest returns the value at coordinate (-1, -1) relative to center.
func (*Neighborhood) South ¶
func (n *Neighborhood) South() uint8
South returns the value at coordinate (+0, +1) relative to center.
func (*Neighborhood) SouthEast ¶
func (n *Neighborhood) SouthEast() uint8
SouthEast returns the value at coordinate (+1, +1) relative to center.
func (*Neighborhood) SouthWest ¶
func (n *Neighborhood) SouthWest() uint8
SouthWest returns the value at coordinate (+1, -1) relative to center.
func (*Neighborhood) West ¶
func (n *Neighborhood) West() uint8
West returns the value at coordinate (-1, +0) relative to center.