On 7/5/07, Red <[EMAIL PROTECTED]> wrote:
> I can't figure out an intelligent way to do this. If I set revert to true,
> it will snap back to it's original position when I want it to stay at the
> square while checking to see if the move is legit. If I set revert to false
> and the move is illegal, it's not going to know where to snap back to.
>
> Anybody have any ideas how to go about this? Thanks in advance.
>

How about pre-fetching your legal moves for the piece using the XHR call?
Then you can validate the move against a local set of data.  For example:

In a grid where the rows are numbered and the columns are lettered,
we'll say a pawn is in square 4A
The pre-fetch for that piece says that it can only legally move to
square 5A (if there were an opponent's piece in 5B, that square would
also be returned)
The user moves the piece forward 1 square (legally) to square 5A (If
they tried 6A, the event would return false and snap the piece back.)
If the ondrop event says it's "OK" for that piece, you fire off an XHR
to get the next list of legal moves for that piece

I'm sure it will get more complicated with regards to taking another
person's piece, etc - but using Ajax before the person actually has to
make the move would be more sensible rather than making the person
wait for the response for each move.

You could then maintain an object with 32 (16 black, 16 white)
elements with arrays of "legal" moves.

My two cents :)

Jon

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to