Nested loops, grids and secluded cells

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • 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!

    Edited 2 times, last by hellii (June 19, 2016 at 3:25 PM).

  • 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 ..?

    a selection of my Fusion examples can be found Please login to see this link.

  • 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.

    Edited once, last by hellii (June 19, 2016 at 4:37 PM).

  • Consider the player draws a path like so, from green circle to red circle:

    Please login to see this link.

    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.

    Edited once, last by hellii (June 19, 2016 at 5:14 PM).

  • I see. Interesting question!

    I would look into flood-fill algorithms:
    Please login to see this link.

    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:

    Please login to see this attachment.

    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

    a selection of my Fusion examples can be found Please login to see this link.

  • 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: Please login to see this link.

    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: Please login to see this link. - 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.

    Edited once, last by hellii (June 19, 2016 at 7:44 PM).

  • Ok, here's a quick tweak of that example
    not 100% tested but should give you an idea of what I was thinking:

    Please login to see this attachment.

    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 XD, if you need further informations let me know!

    a selection of my Fusion examples can be found Please login to see this link.

  • 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: Please login to see this link.

    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): Please login to see this link..

    And here I do it horizontally for ALL rows: Please login to see this link.

    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): Please login to see this link.

    And here I do it vertically for ALL columns: Please login to see this link.

    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' (Please login to see this link.) 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' (Please login to see this link.). 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 (Please login to see this link.).

    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?

  • Uh, we probably overlapped while posting,
    pls check out latest example posted and see if that can be an acceptable solution, before we dig in something else X)

    a selection of my Fusion examples can be found Please login to see this link.

  • EDIT: Yes I noticed we posted at the same time almost haha;

    It looks like your newest example does exactly what I'm going for. I'm having a little difficulty understanding the flags.

    1) If a cell (group.shifting blocks) has internal flag 0 on, that means it's a cell valid for testing, ie. it will look at the type of all adjacent cells?

    2) And if the internal flag 1 for a cell is on, that means the current cell has already been tested?

    3) What does this do: If type of *shifting blocks* = (current_type of cell detector)+1

    EDIT: I'm trying to merge this example with the current code I have, I'll get back to you how it turns out :)

    Edited once, last by hellii (June 20, 2016 at 2:34 PM).

  • Here's how the process is structured:

    Take a look at the "connection_detector" object "detector" animation:
    it exceeds a regular cell size horizontally and vertically of some pixels
    this detector is used to check adjacent cells in this way:

    a) a random cell of first type (1) is picked, the detector is placed above it, its flags 0 and 1 are set ON

    b) each adjacent cell (overlapping detector, but flag 0= OFF) which is the same type of current type inspected, or blank, is "marked" --> setting their flag 0 ON
    these cells "touch" the previous cell and share the same type, or are null types

    c) a random cell among those who have flag 0 ON but flag 1 OFF is now picked, it is marked as "tested for neighbors" --> flag 1 ON, because we are going to test its neighbors now,
    so the detector is placed above this cell, and the process starts back from (b)

    in short:

    1) flag 0 on= is a cell adjacent to the cell we are testing (a neighbor cell), that should be tested as well for neighbors

    2) flag 1 on= is a cell who has been tested for neighbors

    3) this is a bit difficult to explain,
    I added this control to avoid the engine returning true in a situation when you have, say:

    |= line
    A,B,C,D= single cells

    you have this screen:

    A AAA BB CC D

    and say you draw the line in this way:

    A | AAA | BB | CC | D

    You see, you've put the line to divide two A's groups, but you shouldn't, since every A belong to the same group and should be together:

    AAAA | B | C | D

    To detect these situations, the engine grows ID progressively, once per testing cycle,
    (each cycle is a single cell type being checked for all adjacents)
    thus performing only four total cycles (in above situation, where there are four different types)

    in this way, one of the two A's zones is not detected (because when the id grows by one from first group of A, the following cell type picked for inspection is B)
    and if the engine ends with some (non empty) cells not detected, it will return failure.

    a selection of my Fusion examples can be found Please login to see this link.

  • Wow that was a great explanation. I'm also fairly close adapting this approach to my game engine... I'll keep you posted! And thanks a lot for all the help here!! I'll credit you when my game is finished sometime :P

  • How would you go about determining which groups are accepted and which are not? I want to give some feedback to the player which groups are valid and which are not so it's easier for him to complete the levels. I've set up a new VAR for each Cell I call "exclusionIsValid", and I want to change the color of the Cells based on this variable.

    I do it for the other Cell mechanics I have in place already, but since the win conditions are determined differently for this mechanic, I'm not sure how to go about this.

    I'm so close to being done with this mechanic, yet so far. :)

  • Hey thanks for credits, very kind :)

    As for your last post, you need to keep track of what's going on inside the loop,
    I would use an additional value of the "connection detector" and...
    ..well, I guess it's quicker to do than to write XD:

    Please login to see this attachment.

    bad groups will become "black"
    (look actions that >> set RGB coefficient to 0, you can obviously change that to any other action, like changing animation or whatever)

    I've commented the three changes I made in blue, so you can easily locate them

    a selection of my Fusion examples can be found Please login to see this link.

  • Very nice.

    I removed the whole "OR portion" under Test results, as I don't mind if the player groups in Cells like so: A | AA | BBB | CCC

    So let's say the player groups in the Cells like so: A | AA BBB | CCC

    I want the first A to be green (as the A is alone), the AAA BBB to be red (as they are mistakenly grouped together), and CCC to be green as well.

    It looks like it works correctly, ie. it recognizes A | AA | BBB | CCC as SUCCESSFUL. I also got the coloring work as you mentioned, but only if we make it work like "AAA | BBB | CCC", ie. not the "A | AA | BBB | CCC |" way.

    How do I color correctly grouped Cells?

    Edited once, last by hellii (June 20, 2016 at 11:11 PM).

  • Made a quick test on a simplified idea
    (the fact you don't need to test for divisions inside same groups would probably allow for still further simplification)

    Please login to see this attachment.

    Made cells a bit "brighter" to allow for more visible RGB coefficient shift,
    green shift for good groups
    and red for bad

    you can easily track and change "set RGB coefficient" code
    to change animation or do whatever you need to do X)

    (lines 6/8 = "good" color
    line 20 = "bad" color)

    I thought of a couple possible critical situations (again, in "divisions inside same group" condition)
    but brief testing didn't show these issues I was fearing to pop out...
    ...be sure to stress-test before going in production XD

    a selection of my Fusion examples can be found Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!