util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: Apache-2.0 Imports: 5 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 ClearAndSpawnCells

func ClearAndSpawnCells(writer *uilive.Writer, gameConfig GameConfig, frameCells FrameCells)

ClearAndSpawnCells updates the cell string that is printed to the command line.

func IsCoordOutOfFrame

func IsCoordOutOfFrame(gameConfig GameConfig, x, y int) bool

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

func RunGame

func RunGame(gameConfig GameConfig, initPattern Pattern)

RunGame runs the game based on the passed args.

Types

type Cell

type Cell struct {
	X               int
	Y               int
	IsAlive         bool
	LivingNeighbors CellNeighbors
}

func GetCellByCoord

func GetCellByCoord(gameConfig GameConfig, frameCells FrameCells, x, y int) Cell

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

type CellNeighbors

type CellNeighbors []Cell

func GetLivingNeighborsByCoord

func GetLivingNeighborsByCoord(gameConfig GameConfig, frameCells FrameCells, x, y int) CellNeighbors

GetLivingNeighborsByCoord returns a slice of cells that neighbor the cell at (x,y).

type FrameCells

type FrameCells []Cell

func GetFrameCellsByPattern

func GetFrameCellsByPattern(gameConfig GameConfig, pattern Pattern) FrameCells

GetFrameCellsByPattern converts a pattern string to frame cells.

func UpdateCells

func UpdateCells(gameConfig GameConfig, frameCells FrameCells) FrameCells

UpdateCells returns new frame cells after evaluating the living state of frameCells.

type GameConfig added in v1.0.0

type GameConfig struct {
	Width          int
	Height         int
	FrameCount     int
	Interval       time.Duration
	DeadCellChar   string
	LivingCellChar string
}

type Pattern

type Pattern struct {
	Path string
	X    int
	Y    int
}

Jump to

Keyboard shortcuts

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