util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright © 2021 Brian Longmore brianl.ext@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BruteRunGame added in v1.3.0

func BruteRunGame(gc GameConfig)

BruteRunGame runs the game with in-time building.

func ClearAndDrawFrames added in v1.3.0

func ClearAndDrawFrames(gc GameConfig, frameCells Cells)

ClearAndDrawFrames updates the frame that is printed to the command line.

func GenBuildFile added in v1.3.0

func GenBuildFile(bc BuildConfig) error

GenBuildFile creates a build file from bc.If the destination file already exists, it will be overwritten.

func GetConfigListStrings added in v1.2.2

func GetConfigListStrings(config GameConfig) (string, string)

GetConfigListStrings returns both game and pattern config strings from config.

func GetLiveNeighborNumByCoord added in v1.3.0

func GetLiveNeighborNumByCoord(bc BuildConfig, frameCells Cells, x, y int) int

GetLiveNeighborNumByCoord returns the number of cells neighboring the cell at (x,y).

func IsCoordOutOfFrame

func IsCoordOutOfFrame(bc BuildConfig, x, y int) bool

IsCoordOutOfFrame returns whether or not the cell at (x,y) is out of the frame.

func RunBuildFile added in v1.3.0

func RunBuildFile(rc RunConfig) error

RunBuildFile runs a build file according to the parameters passed in rc.

func RunFrames added in v1.3.0

func RunFrames(gd GameData, rc RunConfig)

RunFrames runs the frames based on the passed game data and run config.

func UpdateCells

func UpdateCells(bc BuildConfig, frameCells *Cells)

UpdateCells updates the value of the pointer frameCells after evaluating the living states of its cells.

Types

type BuildConfig added in v1.3.0

type BuildConfig struct {
	BuildFilePath string
	Width         int
	Height        int
	FrameCount    int
	InitPattern   Pattern
}

type Cell

type Cell struct {
	X               int
	Y               int
	IsAlive         bool
	LiveNeighborNum int
}

func GetCellByCoord

func GetCellByCoord(bc BuildConfig, frameCells Cells, x, y int) Cell

GetCellByCoord returns the cell that is at (x,y).

func GetNewCell added in v1.1.0

func GetNewCell(bc BuildConfig, frameCells Cells, cell Cell) Cell

GetNewCell returns a new cell from the passed cell according to the life conditions.

type Cells added in v1.3.0

type Cells []Cell

func GenCellsFromPattern added in v1.3.0

func GenCellsFromPattern(bc BuildConfig) Cells

GenCellsFromPattern converts a pattern string to frame cells.

type Frame added in v1.3.0

type Frame struct {
	FrameNum int
	Cells
}

type Frames added in v1.3.0

type Frames []Frame

func GenFramesFromPattern added in v1.3.0

func GenFramesFromPattern(bc BuildConfig) Frames

GenFramesFromPattern generates and returns Frames according to the values passed in bc.

type GameConfig added in v1.0.0

type GameConfig struct {
	Width        int
	Height       int
	FrameCount   int
	InitPattern  Pattern
	Interval     time.Duration
	LiveCellChar string
	DeadCellChar string
}

type GameData added in v1.3.0

type GameData struct {
	BuildConfig
	Frames
}

func GenGameDataFromBuildFile added in v1.3.0

func GenGameDataFromBuildFile(rc RunConfig) (GameData, error)

GenGameDataFromBuildFile returns GameData that was stored in the targeted json build file.

type Pattern

type Pattern struct {
	FilePath string
	X        int
	Y        int
}

type RunConfig added in v1.3.0

type RunConfig struct {
	BuildFilePath string
	Interval      time.Duration
	LiveCellChar  string
	DeadCellChar  string
}

Jump to

Keyboard shortcuts

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