Hi
I have a shared collection which stores chess player moves. When the player/s return to the room, their moves are all synched one after the next.
My problem is that if the collection contains an item which has a check flag and Alert is generated. I want to be able to identify if the move is the last item in the collection and only alert 'Check' if the last move resulted in check (not if the 'Check' happened during the course of the game).
I guess the best way to do this is to use the IViewCursor interface maybe?
Thanks
Views
Replies
Total Likes
Hi,
There can be only one check instance at a time in the game. So you could add an another shared property that gets updates whenever there is a check instance. The shared property can have a object that says if there is a check instance, and if so the player.
So any player when ever he re-enters the room and can subscribe to the shared property and get alerted if there is a check instance. This could be a simpler approach.
Thanks
Arun
Views
Replies
Total Likes
Hi justoliver,
I think what you want here is to avoid listening to the sharedCollection's events until it has fully synched up - you can wait until SYNCHRONIZATION_CHANGE, and then :
1. run a for loop through the collection to play back each move (potentially collapsing some of the moves - for example, if a piece gets removed later, no need to process its earlier moves)
2. if you see a "check" flag in one of the moves, make sure its the last move by seeing if the "I" in your for loop is equal to collection.length-1.
All that said, I feel like I'm not sure a sharedCollection is the right way to go. Do you need to store and playback the entire sequence of moves? If not, then it seems like a sharedObject, with a key:value of is a more compact way of expressing the state of your board. For example, with a sharedCollection, it remembers every move made and plays through them, including multiple moves on the same piece, whereas with a sharedObject, you would only store the resultant state of the piece, and subsequent moves on that piece would just modify the original entry. It could be that a record of every move is what you're aiming for, in which case I definitely recommend the approach in 1) above, and collapsing the state of the board down to its result before rendering the board's UI.
hope that helps
nigel
Views
Replies
Total Likes
Hi Nigel
Thanks - I will go with your first suggestion.
I like your idea of using a shared object just to record the state of each
piece (in this case off course each individual piece would require a shared
object). However I think the shared collection suits my purpose so that I
can provide a list of moves to the players.
Views
Replies
Total Likes