Skip to content

Commit

Permalink
Merge pull request #1 from qjuanp/upgrade-go-version
Browse files Browse the repository at this point in the history
Upgrade go version
  • Loading branch information
qjuanp authored Feb 23, 2024
2 parents 276f873 + 0ec9583 commit 42b7d73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 1 addition & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module gameoflife

go 1.18

require (
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 // indirect
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
)
go 1.18
18 changes: 12 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ package main
import (
"fmt"
"math/rand"
"os"
"os/exec"
"strings"
"time"

"github.com/inancgumus/screen"
)

func main() {
fmt.Println("Project setup done")
currentBoard := ramdomInitialization(100, 100, 1)

screen.Clear()
clear()
for {
screen.MoveTopLeft()
fmt.Print(boardToString(currentBoard, toCharacter))
time.Sleep(time.Second)
currentBoard = nextBoardState(currentBoard)
}
}

func clear() {
c := exec.Command("clear")
c.Stdout = os.Stdout
c.Run()
}

type serializer func(uint8) string

const ALIVE uint8 = 1
Expand All @@ -42,12 +47,13 @@ func createBoard(rows int, columns int) [][]uint8 {

func ramdomInitialization(rows uint32, columns uint32, seed int64) [][]uint8 {
var board [][]uint8 = make([][]uint8, rows)
rand.Seed(seed)

random := rand.New(rand.NewSource(seed))

for row := range board {
board[row] = make([]uint8, columns)
for column := range board[row] {
randomValue := rand.Float64()
randomValue := random.Float64()
if randomValue >= 0.5 {
board[row][column] = ALIVE
} else {
Expand Down

0 comments on commit 42b7d73

Please sign in to comment.