title: Discrete state and animated transitions
body: <p>I wonder how may I connect together drawing the game with changing state in functional manner. I mean the game logic is the function that takes current state and return new state depending on the chosen action. That is all great but it implies by definition that state transitions in a discrete way. For example in tetris there is no state whereas brick is half tail way down. So if one wants to animate the transition there is a problem how to determine what actually happened. Let's consider state as 2d array that contains position of n enemies. If there are initially two enemies on position (10,10) and (15,20) there is no single solution how they may transition to (12,13) and (16,11). We just do not know which is which. Given two states I have no way to determine whether one from (10,10) moved to (15,20) or to (16,11).</p>
  <p>First solution that came to my mind is to give an id to each enemy. But as far as I am interested only in their positions this complicates my internal state just to allow animate transitions.</p>
  <p>Second approach would be to return not only new state but additionally a list of events that actually happened. Then having such events it is easy to animate the transition. The event here would be something like <code>EnemyMoved(oldPosition, newPosition)</code>. This solution does not seem to be an elegant one either. Domain API would become kind of ridiculous. New state is exact consequence of such events so returning them together does not make much of sense. I thought about separating in a way where domain logic just emits events and the state is built by processing such events outside. But it is hard to imagine how to implement such behavior in functional programming approach. We may even assume that state gets changes synchronously - no two actions get taken at the same time.</p>
  <p>I work with Scala but I think it is more general question. I would appreciate any suggestions, terms to search, links, whatever :)</p>