User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 29

Thread: Nested loops, grids and secluded cells

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nested loops, grids and secluded cells

    Imagine a grid with cells [], and a line L drawn on the grid. Furthermore, imagine a cell has a var set to 1, and another cell has a var set to 2, like so:

    [1][][][]
    [L][L][L]
    [][][2][]

    I want to make sure cells with var 1 are for themselves, divided by the L from cells with var 2. How do I make each side of the Line its own entity?

    I tried doing a loop for each cell to check surrounding cells, and keep doing this while these cell detectors don't hit the line L, but I'm not sure how to correctly make nested loops in MMF2. The loops I've tried, crashed for me. I think it was because it ran infinitely.

    How do I make nested loops for this particular example?

    Thanks in advance!

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Sorry, not really understand what you'd need to do:

    1) you have already cells 1 and 2 and you need to place "L"s? Or..?

    2) is this L going to be only horizontal, or could even be vertical (..diagonal)?

    3) is this L an infinite line or a specific segment lenght or..?

    4) how big is the grid, how many 1s and 2s are going to be there, how/when do you place them ..?

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I have a grid you can draw on, you basically draw a path however you want on the grid, up, down, left or right. The line will start and stop at specific cells. Some of these cells on the grid have variables on them, for the sake of clarity here there are cells with 1's & 2's. As the player, you have to separate these different cells, so they are separated from each other by the line you draw. Only 1's can be grouped together, and only 2's can be grouped together. If there's a 2 in a section of 1's, the separation has failed by the player.

    I was thinking of achieving this by doing the following (I have no idea how to do this, as you'll end up infinitely checking cells, since you keep checking the same cells):
    For Each Cell with 1 or 2, make a Cell Detector active all around for each touching Cell, testing a Cell's properties. If a Cell touches an empty Cell, do this loop all over again. Continue until all Cells have been grouped up. If a Cell touches a Line Cell or the border, stop.

    I hope this was somewhat clearer? If not I'll try and make something more visual.

    EDIT: Also for 4), levels will have different amount of 1's and 2's, and they will have different locations as well.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Consider the player draws a path like so, from green circle to red circle:

    http://imgur.com/MCj4EFU

    How can I go through each Cell and group the empty Cells together (give the grouped Cells a common value)? In this case make Red/Orange Cells its own group, Blue Cells its own group and Black Cells its own group.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    I see. Interesting question!

    I would look into flood-fill algorithms:
    https://en.wikipedia.org/wiki/Flood_fill

    without need for the "replacement" color, obviously
    and with the slight modification that:
    if any color touches another color that is not the "line color",
    the game will drop an alert to say the player failed

    you can use this approach to determine same color inside each "zone"
    (and even "count" number of zones -different colors- and/or number of cells per zone, if needed)

    You could even look at a pretty quick array-less example I made for a brick-type game
    where you can test color-connections:

    brick_game_connect.mfa

    I think it could be more-or-less easily adapted to the "check for color different from line color" idea above
    to test whenever a color is adjacent to a different color than itself/or line color

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the detailed response. I'm not really sure how to use this for my specific problem, perhaps you can help me out on getting started?

    Example: http://imgur.com/WmTOqDS

    So I want to keep the Alpha tile and Omega tile separate, like I do with that line. I was considering making detectors outward from each of those specific tiles, and test the variable of the tile (if the tile is a part of the line, if empty or if it's another Alpha/Omega type tile). The line the player made above would be accepted and the level completed.

    If the player does this however: http://imgur.com/AAwK0Bn - the level will fail and the player will have to draw a correct line. So here the Alpha & Omega tiles are connected.

    No arrays are used here as I use detectors for all tile verification. All tiles have variables so it's easy for me to make levels, so I was thinking I'd have to detect variables of each tile radiating outward from each specific Alpha/Omega tile. It's just a problem for me how to do this iteratively without running an infinite loop!

    Any ideas how I can do this? I'm only able to detect tiles just around a tile; I don't know how to keep checking tiles until I reach a Line tile or the border.

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    I'm a bit in a hurry now, will try to make an example, tweaking the one posted above, later in the day!

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers! As I'm still having trouble with this... it's a tricky thing!

  9. #9
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Ok, here's a quick tweak of that example
    not 100% tested but should give you an idea of what I was thinking:

    check_zones.mfa

    you can move (and/or add other) cell types
    but make sure you always have a grid of "blank" elements around them

    could be probably improved...
    not very well commented also , if you need further informations let me know!

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export Module

    Join Date
    Dec 2012
    Location
    Copenhagen, Denmark
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I may have come up with an idea on how to group up tiles together. It's a little hard to explain, but hear me out.

    Consider this path as an example: http://imgur.com/un7WssU

    We want to do a loop for each tile horizontally and vertically, and count starting from one. If we hit the path, we add 1. If we don't hit the path, we write the same number as before. For clarity, here we do it horizontally for the top row (black numbers): http://imgur.com/pBG8B0z.

    And here I do it horizontally for ALL rows: http://imgur.com/q16NbFG

    It may look a bit messy and not make much sense what I'm trying to do right now, but it will make sense once we do a loop for each tile vertically. For clarity, first I do it for the left-most column (red numbers): http://imgur.com/l2vx2lq

    And here I do it vertically for ALL columns: http://imgur.com/dw87ixs

    So here's where the solution is; all tiles are linked together by their number. Top row tile are linked by both '2' and '1' (http://imgur.com/r6fXhL7) but when we get to the right most full column, their top numbers are different, but all bottom numbers are identical - they're all linked together by the '1' (http://imgur.com/vVFO6c2). The bottom blue tile on the column (top number 3, bottom number 1) is then linked with all blue tiles to the left of this tile, since they all have '3' as their top number (http://imgur.com/x0uVHb1).

    So all these tiles are linked since they have numbers in common.

    After every tile has been numbered like mentioned, I'll have to go through a loop to link them somehow.

    Is this a good solution? What do you think? Is there an easier way?

Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. Nested ForEach loops?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 10th March 2017, 05:05 PM
  2. Nested Foreach loops
    By Pixelthief in forum Fusion 2.5
    Replies: 6
    Last Post: 8th June 2014, 05:52 AM
  3. Nested Loops and cycling properly
    By rubes in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 26th January 2013, 04:48 PM
  4. Nested loops and get loopindex
    By Shadoku in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 27th September 2007, 04:13 PM
  5. nested loops
    By westray in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 14th December 2006, 04:00 PM

Posting Permissions

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