Randomized Number Help

TheTempest

New Member
Reaction score
6
Randomized Number Help [FIXED]

Hey guys. In my map there are 20 islands and 12 players. I want to give each player an island, but randomize it so it's different each time (keeps things fresh).

The problem I'm running into is that 2 players can't have the same island.

I need some sort of way to get this right. The only thing I thought which MIGHT work is just looping until it finds an island that isn't taken up. Of course, this is really inefficient.

If you can do it in GUI I would prefer it (I code in a lot of languages but I don't know JASS. How ironic :rolleyes:)

Thanks
 

Manix

Well-Known Member
Reaction score
29
You didn't mention how you're "giving" the player an island, but let's just say you're spawning a unit there, you should create a dummy unit, or if you already have one create another one called Island Dummy and create one per island (via world editor) then in your trigger where you're giving the islands set the actions up like that:

set tempgroup = units in (entire map) matching (matching unit) equal to Island Dummy
for each integer from 1 to 12 do
loop
set tempunit = random unit from temgroup
remove tempunit from tempgroup
set temppoint = position of tempunit
create 1 peasant for player(integer a) at temppoint
custom script: call RemoveLocation(udg_temppoint)
>outside the loop
custom script: call DestroyGroup(udg_tempgroup)
 

TheTempest

New Member
Reaction score
6
You didn't mention how you're "giving" the player an island, but let's just say you're spawning a unit there, you should create a dummy unit, or if you already have one create another one called Island Dummy and create one per island (via world editor) then in your trigger where you're giving the islands set the actions up like that:

set tempgroup = units in (entire map) matching (matching unit) equal to Island Dummy
for each integer from 1 to 12 do
loop
set tempunit = random unit from temgroup
remove tempunit from tempgroup
set temppoint = position of tempunit
create 1 peasant for player(integer a) at temppoint
custom script: call RemoveLocation(udg_temppoint)
>outside the loop
custom script: call DestroyGroup(udg_tempgroup)

Maybe I wasn't very clear.

I have an int variable PlayerIsles[12] and each element holds the Island # (1-20)

Problem I'm having is that if Player 1 is assigned 3 so PlayerIsles[1] = 3 and Player 2 is assigned 3 then PlayerIsles[2] = 3.

Once the randomizing is finished each player gets a builder at that location so obviouslly you can't have 2 players with the same location.

If I knew JASS i could just do While(tRandNum != PlayerIsles[1] && tRandNum != PlayerIsles[2] etc.)
 

Manix

Well-Known Member
Reaction score
29
That's exactly what I told you to do, you have unit groups here which makes it easier for you to code stuff, you don't need to use integers like in other languages, just look again at my previous post
 

TheTempest

New Member
Reaction score
6
That's exactly what I told you to do, you have unit groups here which makes it easier for you to code stuff, you don't need to use integers like in other languages, just look again at my previous post

I'd prefer to use integers, they take up less memory than creating dummy units.
 

Manix

Well-Known Member
Reaction score
29
o_O well if creating dummies is a problem for you just remove them from the game, which is a total removal of the unit, after you've used them for their purpose..

If you wish to use integers so badly, then simply remove the given isle from the isles variable, example

Isles[1-20] // are your islands
PlayerIsles[1-12] // are the isles that are supposed to be given
IslesCount // is the count of current isles available (Not an Array)
Isle // Integer Variable (Not an Array)

For each integer B from 1 to 12 do
loop
Set Isle = Random number between 1 and IsleCount // This sets the random isle, let's say it's 5
Set PlayerIsles[Integer B] = Isle // Now you need to set the IslesCount to -1
Set IslesCount = IslesCount -1 // Done
For each integer A from Isle to IslesCount // you need to loop through all isles and downgrade them by 1
loop
Set Isles[Integer A] = Isles[Integer A + 1] // now Isle 5 (which I chose to be the random number) becomes Isle 6 and so on, isle 20 becomes isle 19 and the max number of isles becomes 19

I hope you get the idea
 

TheTempest

New Member
Reaction score
6
o_O well if creating dummies is a problem for you just remove them from the game, which is a total removal of the unit, after you've used them for their purpose..

If you wish to use integers so badly, then simply remove the given isle from the isles variable, example

Isles[1-20] // are your islands
PlayerIsles[1-12] // are the isles that are supposed to be given
IslesCount // is the count of current isles available (Not an Array)
Isle // Integer Variable (Not an Array)

Set Isle = Random number between 1 and IsleCount // This sets the random isle, let's say it's 5
Set PlayerIsles[1] = Isle // Now you need to set the IslesCount to -1
Set IslesCount = IslesCount -1 // Done
For each integer A from Isle to IslesCount // you need to loop through all isles and downgrade them by 1
loop
Set Isles[Integer A] = Isles[Integer A + 1] // now Isle 5 (which I chose to be the random number) becomes Isle 6 and so on, isle 20 becomes isle 19 and the max number of isles becomes 19

I hope you get the idea

I downloaded the NewGen pack and JASS is retarded easy. Thanks for trying, Manix. I'll report back when I get some working code (Writing it in JASS is going to be so much easier than GUI when I can use exitwhen)
 

Manix

Well-Known Member
Reaction score
29
Alrightie, what I posted above is the system, if I can call it that way, to pick random stuff by integers, I highly believe it's based off the same idea in jass aswell ;)
 

TheTempest

New Member
Reaction score
6
Fuck JASS syntax.

JASS:
if (iRand == udg_PlayerIsles[a])
then 
set IsTaken = true 
endif


You have to put udg_ before any global variable, correct?

PlayerIsles is an integer array, so I call it using usg_PlayerIsles[] ?
 

Manix

Well-Known Member
Reaction score
29
whether it is an array or not it's still udg_VarName which stands for UserDefinedGlobal, in jass variables are of two types, globals and locals but for more info you should refer to the jass section
 

TheTempest

New Member
Reaction score
6
whether it is an array or not it's still udg_VarName which stands for UserDefinedGlobal, in jass variables are of two types, globals and locals but for more info you should refer to the jass section

I know that. That's the code I have and it's saying that udg_PlayerIsles is an undefined variable (no it isn't)
 

TheTempest

New Member
Reaction score
6
What is this udg_PlayerIsles[a]

JASS:
function GenerateIslandNumber takes integer iPlayerNum returns integer

local integer iRand = GetRandomInt(1, 20)
local integer a = 0
local boolean IsTaken = false

    loop
        set a = a + 1
        
        // If the random number matches one of the islands that have already
        // been taken then set istaken to true
        if (iRand == udg_PlayerIsles[a])
        then 
        set IsTaken = true 
        endif
        
        // After we have looped through all the players (a > iPlayerNum)
        // and there hasn't been a match then exit the loop and return iRand
        exitwhen a > iPlayerNum and IsTaken == false
        
        // This is only called if the exitwhen condition was false
        if(a > iPlayerNum) then

        // Reset our loop variable and generate a new number
        set a = 0
        set iRand = GetRandomInt(1, 20)

        endif
    endloop

return iRand

endfunction


"udg_PlayerIsles undefined variable."

In my variable editor: "PlayerIsles : Integer : Array[12]"
 

TheTempest

New Member
Reaction score
6
What is this udg_PlayerIsles[a]

JASS:
function GenerateIslandNumber takes integer iPlayerNum returns integer

local integer iRand = GetRandomInt(1, 20)
local integer a = 0
local boolean IsTaken = false

    loop
        set a = a + 1
        
        // If the random number matches one of the islands that have already
        // been taken then set istaken to true
        if (iRand == udg_PlayerIsles[a])
        then 
        set IsTaken = true 
        endif
        
        // After we have looped through all the players (a > iPlayerNum)
        // and there hasn't been a match then exit the loop and return iRand
        exitwhen a > iPlayerNum and IsTaken == false
        
        // This is only called if the exitwhen condition was false
        if(a > iPlayerNum) then

        // Reset our loop variable and generate a new number
        set a = 0
        set iRand = GetRandomInt(1, 20)

        endif
    endloop

return iRand

endfunction


"udg_PlayerIsles undefined variable."

In my variable editor: "PlayerIsles : Integer : Array[12]"

EDIT: Sorry for the double post.
 

Summoned

New Member
Reaction score
51
Try setting the Array Size to 1 in the object editor. The Size stands for something very different than what you'd expect Array Size to mean.
 

Manix

Well-Known Member
Reaction score
29
Well Idk, You could've done what I suggested, it works I've used that system for an AoS -ar command
 

Manix

Well-Known Member
Reaction score
29
Well try stuff out, try changing it, changing the array capacity, as already suggested, try creating a different variable and using it, try setting it in the same function see what does what

EDIT: I'm goin to bed nao, I wish you good luck on fixing your code, will respond back tomorrow if it's still an issue
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top