added reset

This commit is contained in:
2024-05-24 17:53:38 +02:00
parent 743a18c696
commit 757b48232f
5 changed files with 68 additions and 0 deletions

21
grid.go
View File

@@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"math/rand"
"os"
"strconv"
"strings"
@@ -40,6 +41,26 @@ func (grid *Grid) Clone() *Grid {
return newgrid
}
func (grid *Grid) Clear() {
for y := range grid.Data {
for x := range grid.Data[y] {
grid.Data[y][x] = 0
}
}
}
func (grid *Grid) FillRandom(game *Game) {
if !game.Empty {
for y := range grid.Data {
for x := range grid.Data[y] {
if rand.Intn(game.Density) == 1 {
grid.Data[y][x] = 1
}
}
}
}
}
func GetFilename(generations int64) string {
now := time.Now()
return fmt.Sprintf("dump-%s-%d.gol", now.Format("20060102150405"), generations)