From 9f7e566d2888f3c321ff5f314d233244d1b386e0 Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Mon, 3 Mar 2025 10:59:17 +0100 Subject: [PATCH] feat: create empty border around the field. --- main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index abe676b..9fadcc6 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,9 @@ type gol struct { // Initialize empty game of life func initGol() gol { start := [ROW][COL]int{} - for i := 0; i < ROW; i++ { - for j := 0; j < COL; j++ { + // Intentionally skipping field around the array making it empty + for i := 1; i < ROW-1; i++ { + for j := 1; j < COL-1; j++ { if rand.Intn(2) == 1 { start[i][j] = 1 } else { @@ -59,8 +60,9 @@ func (g gol) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Let's draw this all simply func (g gol) View() string { var s string - for i := 0; i < ROW; i++ { - for j := 0; j < COL; j++ { + // Making sure to not draw the empty field around the array + for i := 1; i < ROW-1; i++ { + for j := 1; j < COL-1; j++ { if g.grid[i][j] == 1 { s += "*" } else {