【发布时间】:2014-08-26 08:18:40
【问题描述】:
我目前正在尝试在 Haskell 中开发一个小型的康威生命游戏。我编写了一个库,lifegame,它可以管理单元格并计算其世代 (见github.com/qleguennec/lifegame.git)。 Generations 是一个无限列表。 到目前为止,该库运行良好,但缺少文档。这是一个小型图书馆,进入它应该不难。
现在,我来这里的目的是,我正在尝试使用 lifegame 和 helm 来在屏幕上实际显示世代。这是我写的:
import FRP.Helm
import FRP.Helm.Graphics (Element(..))
import qualified FRP.Helm.Window as Window
import FRP.Helm.Animation (Frame, AnimationStatus(..), animate, absolute)
import FRP.Helm.Time (second, running, delta)
import FRP.Elerea.Simple
import Cell.Display (allGenFrames)
import LifeGame.Data.CellGrid (CellGrid(..), randCellGrid)
render :: Form -> (Int, Int) -> Element
render form (x, y) = collage x y $ [form]
main :: IO ()
main = do
cg <- randCellGrid 50 50
anim <- return . absolute $ allGenFrames cg (1 * second) 10
engine <- startup defaultConfig
run engine $ render <~ (animate anim running status) ~~ Window.dimensions engine
where
config = defaultConfig { windowTitle = "bats"
, windowDimensions = (500, 500)}
status = effectful $ getLine >>= \i -> return $
case i of
"Pause" -> Pause
"Stop" -> Stop
"Cycle" -> Cycle
(来自:github.com/qleguennec/bats.git)
计算的艰苦工作在animate running status",第20行。我不太明白animate的第二个参数是什么。此外,我不确定提供无限的Frames列表是否合法。
当我启动代码时,游戏冻结并在 5 分钟后停止。它似乎消耗了所有内存并崩溃。现在,我知道所有这些都缺乏文档。我在做这个工作。但是,作为婴儿 Haskeller 和婴儿 FRP/SDL 开发人员,我需要知道我是否以错误的方式执行此操作(我可能会这样做)。 接受并推荐任何评论。谢谢。
【问题讨论】:
标签: haskell sdl frp conways-game-of-life elerea