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.
[03:01 pm]
Oh_Man -- https://www.youtube.com/watch?v=JgODe0xG2Cw finished it last week lol
[01:37 pm]
Vrael -- jesus christ that was 2005?
[09:19 am]
Linekat -- cool
[01:56 am]
Oh_Man -- cool bit of history, spellsword creator talking about the history of EUD ^
[09:24 pm]
Moose -- denis
[05:00 pm]
lil-Inferno -- benis
[2024-4-19. : 10:41 am]
v9bettel -- Nice
[2024-4-19. : 1:39 am]
Ultraviolet -- no u elky skeleton guy, I'll use em better
[2024-4-18. : 10:50 pm]
Vrael -- Ultraviolet
Ultraviolet shouted: How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
hey cut it out I'm getting all the minerals
Please log in to shout.


Members Online: Revenant, C(a)HeK, Zergy