feat: create empty border around the field.
This commit is contained in:
parent
038d214f75
commit
9f7e566d28
10
main.go
10
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user