From 4f95173cdf53e3af7e9515ccfb99af6f9febce28 Mon Sep 17 00:00:00 2001 From: Juan P Date: Tue, 29 Mar 2022 20:58:10 +0100 Subject: [PATCH 1/3] Updated go.mod to go 1.18 --- go.mod | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 244598d..b15c110 100644 --- a/go.mod +++ b/go.mod @@ -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 \ No newline at end of file From c184291b1c7042757941049436bfc6e19709b4ee Mon Sep 17 00:00:00 2001 From: Juan P Date: Fri, 23 Feb 2024 18:16:43 +0000 Subject: [PATCH 2/3] Clear input before start --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index ff7063e..16e9f00 100644 --- a/main.go +++ b/main.go @@ -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 From 0ec95831f4c2377d0801fc8784ef140f81a17df2 Mon Sep 17 00:00:00 2001 From: Juan P Date: Fri, 23 Feb 2024 18:20:46 +0000 Subject: [PATCH 3/3] Upgraded Randomg source --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 16e9f00..15c17f0 100644 --- a/main.go +++ b/main.go @@ -47,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 {