Staredit Network > Forums > SC2 Assistance > Topic: Random number + withdraw
Random number + withdraw
Aug 27 2010, 1:49 am
By: payne  

Aug 27 2010, 1:49 am payne Post #1

:payne:

I suck too much to design such trigger... :(

Basically, I'm trying to spawn random units for random players. Everything is set up, all I'm missing is the player randomization.
I'm trying to randomize between 1 and 3, and then make the editor understand he isn't allowed to pick the same number a second time. Once I have this done, I can copy-paste all my actions in there and Voilą! ;o



None.

Aug 27 2010, 5:05 pm shmeeps Post #2



So, it picks number 1-3, assigns it to a random player, and then has to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units?



None.

Aug 27 2010, 5:06 pm payne Post #3

:payne:

Quote from shmeeps
So, it picks number 1-3, assigns it to a random player, and then has to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units?
Exactly. :)



None.

Aug 27 2010, 5:20 pm shmeeps Post #4



I think the easiest way, at least in theory, to do it would be to set up an array of type boolean of n size, where n is the number of choices you have (in this case, 3 for 1-3), and another array of type boolean of m size, where m is the number of players you have. If it is false, the corresponding value has not been used, if it is true, it has so we must re-select.

The trigger would look like this: http://vgshorts.com/BBCode/BBCode3.php?ID=16

Code
Pick random stuff
   Events
   Local Variables
       Successful Attempts = 0 <Integer>
       Choices = false <Boolean[3]>
       Players = false <Boolean[3]>
       SelectedChoice = 0 <Integer>
       SelectedPlayer = 0 <Integer>
   Conditions
   Actions
       General - For each integer Successful Attempts from 1 to 3 with increment 1, do (Actions)
           Actions
               ------- Pick the unit choice
               Variable - Set SelectedChoice = (Random integer between 0 and 2)
               General - While (Conditions) are true, do (Actions)
                   Conditions
                       Choices[SelectedChoice] == true
                   Actions
                       Variable - Set SelectedChoice = (Random integer between 0 and 2)
               ------- Pick the player number
               Variable - Set SelectedPlayer = (Random integer between 0 and 2)
               General - While (Conditions) are true, do (Actions)
                   Conditions
                       Choices[SelectedChoice] == false
                   Actions
                       Variable - Set SelectedPlayer = (Random integer between 0 and 2)
               ------- Actions
               ------- Do All the unit spawning stuff here ------
               Variable - Set Successful Attempts = (Successful Attempts + 1)
               Variable - Set Choices[SelectedChoice] = true
               Variable - Set Players[SelectedPlayer] = true



It will work, but it does come with the problem that if it keeps randoming the same choice over and over again, it will freeze until it gets a choice that hasn't been selected.



None.

Aug 27 2010, 5:24 pm shmeeps Post #5



Err, don't add in the

Code
Variable - Set Successful Attempts = (Successful Attempts + 1)


That will break it >.<

Should be like this: http://vgshorts.com/BBCode/BBCode3.php?ID=17



None.

Aug 27 2010, 10:24 pm Temp Post #6



It could be improved if you kept all possible choices in an array and selected from that instead (would keep it from freezing). Although you would need a function for shrinking the array, not sure which would be fastest.



None.

Aug 28 2010, 3:14 am payne Post #7

:payne:

Quote from Temp
It could be improved if you kept all possible choices in an array and selected from that instead (would keep it from freezing). Although you would need a function for shrinking the array, not sure which would be fastest.
http://www.staredit.net/starcraft2/Random_integer

Please share your knowledge. :awesome:



None.

Aug 28 2010, 4:32 am shmeeps Post #8



Shrinking an array can generally be about as expensive, and you have to also keep up with the size as well as set up both arrays. Technically, the easiest way to do this would be to use some ADT like a vector/deque/set, even possibly a linked list. But as far as I know SC2 doesn't support these data types.

This was just the first implementation that I came up with that works with the small sets he's looking for.



None.

Aug 29 2010, 12:13 am Temp Post #9



I wasn't thinking of shrinking the array itself. It would be pretty easy to have a variable to keep track of the length of the array. All you would need to do is move items and reset the length.

Also a linked list is definitely possible because a record is just a struct. Unfortunately you can't pass them to functions so they are really only useful as globals.
EDIT: never mind galaxy is a worse language than I though, you cannot nest structs, and you have to declare something before you use it. There might be a way to do this with pure galaxy but I'm not sure exactly how with this language.

Post has been edited 1 time(s), last time on Aug 29 2010, 12:27 am by Temp.



None.

Aug 29 2010, 4:30 am shmeeps Post #10



Well, the problem I see with that is just resizing the array and making sure you never go out of bounds. I don't know if you could make a dynamic resizer in Galaxy that reduces the array size by one and successfully migrates all the data.



None.

Aug 29 2010, 6:07 am Temp Post #11



You don't need to actually resize the array. You use array that is at least the size of the amount of numbers you want to select from.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[02:53 am]
Mr.BurnLiquid -- Symmetry
Symmetry shouted: I'll check it out this weekend!
Thanks
[02:47 am]
Symmetry -- I'll check it out this weekend!
[02:40 am]
Mr.BurnLiquid -- Symmetry
Symmetry shouted: Another map maker? Damn we really ARE back
I invite you to try out the map I modified. I don't have the creativity to create maps from scratch, but I do have the know-how to modify existing ones; my project is to tweak community campaigns (specifically those with errors—to make them playable.
[02:27 am]
Symmetry -- Another map maker? Damn we really ARE back
[01:51 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Now that I wanted to change my avatar, the error image is showing up, haha.
[01:34 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Mr.BurnLiquid
Mr.BurnLiquid shouted: Ultraviolet Thanks; I'm new to the site and a Spanish speaker. I must have missed the part where it was prohibited—I'll change it now.
I invite you to try out a mission I'm modifying from *StarCraft Reversed*; I'm trying to make it more playable and challenging.
[01:33 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: Mr.BurnLiquid actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
Thanks; I'm new to the site and a Spanish speaker. I must have missed the part where it was prohibited—I'll change it now.
[01:31 am]
Ultraviolet -- Mr.BurnLiquid
Mr.BurnLiquid shouted: Ultraviolet Is it forbidden to have a large avatar?
actually yeah though I wasn't really saying it to narc on you. It just caught me off guard because I don't usually see it (because it's against the rules) "The avatar may not be bigger than 150x150 pixels". Kinda silly that it relies on users to be well behaved rather than just limiting the dimensions on uploads :lol:
[12:20 am]
Mr.BurnLiquid -- Ultraviolet
Ultraviolet shouted: https://staredit.net/profile/133367/ dude's avatar is massive
Is it forbidden to have a large avatar?
[12:04 am]
Ultraviolet -- https://staredit.net/profile/133367/ dude's avatar is massive
Please log in to shout.


Members Online: Excalibur