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 diff --git a/main.go b/main.go index ff7063e..15c17f0 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 @@ -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 {