Itoo Software Forum

Author Topic: Choose new segment based on last segment?  (Read 578 times)

tonyinseattle

  • Newbie
  • *
  • Posts: 25
Choose new segment based on last segment?
« on: October 27, 2021, 03:38:23 AM »
How do you instruct Railclone to choose a new segment based on the last segment? As a simple example: Suppose you randomize five colored squares along a line (purple, yellow, green, blue, red). However, every time a green segment comes up, you want, say, a 60% chance that the NEXT segment in the series will also be green. This would create random colors except when green appears, in which case you would have longer strings of green in a row due to the probability they'll appear next to each other.

Is it possible to do this? I've tried to create this with variables, but variable values seem to fall off every time the Arithmetic is evaluated. I've also tried to wrap my head around ways of using Sequence or Compose, but nothing quite works.

If the above is not possible, I'd even be happy with this scenario: If a green appears, then the next x segments are also green (where x is, say, a random number between 3 and 10). Slightly different but would get me a similar effect.

Any help out there? Is there a way to let Railclone "know" what the last segment was in order to inform the next?

I'm including a max file just to get things started

Thanks,

Tony

Dragan

  • Hero Member
  • *****
  • Posts: 1419
Re: Choose new segment based on last segment?
« Reply #1 on: October 27, 2021, 12:14:51 PM »
Hi
I don't have access to 3dsmax at the moment but you can try this:

