• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Randomize Regions("levels") Without Repeating?

Status
Not open for further replies.
Level 4
Joined
Apr 16, 2018
Messages
47
I am making an escape maze, and need the ability to randomize which level comes up next without ever doing the same maze level which are differentiated by the start region where they both start and respawn at each level when set to current spawn region.

I was hoping to add them all to a list randomly without ever picking the same one, then go down the list in order to do each. I have tried an integer approach and a regions array approach but I could not figure out how in either. Could not find any useful events for regions. to add them or remove them from arrays or anything. I am completely lost, I just cant figure out what to do. I have been happy to be able to do most my stuff myself, but some reason this is just not computing in my head...
 
Last edited:
Level 23
Joined
Apr 3, 2018
Messages
464
To remove an item from a list (array), swap it with the last item of your list and reduce your "item count" variable (used when randomizing as max value) by 1.

Something like
  • given array ABCDE, count = 5
  • random 1 to 5, say you roll 2 which is B
  • let's remove B, swap it with last item #5 = E
  • after swap it's AECDB, count = 4
Now you can't roll B again by rolling 1-4
 
Last edited:
You can also do this with pre-placed units and unit groups;
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in RandomizeUnitsRegion <gen>) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to SelectionUnitGroup
  • Remove From Unit Group
    • Events
      • Player - Player 1 (Red) types a chat message containing Your Event Here as An exact match
    • Conditions
    • Actions
      • Set RandomUnit = (Random unit from SelectionUnitGroup)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of RandomUnit) Equal to Footman
        • Then - Actions
          • Unit Group - Remove RandomUnit from SelectionUnitGroup
          • Trigger - Run Run Your Functions Here 1 <gen> (checking conditions)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of RandomUnit) Equal to Peasant
            • Then - Actions
              • Unit Group - Remove RandomUnit from SelectionUnitGroup
              • Trigger - Run Run Your Functions Here 2 <gen> (checking conditions)
            • Else - Actions
 
Last edited:
Level 4
Joined
Apr 16, 2018
Messages
47
Interesting to see the unit version, suppose that would work indeed, thank you for the suggestion.

Well I managed to get the first method from biridius working, seems so obvious after layed it out. xD

Only 1 problem... for no fking reason that I can possibly fathom or find no matter how much I isolate parts of all the triggers to test and find... My character no longer slides, dies, or anything related to my sliding maze mechanics... I have a command that individually starts each level in i'm pretty sure the same way per level and slides fine; but as soon as I do the random mode it will no longer work on those mechanics...

I don't wanna be a pain, and post tons of triggers for help considering it is kinda of a slight complicated of interconnected triggers for different purposes.

Edit: Fixed the problem... Was a stupidly easy small thing that simply needed found and that is all...

Thank you everyone for the help on this!
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
The programmatical approach is to add all of them to a set data structure and then pick random elements from that set to add to a list and then be removed from the set, and then sequentially progress through that list.

The set data structure is usually implemented as an array list except removal of elements replaces the removed element with the end of list element for O(1) complexity since sets do not care about element order unlike lists. A random element is then obtained by a random index between the first of list and last of list, again with O(1) complexity. The resulting list is usually an array list, which is progressed through sequentially by incrementing an integer every level.
 
Status
Not open for further replies.
Top