Op woensdag 12 oktober 2016 06:17:37 UTC+2 schreef hoang...@gmail.com:
>
> But if I do it this way, it's gonna return both the player's move and the
> AI's move at the same time. What I want to have is that the game displays
> the player's move THEN call minimax function on current model and
I'm sorry. Don't why your answer wasn't loaded that day.
Aren't "set and unset whenever processing is started/finished"
side-effects? We can do that easily in imperative languages but all
functions in ELM are pure.
Vào 03:55:33 UTC+7 Thứ Ba, ngày 11 tháng 10 năm 2016, OvermindDL1 đã viết:
>
>
But if I do it this way, it's gonna return both the player's move and the
AI's move at the same time. What I want to have is that the game displays
the player's move THEN call minimax function on current model and THEN
display the AI's move
Vào 06:41:14 UTC+7 Thứ Tư, ngày 12 tháng 10 năm 2016,
It's a common misunderstanding that every discrete change to a model must
originate from a different message. In general messages are for expressing
what is allowed to happen in your application as a result of outside
behavior like user input and server responses, whereas you want to run your
PS: The subscription to time is useful if you want some sort of timeout or
delay between the user move and the AI move.
If you want to do the AI move immediately after the user move (without
delay),
a pattern with a recursive update call (and without subscription) is
probably more suited.
I had the solution. Just show thinking when its AI's turn and the game is
not over. :D
Vào 03:07:59 UTC+7 Thứ Ba, ngày 11 tháng 10 năm 2016, hoang...@gmail.com đã
viết:
>
> The AnimationFrame works perfectly. Thank you :D
> I have another question came in mind. How do you think can we make
I'd set a flag on the model for when it is 'processing' (good flag name,
maybe `isProcessing` or so?) and just test that in the model and set and
unset it whenever processing is started/finished. :-)
Just think of it as another piece of 'state'. In fact if it can be gleaned
from another
The AnimationFrame works perfectly. Thank you :D
I have another question came in mind. How do you think can we make the view
display, for example "Thinking", while the minimax algorithm is being
executed?
Thank you a lot for your help. :D
Vào 00:11:59 UTC+7 Thứ Ba, ngày 11 tháng 10 năm 2016,
Most callbacks in a browser, such as the timeout used for Time, is
throttled to 4ms and behaves strangely below 16ms, if you want to execute
as fast as possible then you should use an AnimationFrame subscription.
Time subscriptions should only be used for 500ms or larger or so, any less
and
I just found a problem with using subscription though. I tried replace
second with millisecond, while the minimax was executing (about less than a
second) the program keep calling more AIMove.
subscriptions model =
if (gameIsNotFinished model && model.turn == AIToMove) then
Time.every
The example he put above is fine: :)
```
subscriptions : Model -> Sub Msg
subscriptions model =
if (gameIsNotFinished model && model.turn == AIToMove) then
Time.every second AIMove
else
Sub.none
```
Though if you want it in another function you can do that too (useful to
batch
Can you show code example :D I'm quite new to Elm and javascript.
Vào 23:45:45 UTC+7 Thứ Hai, ngày 10 tháng 10 năm 2016, OvermindDL1 đã viết:
>
> Yep, just call it from the subscriptions callback then.
>
>
> On Monday, October 10, 2016 at 10:36:58 AM UTC-6, hoang...@gmail.com
> wrote:
>>
>>
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
>
(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
14 matches
Mail list logo