feat: create empty border around the field.

This commit is contained in:
CronyAkatsuki 2025-03-03 10:59:17 +01:00
parent 038d214f75
commit 9f7e566d28

10
main.go
View File

@ -23,8 +23,9 @@ type gol struct {
// Initialize empty game of life // Initialize empty game of life
func initGol() gol { func initGol() gol {
start := [ROW][COL]int{} start := [ROW][COL]int{}
for i := 0; i < ROW; i++ { // Intentionally skipping field around the array making it empty
for j := 0; j < COL; j++ { for i := 1; i < ROW-1; i++ {
for j := 1; j < COL-1; j++ {
if rand.Intn(2) == 1 { if rand.Intn(2) == 1 {
start[i][j] = 1 start[i][j] = 1
} else { } else {
@ -59,8 +60,9 @@ func (g gol) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Let's draw this all simply // Let's draw this all simply
func (g gol) View() string { func (g gol) View() string {
var s string var s string
for i := 0; i < ROW; i++ { // Making sure to not draw the empty field around the array
for j := 0; j < COL; j++ { for i := 1; i < ROW-1; i++ {
for j := 1; j < COL-1; j++ {
if g.grid[i][j] == 1 { if g.grid[i][j] == 1 {
s += "*" s += "*"
} else { } else {