life

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 12 Imported by: 1

README

Life - Convert between Game of Life pattern formats

GoDoc Go Report Card Codacy Badge HitCount PR's Welcome

Convert between RLE, Life 1.06 and Plaintext file formats containing Conway's Game of life patterns. This program may be used as a library or through the command line.

Note: This project was made as part of the Project52 challenge in order to improve my Go skills.

Features

  • Convert between any combination of RLE, Life 1.06, and Plaintext file formats.

Installation

If you want to use it as a library:

$ go get github.com/ayoisaiah/life

or if you want to use it via the command line:

$ go get github.com/ayoisaiah/life/cmd/...

The life command should now be available provided the $GOPATH/bin folder is in your path.

You can also download the precompiled binaries for Linux, Windows, and macOS here (only for amd64).

Usage

Library usage

Here's an example that converts one of the RLE patterns hosted here to its Plaintext equivalent.

package main

import (
	"fmt"
	"log"

	"github.com/ayoisaiah/life"
)

func main() {
	url := "https://copy.sh/life/examples/123.rle"
	p, err := life.PresetFromURL(url, "rle")
	if err != nil {
		log.Fatal(err)
	}

	b, err := p.ToPlainText()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(b))
}
# output
!Name: 1-2-3
!A period 3 oscillator that was found in August 1972.
!
..OO......
O..O......
OO.O.OO...
.O.O..O...
.O....O.OO
..OOO.O.OO
.....O....
....O.....
....OO....

Full documentation can be found here.

Command line usage
  • Load Plaintext pattern from a file and convert to RLE
$ life --file 101.cells --output rle
#C 101
#C Achim Flammenkamp
#C A period 5 oscillator that was found in August 1994.
#C The name was suggested by Bill Gosper, noting that the phase shown
#C below displays the period in binary.
x = 18, y = 12
4b2o6b2o$3bobo6bobo$3bo10bo$2obo10bob2o$2obobo2b2o2bobob2o$3bobobo2bob
obo$3bobobo2bobobo$2obobo2b2o2bobob2o$2obo10bob2o$3bo10bo$3bobo6bobo$4
b2o6b2o!
  • Load RLE pattern from URL and convert to Life 1.06
$ life --url "https://copy.sh/life/examples/gosperglidergun.rle" --input rle --output life106
#Life 1.06
24 0
22 1
24 1
12 2
13 2
20 2
21 2
34 2
35 2
11 3
15 3
20 3
21 3
34 3
35 3
0 4
1 4
10 4
16 4
20 4
21 4
0 5
1 5
10 5
14 5
16 5
17 5
22 5
24 5
10 6
16 6
24 6
11 7
15 7
12 8
13 8

TODO

  • Write more tests

Credit and sources

Life relies heavily on other open source software listed below:

Contribute

Bug reports, or pull requests are much welcome!

Licence

Created by Ayooluwa Isaiah and released under the terms of the MIT Licence.

Documentation

Overview

Package life implements the conversion between a subset of Game of life formats which can be found here: https://www.conwaylife.com/wiki/Category:File_formats The specific formats supported by this package include the following: - RLE - Life 1.06 - Plaintext

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellState

type CellState int

CellState represents the state of a cell

const (
	// Dead is a dead cell
	Dead CellState = iota
	// Alive is a live cell
	Alive
)

type Pattern

type Pattern struct {
	Cells       [][]CellState
	Name        string
	Description []string
	Author      string
}

Pattern represents a parsed life pattern

func ParseToPattern

func ParseToPattern(r io.Reader, format string) (*Pattern, error)

ParseToPattern returns a parsed life pattern It reads the pattern from r and parses it according to the specified format. Valid formats are: rle, life106, and plaintext

func PresetFromFile

func PresetFromFile(filePath string) (*Pattern, error)

PresetFromFile loads a preset pattern from a file

func PresetFromURL

func PresetFromURL(presetURL, inputFormat string) (*Pattern, error)

PresetFromURL loads a preset pattern from a URL. Valid formats are: rle, life106, and plaintext

func (*Pattern) ToLife106

func (p *Pattern) ToLife106() ([]byte, error)

ToLife106 processes a parsed life pattern to the Life 1.06 format

func (*Pattern) ToPlainText

func (p *Pattern) ToPlainText() ([]byte, error)

ToPlainText processes a parsed life pattern to the plaintext format

func (*Pattern) ToRLE

func (p *Pattern) ToRLE() ([]byte, error)

ToRLE processes a parsed life pattern to the RLE format

Directories

Path Synopsis
cmd
life command

Jump to

Keyboard shortcuts

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