1. Create Compose node and connect  Green Segment to the first input.
2. Create Randomize node and connect all Color Segments to the node (set the Green Segment as the first). Set Presence%: 100% for Green and 0% for the rest of the fields. Connect this Randomize Node to the second Compose input.
3. Create a new Randomize node and to the first input connect the Compose output and to the rest of inputs connect Color Segments except Green Segment
4. Connect this Randomize to Generator`s Default input

Now you can combine Presence% on the First Randomize node to increase segments from 0% to higher values to be more present; eg. Set 50% for the Blue and you should see some of the Blues Segments are added next to the Green ones.

P.S. It is possible to get 4 Greens at a time or even more because of Randomise algorithm, so if you want to avoid   those follow this tutorial: https://www.itoosoft.com/tutorials/non-repeating-randomisation?back=page%3D4%26tag%3Drailclone

Sorry for image presentation  ;D
« Last Edit: October 27, 2021, 12:44:40 PM by Dragan »

Dragan

  • Hero Member
  • *****
  • Posts: 1419
Re: Choose new segment based on last segment?
« Reply #2 on: October 27, 2021, 07:28:33 PM »
Sorry for the delay.
Here is the scene file. I exposed the Green presence parameter.
Hope this will help, please let me know if you need more.

Best Regards


tonyinseattle

  • Newbie
  • *
  • Posts: 25
Re: Choose new segment based on last segment?
« Reply #3 on: October 27, 2021, 10:28:51 PM »
Dragan, I’ve only had a few minutes to download your file and to take a look at this today, but I wanted to thank you for your reply, your drawing, and for following up with a file! It’s much appreciated. I will look at this more carefully later today or tomorrrow and let you know if I’m confused about anything… thanks again!

Tony

tonyinseattle

  • Newbie
  • *
  • Posts: 25
Re: Choose new segment based on last segment?
« Reply #4 on: October 27, 2021, 11:16:25 PM »
OK, I got obsessed with this and put my work aside and played with it. I think I understand what your setup is doing.

So, every time a green square appears, it's followed by a green square x percent of the time, set in the Green % constant.

However, this doesn't continue. In other words, I wanted greens to be "sticky" so that if a green appears, there's x percent chance the next one will be green, and if it is, then there's another x percent that the next one after that will be green too, and so on, until a non-green square appears. (I should have made that more clear.)

The end result would be random colors of squares, but longer stretches of green blocks when they appear.

It seems like a lot of this could be solved if the Compose operator had counters like Sequence does. At least in that case, I could use arithmetic to say if a green square appears, I want from 1 to 20 (randomly chosen) green squares to appear after it before moving on to another color. That would be an acceptable option.

To summarize, is there a way to do either of these two options:

1. If a green square appears, there's an x chance the next square will be green. And if it is, then there's another x percent chance the next one will be green again. Continuing on until the square is not green.

2. If a green square appears, a random number of follow-on green squares appear before moving on to another color.

Thanks!

Tony

Dragan

  • Hero Member
  • *****
  • Posts: 1419
Re: Choose new segment based on last segment?
« Reply #5 on: October 27, 2021, 11:31:30 PM »
Hm... I am still not sure how your algorithm should work but I added some more parameters, for now, to make it more efficient:
Green% is not efficient as it just determinate in what percentage the last segment will appear as Green, so I'll take a look to accommodate this to match your request (when I figure out  :D )
I added Fixed/Random parameters.
You can now choose how many Green segments will be added and in what manner (fixed or random).



tonyinseattle

  • Newbie
  • *
  • Posts: 25
Re: Choose new segment based on last segment?
« Reply #6 on: October 28, 2021, 12:14:54 AM »
Ha, yeah it's kinda complicated!

OK, I just checked out the "c" file and I think this accomplishes what I outlined in option 2 above. So, when Railclone randomly "chooses" a green square, it follows with a random number of green squares before continuing on with another color. That works well enough. Thank you!

Just for the sake of explanation, my original idea-- option 1 above -- was that I was looking for a way to "see" what the previous segment was and allow it to inform what the current segment would be. For example, at the first segment, Railclone places a colored square. Then at the second segment Railclone "looks back" at the previous segment. If that previous segment was NOT green, then it places another randomly colored square of any of the colors (including green) - equal chances for all. If it was green, then I want there to be an x percent chance that this square will be green also. Then onto the third segment. It checks back on the 2nd segment. Was it green? If so, x percent chance this will be green too. If not, then any of the random colors (including green) - equal chances for all.

(Of course, you would want x to be less than 100, or the first time a green square was placed, all of the following squares would be green.)

The effect would be random colors, but blocks of green because the green squares were all "sticky" -- in other words, if a green is placed, there's a good chance the next one will be green again and again until it breaks the cycle by not choosing green.

But I don't think there's any way for Railclone to "see" what the last segment placed was. I thought I could use variables to look back on a segment. For example, if it chooses a green square then set GreenYes = 1. At the next segment, check if GreenYes = 1, and if true, then there's an x percent chance this current segment should be green too. Then railclone chooses the current segment using those weighted chances toward green. If it chooses green, then it places a green square and keeps GreenYes = 1. If not, then it set GreenYes = 0, and it put a randomly colored square in this segment (all equal chances). Then, onto the next segment. First, check GreenYes. If it's 1, then x percent chance this square will be green. If 0, then randomly choose another color, all equal chances.

I don't think variables work that way, though.

At any rate, I hope that makes sense!

Thanks for your help!

Tony

Dragan

  • Hero Member
  • *****
  • Posts: 1419
Re: Choose new segment based on last segment?
« Reply #7 on: October 28, 2021, 06:25:02 AM »
Hm, I don't see the difference between "x chance" vs ”random" distribution. Both ways you should get random number of Greens.
It will help me a lot if you can present visual exaple how "x chance" should look like.

tonyinseattle

  • Newbie
  • *
  • Posts: 25
Re: Choose new segment based on last segment?
« Reply #8 on: October 28, 2021, 06:32:28 AM »
OK, I see the confusion.

When I say “x” I just mean it’s just a stand-in for a number greater than equal chance.

So, for the first segment, there’s an equal chance that it’ll be any of the 5 colors, so 20% chance each. If it happens to be green, then I want to be able to pick a number for the chance (in other words, x) that the next segment will be green. So, if x is 60, then for that second segment, there’s a 60 percent chance it will be green and only 10 percent chance it will be any of the other four colors.

So anytime there’s a green segment, there’s a 60% chance the next segment will be green, too. A green square is always more likely to be followed by another green square.

I would like to be able to change x from 60% to maybe 70% or 80% and get different results.

Hope that helps!

Dragan

  • Hero Member
  • *****
  • Posts: 1419
Re: Choose new segment based on last segment?
« Reply #9 on: October 28, 2021, 08:33:26 AM »
But eventually, that will still produce a random number of Greens in a sequence. Unless you want to have to be generated on Start/Section instead of Segment mode.
If you see my parameter table you will see the Fixed/Random checkbox. If this is checked RC will use random mode.
"Add_RND Min" and "Add_RND Max" will control how many Green segments will be added behind the initial Green segmnet.
So: Min/Max = 2/8 will randomly add between 2 and 8 additional Green segments after the Initial one.
I can show this Min/Max ratio as some kind of percentage value but with Min/Max you have more control.

Green% remains from the first generator and it will just control the last segment so it should just be left on 100%. I think there is no need for this part of the Style.



tonyinseattle

  • Newbie
  • *
  • Posts: 25
Re: Choose new segment based on last segment?
« Reply #10 on: October 28, 2021, 09:01:59 AM »
Yes, absolutely! What you provided works exactly. I was only thinking about it in a different way. Again, thank you so much for all of the time, and the files. Much appreciated!