Have we achieved torus?

cat-town
Dan Buch 12 years ago
parent 8056d86cbf
commit 3bfa23fff2

@ -60,7 +60,7 @@ func TestLiveCellWithTwoOrThreeLiveNeighborsLivesOn(t *testing.T) {
game.EvaluateGeneration()
cell := game.State.Get(0, 0)
cell := game.State.Get(0, 2)
if cell.Value != 1 {
t.Errorf("%v != 1", cell.Value)
return
@ -262,8 +262,8 @@ func TestGenerationScoreCardCalculateResultsInCorrectNeighborCounts(t *testing.T
genScore.Calculate(state)
cell := genScore.Get(0, 0)
if cell.Value != 3 {
t.Errorf("[0, 0] value %v != 3", cell.Value)
if cell.Value != 4 {
t.Errorf("[0, 0] value %v != 4", cell.Value)
return
}

@ -59,6 +59,10 @@ func (state *GameState) Width() int {
func (state *GameState) GetRow(y int) *GameStateRow {
lenRows := len(state.Rows)
if y < 0 {
return state.GetRow(lenRows + y)
}
if y+1 > lenRows {
return state.GetRow(y % lenRows)
}
@ -75,6 +79,10 @@ func (state *GameState) Get(x, y int) *GameStateCell {
row := state.GetRow(y)
lenCells := len(row.Cells)
if x < 0 {
return state.Get(lenCells+x, row.Y)
}
if x+1 > lenCells {
return state.Get(x%lenCells, row.Y)
}

@ -39,7 +39,6 @@ func NewGenerationScoreCard(height, width int) *GenerationScoreCard {
}
func (genScore *GenerationScoreCard) Calculate(state *GameState) error {
stateWidth := state.Width()
stateCells, err := state.Cells()
if err != nil {
return err
@ -54,14 +53,6 @@ func (genScore *GenerationScoreCard) Calculate(state *GameState) error {
xTarget := stateCell.X + neighbor.X
yTarget := stateCell.Y + neighbor.Y
if xTarget < 0 || yTarget < 0 {
continue
}
if xTarget+1 > stateWidth || yTarget+1 > stateWidth {
continue
}
cell := genScore.Get(xTarget, yTarget)
genScore.Set(xTarget, yTarget, cell.Value+1)
}

Loading…
Cancel
Save