Problem with chain reaction algorythm

Hello all,
i apologize from the start if this isn't the correct place to post this question.
I'm quite new to GameSalad, however i'm an experienced programmer. I'm only stating this to say i'm quite used to working with algorythms and general program logic.

I'm kinda addicted to GS, and i think i got the basic knowledge by now, however, there is this problem i can't seem to solve and, i honeslty don't know why, and can't find a similar thread but it. Please, bear with me :)

Im trying to develop some sort of chain reaction with some actors on a 2D board. "Something" happens to an actor and the surrouding actors (of the same type) are influenced by it. According to some variables, they may or may not spread that same behavior to the surrouning ones, and so on. Basic chain reaction 101.
Something like this:
http://www.freeaddictinggames.com/game/bomb-chain/

The problem is that it seems that some of the actors miss out of this chain reaction. The effect can and should spread on all directions on a X/Y axis, ideally on multiple "threads", however, it seems to spread to some directions and ignore others. The spread rule is simple math, im not doing anything with colision or anything, simple position comparisson.

Any thoughts?

Thx!

Comments

  • DuesDues Member Posts: 1,159
    Hi @muffles and Welcome to the forums!
    Id suggest you post some screenshots of you rules, so its easier for people who read this to give you an answer :)
    It could have something to do with the order of your rules. You might know this, but GS reads from the bottom of the layers and up, and inside the actors its from the top and down.

  • mufflesmuffles Member Posts: 8
    Hey, thanks for the reply!
    I made a simple layout just to test this behavior before implementing it on the actual puzzle.
    I will post 2 images with the behavior i'm trying to get:

    This one is the starting state:
    http://oi59.tinypic.com/2w5u4w0.jpg

    By clicking on any "1" i would trigger an event. Each "1" would expand to all directions (up, down, right, left). Any expansion to another "1" would trigger that one's expansion and so on.

    As you can see here:
    http://oi61.tinypic.com/5y6uww.jpg

    By clicking on the second "1" from the left, It seems to expand to the right side only, on a single thread it seems, and totally ignoring the other directions as it goes.
    I've tried many different aproaches, some much more complicated than the others, but eventually they all fail.
    Want me to explain them?

    Thanks in advance!
  • mufflesmuffles Member Posts: 8
    edited February 2014
    Ok, ill go ahead and just try to explain my approach, just to speed up the process :)

    So, the basic design for testing pusposes consists only in one actor, the square. To map it fast on a 2D board I simply defined variables by hand to each instance (X,Y). So each one has an X and a Y coordinate, and a counter (0/1)

    Rules image:
    http://oi61.tinypic.com/28qz382.jpg

    About the actor rules, there is:
    - The obvious display text;
    - One to make a 0 into a 1;
    - One to check if the counter is already 1 and save the coordinates as game variables;
    - One to check the game variables and make the math to check if it's next to a "1", and if it is, becomes a 1 aswell;

    After this failing, i tried to add an "update counter" on all actors. The plan was to at each new "iteration", each actor had to update it's state according to the last event, before the next step in the chain could be made.
    That also failed and i honestely can't understand why, since the behavior im viewing makes absolutelly no sense to me, it's as if it works sometimes, and sometimes it just doesn't...

    I've made countless attempts and i seem to be stuck at the moment..

    Thank you in advance!
  • mufflesmuffles Member Posts: 8
    Still stuck @Dues, any ideas?
  • DuesDues Member Posts: 1,159
    This is beyond my level of intelligence :)
    Maybe someone like @Tatiang or @Fryingbaconstudios could give you any tips?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Can you post a screenshot of the starting state and then a separate screenshot showing what the next state should look like (instead of one showing a failed state)?

    This is really throwing me off:
    "Something" happens to an actor and the surrouding actors (of the same type) are influenced by it. According to some variables, they may or may not spread that same behavior to the surrouning ones, and so on. Basic chain reaction 101.
    If you're a programmer, you should be able to give me the whole algorithm. That will make things a lot clearer.

    In fact, screenshots aren't necessary but are probably a time-saver. You could also just show the progression of a few steps, like this:

    00000
    01110 (click row 2, col 2)
    00000

    01000
    11110 (click row 2, col 4)
    01000

    01010
    11111
    01010


    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • mufflesmuffles Member Posts: 8
    Thx for the comment @tatiang.
    I kinda messed up splitting the question into a few posts, I will try to be clearer.

    I made a simple board, lts say 4x4. All the actors have a default state of 0:

    0 0 0 0
    0 0 0 0
    0 0 0 0
    0 0 0 0

    By pressing any 0, it would increment itself to 1. By pressing any 1, it would increment th surrounding blocks to 1.

    0 0 0 0
    0 1 0 1
    0 0 0 0
    0 0 0 0

    press (1,1)

    0 1 0 0
    1 1 1 1
    0 1 0 0
    0 0 0 0

    If the surrounding blocks are already 1, they will also expand themselves. Given this last state and pressing (1,3) one would get a chain reaction through all the '1's:

    1 1 1 1
    1 1 1 1
    1 1 1 1
    0 1 0 0

    My problem consists in getting something like:

    0 0 0 0
    0 1 1 0
    0 0 0 0
    0 0 0 0

    press (1,1)

    0 0 1 0
    0 1 1 1
    0 0 1 0
    0 0 0 0

    It seems it triggers the rule on (1,2) first and "forgets" to trigger the rule for (0,1) to realise it's suposed to increment. And so, breaking the chain reaction, working on what appears to be a single thread.

    Would this make my problem clearer?


    Thank you!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, it makes sense now! :)

    I would, without a doubt, use tables for this. It's going to be a little more work without a Pro membership (the tables functions and expressions in the Nightly build are a huge help with this sort of thing) but it's certainly doable. I'll see if I can work out a demo for you. Obviously, the hard part is the chain reaction.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • mufflesmuffles Member Posts: 8
    That was my first thought exactly. It would be much easier to do the math on some arrays and simply output the values, however, i can't seem to do much with the tables, not even a simple for loop...

    Any help would be REALY welcome :)

    Thanks a bunch
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Well, the Pro nightly build has Loop and Loop over Table behaviors as well as fine control over table cells (merge cells, sum cells, etc.). There are ways to do much of this in the free version but it takes longer and is more cumbersome to code.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    So it's kind of a pain to make this demo with the free version and as such I'm going to direct you to a Minesweeper demo that might be of use: https://forums.gamesalad.com/discussion/comment/438905/#Comment_438905.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @muffles -- Here is a quick prototype that shows one way to go. Normally I'd use tables too, but for some reason I didn't want to.

    This might give you some ideas to bounce around.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited February 2014
    Yes the new table summing and search functions would slim the code to do this way down.

    I'm using them to do something similar for my battle ship multiplayer prototype. I have a grid and chart the ship's location also hits and missed and calculate when a ship has been hit in each of it's grid slots. Being able to isolate table cross sections by column and row makes this easier than it would have been in the past.
  • mufflesmuffles Member Posts: 8
    edited February 2014
    @RThurman, awesome thanks! Eventually i got this working, although it still has a few bugs.

    @FryingBaconStudios, how do you place your board tiles on the scene? Do you do it by hand. I'm asking this because i'm trying to auto build my board according to a table, lets say 5x5. It seems simple enough, however I can't seem to get the "auto loop" through all of the table's values at the start of each level...

    If i do:

    game.counter = 0;

    *Actor1*
    - game.trigger = true;
    - if(game.trigger == true)
    game.counter = game;
    game.trigger = false;
    Spawn Actor2;

    *Actor2*
    - if(game.trigger = false)
    game.trigger = true


    Shouldn't this work as a loop? If not, how else can I loop through a whole table?

    Thanks!

  • mufflesmuffles Member Posts: 8
    Anyone?
Sign In or Register to comment.