   require BattleSnake.Replay
   require Record
 
+  @enforce_keys [:size, :buffer]
+
   defstruct([
-    :frame_buffer,
-    :watched_frame_buffer,
-    :receiver,
+    :buffer,
+    :size,
     :replay_speed,
     :topic,
+    pos: 0,
     state: :suspend
   ])
 

    time = state.replay_speed
    topic = state.topic

    {frame, new_state} =
      get_and_update_in(state.watched_frame_buffer, fn [frame | buffer] ->
        {frame, buffer}
      end)

    new_state =
      update_in(new_state.frame_buffer, fn buffer ->
        [frame | buffer]
      end)

    Process.send_after(self(), {:broadcast_prev_frame, :auto}, time)
    PubSub.broadcast(topic, %Frame{data: frame})

    time = state.replay_speed
    topic = state.topic

    {pos, new_state} = get_and_update_in(state.pos, &{&1, &1 + 1})
    frame = :array.get(pos, state.buffer)

    Process.send_after(self(), {:broadcast_next_frame, :auto}, time)
    PubSub.broadcast(topic, %Frame{data: frame})
