I am trying to learn more about functional-reactive programming by using Rx.Net to implement Tic-Tac-Toe. The problem I am having is that there seems to be a circular dependency in my game-logic.
The commands
stream (PlaceToken
, ResetGame
, etc.) is generated from user-input streams.
The current state of the game (boardStates
) is derived by applying commands
to the previous state, starting with the initial state:
var initialBoardState = new BoardState();
var boardStates = commands
.Scan(initialBoardState, (boardState, command) => command.Apply(boardState))
.DistinctUntilChanged();
However, the commands
stream should depend on the boardStates
stream. This is because the valid set of commands changes with the current state.
For example, the PlaceToken
command should only be issued when the user clicks on an empty tile, but the set of empty tiles is defined by the current state!
So to summarise, I have two streams which seem to depend on each-other. How should I work around this in functional-reactive programming?