5

To try out Netwire, I'm implementing Pong using the library. In the code I have a ball wire and a computer paddle wire, and since they depend on each other for some values I've been running into issues with infinite loops. Some pseudo-code to explain:

ball :: Wire () IO GameInput Ball
ball = (... define ball ...) . pcPaddle

pcPaddle :: Wire () IO GameInput Paddle
pcPaddle = (... define pcPaddle ...) . ball

The thing to notice is they take each other for inputs. I've tried to alleviate this by doing the following:

ball :: Wire () IO GameInput Ball
ball = ( ... ) . delay ( ... base paddle init ...) . pcPaddle

and other variations of using the delay function in these two wires, but I'm getting the <<loop>> runtime error regardless.

How do I initialize one of the wires so that this system can work?

4

1 回答 1

6

当然,5 分钟后,我找到了似乎有效的神奇组合。我所做的是我改变了电线的输入

ball :: Wire () IO Paddle Ball
ball = ...

paddle :: Wire () IO Ball Paddle
paddle = ...

然后在创建我的电线网络时,我这样做了:

{-# LANGUAGE DoRec  #-}
{-# LANGUAGE Arrows #-}
system = proc g -> do
    rec b <- delay (... ball initial value ...) . ball -< p
        p <- paddle -< b

    returnA -< (b,p)

这承认了它们的依赖关系,并在第一次传球时为球拍提供了虚拟初始值。

于 2013-08-30T02:56:34.743 回答