|
|
|
@ -3,6 +3,7 @@ package conway
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GameOfLife struct {
|
|
|
|
@ -171,6 +172,32 @@ func (game *GameOfLife) ImportState(state *GameState) error {
|
|
|
|
|
return game.State.Import(state)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (game *GameOfLife) String() string {
|
|
|
|
|
var rows []string
|
|
|
|
|
|
|
|
|
|
height := game.State.Height()
|
|
|
|
|
width := game.State.Width()
|
|
|
|
|
|
|
|
|
|
for y := 0; y < height; y++ {
|
|
|
|
|
var cells []string
|
|
|
|
|
for x := 0; x < width; x++ {
|
|
|
|
|
stringVal := "X"
|
|
|
|
|
|
|
|
|
|
value, err := game.State.Get(x, y)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if value == 0 {
|
|
|
|
|
stringVal = "_"
|
|
|
|
|
}
|
|
|
|
|
cells = append(cells, stringVal)
|
|
|
|
|
}
|
|
|
|
|
rows = append(rows, strings.Join(cells, ""))
|
|
|
|
|
}
|
|
|
|
|
return strings.Join(rows, "\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewGenerationScoreCard(height, width int) *GenerationScoreCard {
|
|
|
|
|
genScore := &GenerationScoreCard{}
|
|
|
|
|
for i := 0; i < height; i++ {
|
|
|
|
|