This is quite a good idea. But can we define our own function that can return a Sub Msg?
Vào 20:41:40 UTC+7 Thứ Hai, ngày 10 tháng 10 năm 2016, Wouter In t Velt đã viết: > > (disclaimer: I am also quite new to Elm) > I always try to avoid creating my own Cmd: there is usually a better, less > bug-prone way to achieve this (e.g. with resursive update calls). > > That said: I can see the logic in having a Msg originating from a "real" > player, and another Msg from your AI player. > > What you could do, is make a subscription to Time, that is only active if > it is the AI's turn to move. > That way, you get a) a delay before the AI makes a move + b) you do not > need to create your own command > Whenever it is the user's turn, or as soon as the game is over, the > subscription is turned off. > > Something like this: > > subscriptions : Model -> Sub Msg > subscriptions model = > if (gameIsNotFinished model && model.turn == AIToMove) then > Time.every second AIMove > else > Sub.none > > You would of course have to define your own functions to check if the game > is still playing (no winner and no draw) and if it is the AI's turn to play. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
