cell

package
v0.0.0-...-74b5f4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

The cell package manages the state for the Conway's Game of Life cellular automaton.

Package cell is a generated protocol buffer package.

It is generated from these files:

field.proto

It has these top-level messages:

FieldProto

Package cell is a generated protocol buffer package.

It is generated from these files:

input.proto

It has these top-level messages:

UpdateRequest
UpdateResponse
UpdateMaskRequest
ResetFieldRequest

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(c *Field, tick <-chan time.Time, update <-chan *UpdateRequest) <-chan *Field

Run creates a channel which generates a new state for every message it recieves from tick, using the starting state c.

func ToImage

func ToImage(f *Field) *image.NRGBA

ToImage converts the lower 24 bits of a Field's state into an image.

Types

type Field

type Field struct {
	// State holds the state information. The state for the cell at (x, y)
	// is stored at State[Width * y + x].
	State []uint32
	// Width is one dimension of the 2D state. The state is of size Width
	// times Height.
	Width int
	// Height is one dimension of the 2D state. The state is of size Width
	// times Height.
	Height int
}

Field represents the entire state of a 2D cellular automaton.

func FromProto

func FromProto(f *FieldProto) (*Field, error)

FromProto converts a FieldProto into the Field struct.

Since FieldProtos can come from untrusted sources this method returns an error instead of panicing when encountering invalid Field data.

func NewField

func NewField(w, h int) *Field

NewField creates an empty 2D cellular automaton state with the given (w, h) dimensions.

func RandomField

func RandomField(w, h int) *Field

RandomField creates a random 2D cellular automaton state with the given dimensions (w, h).

It uses the lower 24 bits of state to make it easy to visualize using with an image (8 bits for each red, green, and blue).

type FieldProto

type FieldProto struct {
	// State holds the state information. The state for the cell at (x, y)
	// is stored at State[Width * y + x].
	State []uint32 `protobuf:"varint,1,rep,name=state" json:"state,omitempty"`
	// Width is one dimension of the 2D state. The state is of size Width
	// times Height.
	Width int32 `protobuf:"varint,2,opt,name=width" json:"width,omitempty"`
	// Height is one dimension of the 2D state. The state is of size Width
	// times Height.
	Height int32 `protobuf:"varint,3,opt,name=height" json:"height,omitempty"`
	// Seq is the sequence number indicating the current iteration number.
	Seq int32 `protobuf:"varint,4,opt,name=seq" json:"seq,omitempty"`
}

FieldProto represents the entire state of a 2D cellular automaton.

func ToProto

func ToProto(f *Field) *FieldProto

ToProto converts a Field into the FieldProto.

func (*FieldProto) ProtoMessage

func (*FieldProto) ProtoMessage()

func (*FieldProto) Reset

func (m *FieldProto) Reset()

func (*FieldProto) String

func (m *FieldProto) String() string

type ResetFieldRequest

type ResetFieldRequest struct {
}

ResetFieldRequest modifies the field to be a random state.

func (*ResetFieldRequest) ProtoMessage

func (*ResetFieldRequest) ProtoMessage()

func (*ResetFieldRequest) Reset

func (m *ResetFieldRequest) Reset()

func (*ResetFieldRequest) String

func (m *ResetFieldRequest) String() string

type UpdateMaskRequest

type UpdateMaskRequest struct {
	Value uint32 `protobuf:"varint,1,opt,name=value" json:"value,omitempty"`
}

UpdateMaskRequest modifies the mask used in the Game of Life calculation.

The default mask is used to filter the calculations to use every three bits for the game of life.

func (*UpdateMaskRequest) ProtoMessage

func (*UpdateMaskRequest) ProtoMessage()

func (*UpdateMaskRequest) Reset

func (m *UpdateMaskRequest) Reset()

func (*UpdateMaskRequest) String

func (m *UpdateMaskRequest) String() string

type UpdateRequest

type UpdateRequest struct {
	// Types that are valid to be assigned to Input:
	//	*UpdateRequest_UpdateMask
	//	*UpdateRequest_ResetField
	Input isUpdateRequest_Input `protobuf_oneof:"input"`
}

UpdateRequest is used to to modify a running Game of Life simulation.

func (*UpdateRequest) GetInput

func (m *UpdateRequest) GetInput() isUpdateRequest_Input

func (*UpdateRequest) GetResetField

func (m *UpdateRequest) GetResetField() *ResetFieldRequest

func (*UpdateRequest) GetUpdateMask

func (m *UpdateRequest) GetUpdateMask() *UpdateMaskRequest

func (*UpdateRequest) ProtoMessage

func (*UpdateRequest) ProtoMessage()

func (*UpdateRequest) Reset

func (m *UpdateRequest) Reset()

func (*UpdateRequest) String

func (m *UpdateRequest) String() string

func (*UpdateRequest) XXX_OneofFuncs

func (*UpdateRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type UpdateRequest_ResetField

type UpdateRequest_ResetField struct {
	ResetField *ResetFieldRequest `protobuf:"bytes,2,opt,name=reset_field,oneof"`
}

type UpdateRequest_UpdateMask

type UpdateRequest_UpdateMask struct {
	UpdateMask *UpdateMaskRequest `protobuf:"bytes,1,opt,name=update_mask,oneof"`
}

type UpdateResponse

type UpdateResponse struct {
}

UpdateResponse is the response to an UpdateRequest.

It is blank for now, but exists in case we need to add response information in the future.

func (*UpdateResponse) ProtoMessage

func (*UpdateResponse) ProtoMessage()

func (*UpdateResponse) Reset

func (m *UpdateResponse) Reset()

func (*UpdateResponse) String

func (m *UpdateResponse) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL