Skip to content

Commit

Permalink
Make matrix a slice
Browse files Browse the repository at this point in the history
With this we make the program more flexible and ready to parametrize
via CLI args the Board dimensions.
  • Loading branch information
eloylp committed Nov 19, 2019
1 parent 16a89de commit 54c1f8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
12 changes: 6 additions & 6 deletions board.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package main

type Cell bool
type Board [4][4]Cell
type Board [][]Cell

func (b Board) NextGen() Board {
newBoard := Board{}
newBoard := make(Board, len(b))
for y := 0; y < len(b); y++ {
for x := 0; x < len(b[x]); x++ {
newBoard[y][x] = b.NextGenCell(x, y)
for x := 0; x < len(b[y]); x++ {
newBoard[y] = append(newBoard[y], b.NextGenCell(x, y))
}
}
return newBoard
}

func (b Board) TextBoard() [][]string {
newBoard := make([][]string, 4)
newBoard := make([][]string, len(b))
for y := 0; y < len(b); y++ {
for x := 0; x < len(b[x]); x++ {
for x := 0; x < len(b[y]); x++ {
c := b[y][x]
if c {
newBoard[y] = append(newBoard[y], "x")
Expand Down
7 changes: 6 additions & 1 deletion board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ func TestBoard_NextGen(t *testing.T) {
}

func TestIsReachableNeighbour(t *testing.T) {
b := Board{}
b := Board{
{false, false, false, false},
{false, false, false, false},
{false, false, false, false},
{false, false, false, false},
}
type sample struct {
X, Y, OX, OY int
Case string
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

func main() {
b := Board{
{false, false, false, false},
{false, true, false, false},
{false, true, true, false},
{false, true, false, false},
{false, false, false, false, true},
{false, true, false, false, true},
{false, true, true, false, false},
{false, true, false, false, true},
}
g := NewGame(b, 5, 1)
g := NewGame(b, 10, 1)
g.Run()
}

0 comments on commit 54c1f8a

Please sign in to comment.