From e825560703abe07d3384cd594c5ca530c70ee379 Mon Sep 17 00:00:00 2001 From: Messi Yang Date: Fri, 3 Jun 2022 15:14:38 +0800 Subject: [PATCH] 1. Update README.md. --- README.md | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0c78415..b2ebea3 100644 --- a/README.md +++ b/README.md @@ -95,19 +95,27 @@ func cgolNextUnitGenerator( } } +// You have to generate your initial cells. +func generateInitialCgolCells(width int, height int, cell CgolCell) *[][]CgolCell { + cells := make([][]CgolCell, width) + for x := 0; x < width; x += 1 { + cells[x] = make([]CgolCell, height) + for y := 0; y < height; y += 1 { + cells[x][y] = cell + } + } + + return &cells +} + func main() { - // Declare size of the map in the game. - size := ggol.Size{Height: 3, Width: 3} // Initial status of all units. initialCgolCell := CgolCell{Alive: false} + initialCgolCells := generateInitialCgolCells(3, 3, initialCgolCell) - // Alrighty, let's create a new game with size of 3x3, - // you also need to tell the game what's the initial status - // of each unit, let's say all units are not alive. - game, _ := ggol.NewGame( - &size, - &initialCgolCell, - ) + // Alrighty, let's create a new game with the given cells + game, _ := ggol.NewGame(initialCgolCells) + size := game.GetSize() // Set generator of next unit. game.SetNextUnitGenerator(cgolNextUnitGenerator)