[SOLVED]How do I pseudorandomness?

0 favourites
  • 14 posts
  • Hello World,

    As some of you may know(for example if you remember the itunes random generation scandal) true randomness doesn't really sit well with people because, ironically, it's not quite as "random" as we expect it to be, things repeat quite often.

    And after a few tests it seems it doesn't sit well with my game eighter, so I need your help to create some pseudorandomness.

    Ok, check the screenshot below.

    In event nr. 4 you can see how I currently try to randomize the sprites that appear.

    Could you guys please show me how the code would be if I wanted to do the following:

    • on first created pick a random member of the family(as I understand it, it does this by default on created since it's a family), then pick a random frame of that member;
    • on next created pick a random member of the family except the member that was previously picked, then pick a random frame of that member except the frame number that was previously picked;
    • on next created pick a random member of the family except the members that where previously picked, then pick a random frame of that member except the frame numbers that where previously picked;
    • after all family members have been picked reset them and the frame numbers(but keep track/remove the frames that where picked in each of them) then start picking family members again respecting the rules above;
    • after all combinations of family members and frames have been picked restart the entire process(so here you would reset the family members, the frame numbers and the frames each one has available for picking).

    Example:

    We have this family:

    • fam.member1 with frames 0, 1, 2, 3
    • fam.member2 with frames 0, 1
    • fam.member3 with frames 0, 1, 2, 3, 4, 5

    Then we start the process and they are randomly picked(spawned) as follows:

    fam.member3 frame 3

    fam.member1 frame 1

    fam.member2 frame 1 skipped as 1 was already chosen during this phase

    fam.member2 frame 0

    First batch done, this is what we have left for the next batch:

    • fam.member1 with frames 0, 2, 3
    • fam.member2 with frames 1
    • fam.member3 with frames 0, 1, 2, 4, 5

    Start picking again:

    fam.member2 frame 0 skipped, while the number 0 is available to be picked in this batch, that family member no longer has that particular frame available

    fam.member2 frame 1

    fam.member1 frame 3

    fam.member3 frame 5

    Now we are left with:

    • fam.member1 with frames 0, 2
    • fam.member3 with frames 0, 1, 2, 4

    And so on. Notice how the frame number that gets picked never repeats itself during a pick phase and it resets between phases, but we keep track and remove the frames that where picked of each individual member between phases, we only make these frames available again after the entire process has finished.

    A couple of important things/problems to keep in mind:

    • I tried both floor(random(8)) and random(0,8) and I didn't notice any difference, so use which ever one you think is best
    • the family members don't all have the same number of frames, some have more frames some have less. That's why it's important to keep track the of the frame numbers that where picked for each family member itself.
    • I don't know if it matters or not, but in event nr. 3 I show you how I spawn the monsters. I'd like to keep that part if possible.

    If you need anymore info let me know.

    Thank you!

  • - the family members don't all have the same number of frames, some have more frames some have less. So what happens for example if my highest number of frames is 8, 1 to 7 have already been picked, but the next family member randomly picked to be created only has 5 frames?

    This makes it impossible..

    You can't set an animation to a frame that doesn't exist..

    If you could explain what you would want to happen in the case this happens?

    Also, what do you mean by "after all combinations of family members and frames have been met"

    Do you just want to create all family members and all frames, or just one of each family-member?

  • Well LittleStain , I guess the most logical(correct me if I'm wrong) course of action in that case would be to skip that combo, don't count/register it as picked(this way the family member won't be taken out of the pool simply for not having enough frames) and try to pick again untill you find a combo that is "valid"/possible. And if there are no more valid combinations left then restart the process.

    Does that make sense?

    P.S. Olso keep in mind that the numbers I use as examples there are actually 1 higher then the numbers of frames. Because I think I read somewhere that floor doesn't pick the last number. So if a animation only has 4 frames I have to set it to 5, so that it can pick 0, 1, 2, 3 and 4.

    LE: I'm just now noticing your second question, yes I'd like to pick all family members and all frames in the end. But without too much repetition, that's why I worded it like that.

    I edited my first post and reworded it to try and make it more clear and added a short example too of how it would work.

  • This is how Dota 2 does it:

    http://dota2.gamepedia.com/Pseudo-random_distribution

    Basically reduces streaks in both "directions" (spawning too fast or spawning nothing at all).

  • Well, good for them mindfaQ , but that doesn't really help me with anything. I need a capx(or some screenshots) with how things would be done in C2 following the rules and example I gave in the first post.

  • Well, good for them mindfaQ , but that doesn't really help me with anything. I need a capx(or some screenshots) with how things would be done in C2 following the rules and example I gave in the first post.

    Ok, so these "fases" or "batches" are at the same time or at different times?

    It would be pretty easy to create a loop that would create a sprite animationframecount times and set each instance to a different frame..

    If they should be created at different times you might want to use that anyway and remove all the ones that have been created before, pick a random instance, etcetera..

    It really depends on what you want to do..

    How many members of the family are there and ist there a reason they should be created as family-memebers instead of creating them as sprites?

  • The phases are at different times LittleStain . Each time an object gets created 1 phase runs. So as you can see from event 3 in the picture the function creates 6 objects one after the other, so 6 phases would run at this time. Sometime later(this is determined by another event I have every x/variable seconds) the function gets called again, 6 new objects get created that push the others down, at this time another 6 phases run(continued from where they left of last time) and so on.

    All families have 5 members each. In total there will be 4 families: MonstersNoSigns, MonstersWithSigns, AmmoNoSigns and AmmoWithSigns. I will be using these families in groups 2 at a time(one group for signs one group for no signs) so at any one time I will be duplicating whatever system you come up with and using it once to spawn monsters and then separately at the same time to spawn the appropiate ammo.

    There is no super important reason why I chose to use families. I just decided on that because it seemed to make part of my randomization and grouping them togheter easier, and because honestly that's what I thought the whole purpose of the family was, to put togheter different things that you plan to use in the same way so you wouldn't have to make a ton of events for each one. And because I'm probably gonna need to put them in families later anyway for other purposes(such as scoring, etc.).

    If you can come up with a better system that doesn't use families(at least for this purpose) that's fine by me, but then you will olso need to show me a reworked version of my spawning system.

  • Yes, indeed it is. Just bad topic title, really.

    You sadly can't spawn families by object name afaik, so using families for creating instances probably won't work, if you want to control what you spawn.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The rules as written don't really give good results:

    https://dl.dropboxusercontent.com/u/542 ... andom.capx

    A few notes on the capx:

    An array instance for each object type is used to keep track of what frames can be picked.

    A family isn't used since you can't specify what member of the family to create, but no matter it only added two events.

    There are a total of 9 different frames in the capx so it just created nine rows of nine to test the idea.

    It looks good toward the beginning of the run but the end of the run almost always looks the same. However it may look better if each sprite had the same amount of frames.

    Probably these rules would work better to run through all the frames in a more distributed manner:

    never create the same sprite twice in a row. (unless there are no other choices)

    the random object picked should be based on how many frames are left for a object. (So an object with more frames are more likely to be picked)

    Once all frames are picked, reset.

    mindfaQ's link may be applicable.

  • Thank you. I really appreciate the effort R0J0hound , sadly it seems you're right, it doesn't look to good. Can you please modify it and try it with your suggestions? Except the one where all objects have the same number of frames, I really can't have/do that unfortunately.

    Olso another thing to keep in mind please,(cause I played around a bit with your loppindex params and I'm not sure in the end if I could make it work in my game) is:

    (by the way using params is a new experience for me, I've never used params on functions before, don't really understand how they work )

    • when a row of monsters/ammo gets created it's "inactive" it's basically just to show the player what's coming next(like you would see the next block that's gonna come in tetris), the sprites will be 45x45 and their first move on y will be of 60px
    • when they move the first time(60px) they will get resized to 65x65 and every time they move on y after that they will be moving 71px instead of 60.

    I'm afraid, is that a bit more flexibility then your example allows for?

    Here's a pic of my movement and resizing code so you can see exactly what I'm talking about.

  • bump.

  • Ok, here's a question LittleStain , R0J0hound , and everyone else.

    What if I take each frame and make it a separate object on it's own? Would that make things easier, could I then put them in an array and do that random thing or what?

    And would that have any drawbacks, specially performance wise?

  • Here's a simplified capx that most of the time creates all the combinations without two of the same type next to each other. It uses an array that stores all the combinations with some text like "sprite:0". Then the array is shuffled by swapping values while trying to keep each two of the same type from being next to each other.

    https://dl.dropboxusercontent.com/u/542 ... ndom2.capx

    As far as moving the objects or using families, you can do anything you like there. All this does is create the objects. Think of the "create" function as a create action with a family as a parameter, only this follows your controlled random requirement.

  • Looks awesome R0J0hound . I'll go with it, thank you very much.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)