diff --git a/README.md b/README.md index 615afd1..e01b930 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Based on: https://youtu.be/FWSR_7kZuYg?si=ix1dmo76D8AmF25F * game patterns can be loaded using RLE files, see https://catagolue.hatsya.com/home * you can paint your own patterns in the game * the game can also be started with an empty grid, which is easier to paint patterns +* wrap around grid mode can be enabled # Install diff --git a/game.go b/game.go index b5fe2ea..7c89bbf 100644 --- a/game.go +++ b/game.go @@ -45,7 +45,8 @@ type Game struct { Markmode bool // enabled with 'c' MarkTaken bool // true when mouse1 pressed MarkDone bool // true when mouse1 released, copy cells between Mark+Point - Mark, Point image.Point + Mark, Point image.Point // area to marks+save + Wrap bool // wether wraparound mode is in place or not } func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) { @@ -551,13 +552,28 @@ func (game *Game) Init() { func (game *Game) CountNeighbors(x, y int) int64 { var sum int64 - // so we look ad all 8 neighbors surrounding us. In case we are on - // an edge, then we'll look at the neighbor on the other side of - // the grid, thus wrapping lookahead around. - for i := -1; i < 2; i++ { - for j := -1; j < 2; j++ { - col := (x + i + game.Width) % game.Width - row := (y + j + game.Height) % game.Height + for nbgX := -1; nbgX < 2; nbgX++ { + for nbgY := -1; nbgY < 2; nbgY++ { + fmt.Printf("nbgX: %d, nbgY: %d\n", nbgX, nbgY) + + var col, row int + if game.Wrap { + // In wrap mode we look at all the 8 neighbors surrounding us. + // In case we are on an edge we'll look at the neighbor on the + // other side of the grid, thus wrapping lookahead around + // using the mod() function. + col = (x + nbgX + game.Width) % game.Width + row = (y + nbgY + game.Height) % game.Height + + } else { + // In traditional grid mode the edges are deadly + if x+nbgX < 0 || x+nbgX >= game.Width || y+nbgY < 0 || y+nbgY >= game.Height { + continue + } + col = x + nbgX + row = y + nbgY + } + sum += game.Grids[game.Index].Data[row][col] } } diff --git a/main.go b/main.go index 22405f9..6374272 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) const ( - VERSION = "v0.0.5" + VERSION = "v0.0.6" Alive = 1 Dead = 0 ) @@ -60,6 +60,7 @@ func main() { pflag.BoolVarP(&game.Empty, "empty", "e", false, "start with an empty screen") pflag.BoolVarP(&game.Invert, "invert", "i", false, "invert colors (dead cell: black)") pflag.BoolVarP(&game.ShowEvolution, "show-evolution", "s", false, "show evolution tracks") + pflag.BoolVarP(&game.Wrap, "wrap-around", "w", false, "wrap around grid mode") pflag.Parse()