Skip to content

Commit

Permalink
move main.go to a cmd folder corresponding Go best practice
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonWaldherr committed Nov 4, 2018
1 parent 00b5c91 commit 7ace8d0
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/-trash
/.idea
cmd/cgol/cgol
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
install:
- go get -u -t simonwaldherr.de/go/cgolGo
- go get -u -t simonwaldherr.de/go/cgolGo/...
- go get github.com/modocache/gover
script:
- $HOME/gopath/bin/cgolGo -d 100
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Simon Waldherr
Copyright (c) 2018 Simon Waldherr

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
[![BCH compliance](https://bettercodehub.com/edge/badge/SimonWaldherr/cgolGo?branch=codacy-badge)](https://bettercodehub.com/)
[![Travis CI](https://img.shields.io/travis/SimonWaldherr/cgolGo.svg?style=flat)](https://travis-ci.org/SimonWaldherr/cgolGo)
[![Go Report Card](https://goreportcard.com/badge/github.com/simonwaldherr/cgolGo)](https://goreportcard.com/report/github.com/simonwaldherr/cgolGo)
[![codebeat badge](https://codebeat.co/badges/a20ab70f-2baa-490b-8fcf-69ac1961e969)](https://codebeat.co/projects/github-com-simonwaldherr-cgolgo-master)
[![Codebeat badge](https://codebeat.co/badges/a20ab70f-2baa-490b-8fcf-69ac1961e969)](https://codebeat.co/projects/github-com-simonwaldherr-cgolgo-master)
[![Coverage Status](https://coveralls.io/repos/github/SimonWaldherr/cgolGo/badge.svg?branch=master)](https://coveralls.io/github/SimonWaldherr/cgolGo?branch=master)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/SimonWaldherr/cgolGo/life)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/SimonWaldherr/cgolGo/master/LICENSE)

## conway's game of life in golang
## Conway's game of life in Golang

[Conway's Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life)
in [golang](http://en.wikipedia.org/wiki/Go_(programming_language))
in [Golang](http://en.wikipedia.org/wiki/Go_(programming_language))

Conway's Game of Life is a [zero-player game](https://en.wikipedia.org/wiki/Zero-player_game) - a [cellular automaton](https://en.wikipedia.org/wiki/Cellular_automaton) simulation invented by [John Horton Conway](https://en.wikipedia.org/wiki/John_Horton_Conway).
There are many implementations in every important programming language [here on GitHub](https://github.com/search?q=topic%3Aconway-game&type=Repositories).
The map of a Game of Life consists of an two-dimensional grid of square cells.
The map of a Game of Life consists of a two-dimensional grid of square cells.
Each cell can have one of to two possible states - dead or alive.
The future of a cell is determined by its own current status and that of the eight direct neighbors - vertically, horizontally and diagonally.
* a living cell with two or three living neighbours stays alive
* a dead cell with three living neighbours becomes a live cell
* a living cell with two or three living neighbors stays alive
* a dead cell with three living neighbors becomes a live cell
* every other cell will be a dead cell in the next round

## examples
## Examples

01.gif

Expand All @@ -41,6 +41,6 @@ The future of a cell is determined by its own current status and that of the eig

[![15.gif](http://simonwaldherr.github.io/cgolGo/output/15.gif)](https://github.com/SimonWaldherr/cgolGo/blob/master/structures/15.txt)

## license
## License

[MIT](https://github.com/SimonWaldherr/cgolGo/blob/master/LICENSE)
12 changes: 6 additions & 6 deletions cgol.go → cmd/cgol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package main
import (
"flag"
"fmt"
"time"

"simonwaldherr.de/go/golibs/gcurses"
"simonwaldherr.de/go/cgolGo/gif"
"simonwaldherr.de/go/cgolGo/life"
"simonwaldherr.de/go/golibs/gcurses"
"time"
)

var field *life.Field

var (
setfps int
setwidth int
Expand All @@ -22,9 +21,10 @@ var (
port string
)

func main() {
var gv = &gif.GifVisualizer{}
var field *life.Field
var gv = &gif.GifVisualizer{}

func main() {
writer := gcurses.New()
writer.Start()

Expand Down
6 changes: 3 additions & 3 deletions start.sh → cmd/cgol/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fi

if [[ "$INPUT" == "R" ]] || [[ "$INPUT" == "r" ]]
then
go run cgol.go -w $(tput cols) -h $(($(tput lines)-5)) -d -1 -f $FPS
go run main.go -w $(tput cols) -h $(($(tput lines)-5)) -d -1 -f $FPS
elif [[ "$INPUT" == "F" ]] || [[ "$INPUT" == "f" ]]
then
echo "ENTER THE NAME OF A FILE"
ls "structures"
ls "../../structures"
read -n 2 -s INPUT
go run cgol.go -w $(tput cols) -h $(($(tput lines)-5)) -d -1 -f $FPS -o "structures/$INPUT.txt"
go run main.go -w $(tput cols) -h $(($(tput lines)-5)) -d -1 -f $FPS -o "../../structures/$INPUT.txt"
fi
6 changes: 3 additions & 3 deletions startGIF.sh → cmd/cgol/startGIF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ fi

if [ "$INPUT" == "R" ] || [ "$INPUT" == "r" ]
then
go run cgol.go -w $((WIDTH/4)) -h $((HEIGHT/4)) -d $FRAMES -g cgol
go run main.go -w $((WIDTH/4)) -h $((HEIGHT/4)) -d $FRAMES -g cgol
elif [ "$INPUT" == "F" ] || [ "$INPUT" == "f" ]
then
echo "ENTER THE NAME OF A FILE"
ls "structures"
ls "../../structures"
read -n 2 -s INPUT
go run cgol.go -w $((WIDTH/4)) -h $((HEIGHT/4)) -d $FRAMES -g cgol -o "structures/$INPUT.txt"
go run main.go -w $((WIDTH/4)) -h $((HEIGHT/4)) -d $FRAMES -g cgol -o "../../structures/$INPUT.txt"
fi

gifsicle --resize-width $WIDTH -O --careful -d $((100/FPS)) -o cgol.gif cgol.gif
2 changes: 1 addition & 1 deletion structsGIF.sh → cmd/cgol/structsGIF.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

for i in $(seq -w 1 20) ; do
go run cgol.go -w 50 -h 50 -d 250 -o structures/$i.txt -g $i -l 200;
go run main.go -w 50 -h 50 -d 250 -o "../../structures/$i.txt" -g $i -l 200;
gifsicle --resize-width 250 -O --careful -d 5 -o $i.gif $i.gif;
done
17 changes: 0 additions & 17 deletions gif.coverprofile

This file was deleted.

43 changes: 0 additions & 43 deletions life.coverprofile

This file was deleted.

2 changes: 2 additions & 0 deletions life/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func GenerateFirstRound(width, height int) *Field {
return field
}

// LoadFirstRound wraps LoadFirstRoundFromTXT or
// LoadFirstRoundFromRLE depending on the file extension
func LoadFirstRound(width, height int, filename string) *Field {
switch filepath.Ext(filename) {
case ".txt":
Expand Down

0 comments on commit 7ace8d0

Please sign in to comment.