Conway's Game of Life/Scala: Difference between revisions
m
Fixed syntax highlighting.
(moved from Conway's Game of Li) |
m (Fixed syntax highlighting.) |
||
Line 22:
created, an exception will be thrown to indicate the board can no longer be correctly represented.
<
private val offsets = List(-1, 0, 1)
private def offsetsOf(n: Int) = offsets map (_ + n)
Line 82:
*/
implicit def coordFromTuple(t: (Int, Int)) = apply(t._1, t._2)
}</
'''Generation'''
Line 94:
with the pattern recentered.
<
import Generation._
Line 201:
case _ => None
}
}</
'''Conway's Game of Life Patterns'''
Line 215:
A few helper methods are provided to get these patterns into use.
<
// Lists for all patterns available
def stillLives = List(block, beehive, loaf, boat) map ((_, 1))
Line 328:
def moveTo(coords: Traversable[Coord], to: Coord) = coords map (_ + to)
}</
'''Tester'''
Line 340:
It also prints three generations of a blinker, as requested.
<
import ConwayPatterns._
val MaxGenerations = 5500 // Give up at MaxGenerations to avoid spending too much time on errors
Line 429:
}
}
}</
Output:
|