A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: turn based simultaneous moving :)

  1. #1
    Collision Noob
    Join Date
    Dec 2009
    Location
    Some unhappy flat
    Posts
    11

    turn based simultaneous moving :)

    I'm making a turn based game.

    enemies, and human player plan their moves,and after pressing "endturn" they all will move simultaneously.

    The thing is - I've made them to compete for desired spot if they choose the same spot for destination. It plays quite simple - unit which won(let's name him 1st) occupies new spot, and the one who's lost(2nd) - stays on his old spot.
    But I have a problem, when there's a 3rd unit, which would like to occupy a spot, where one of the competing units was standing. In case when 2nd unit has lost, it goes back to it's old place, which is already occupied by 3rd guy. And 2nd unit is trapped between 3rd and 1st.

  2. #2
    Senior Member
    Join Date
    Dec 2009
    Posts
    109
    Make it so the second and the third guy compete of that spot.
    Syntax Error

  3. #3
    Collision Noob
    Join Date
    Dec 2009
    Location
    Some unhappy flat
    Posts
    11
    Thing is it - must happen at one time. But in that case it starts chaining.

    Anyway I've scratched idea about one unit pushing another unit from it's place. If spot is taken, nothing happens now. Still looks nice.

    Close/delete topic please.

  4. #4
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    Two ways:

    Single elimination:
    1) Make 1 array of all the moving pieces.
    2) Pick a random piece in the array, and move it only if the space it is moving to is empty.
    3) Remove that piece from the array.
    4) if array is not empty, goto 2

    This is simple, but has the possibility that a piece wants to move to a place ABOUT to be vacated, but not vacated when it moves. Easy fix would be:

    recursive elimination.
    1) Make 2 arrays. One of all the moving pieces, one that starts empty.
    2) Pick a random piece in array 1, and move it only if the space it is moving to is empty.
    3) If the move was successful, remove piece from the array 1. If the move is not successful, remove the piece from array 1 and add it to array 2
    4) if array 1 is not empty goto 2, if array 1 is empty go to 5
    5) copy array 2 to array 1, clear array 2 and goto step 2.

    Keep looping through steps 2-5 until no piece moves.

    Adamkyler's method works great as well. This is going to be somewhat recursive unless you are okay with the single elimination method where you might not be able to move into a vacated square.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center