• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Duplicated AI Player Names In-Game

Status
Not open for further replies.
Level 2
Joined
Aug 24, 2017
Messages
18
hey guys, it's me again. so i recently figured out how to make AI players have random names for their selves, and i was over the moon when i learned something.
but however, it has come to my attention when i tested this on a melee map (for fun lolz), I got 2 issues.

Issue #1: Some of the AI players happened to have gotten the same names.

Example A:
Screenshot (109).png

Screenshot (108).png


Example B:
Screenshot (104).png

Screenshot (105).png



Issue #2: At other times, the AI bots were named as "Player #" (the # was meant to be the number, like Player 6, Player 9, etc.) when they were supposedly should be named with "AI [AIName]"

Example:
Screenshot (106).png

Screenshot (107).png




Honestly I don't even know what went wrong, I'm such a dummy when to creating/editing triggers and all, so if anyone could shed some light on how to fix this, it would be highly appreciated. Here's how my triggers looked like:
Screenshot (99).png

Screenshot (100).png
Screenshot (101).png
Screenshot (102).png
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
You cannot EVER put a wait in a Map Init trigger. The wait will be completely ignored because waits can’t happen in the map init thread (it technically runs during the loading screen). For what you want to do just change the event to 0.50s elapsed game-time and remove the wait.

Statistically it’s not a 1/27 chance to have a shared name; it’s actually much higher than that. It’s 1/27 that the (N+1)th name is the same as the Nth name.

To work out the probability that NO NAMES are duplicated, consider each AI name being chosen sequentially:

1. All names are unique so 27/27 chance to be unique.
2. One name is used so 26/27 names are unique.
3. Two names are used so 25/27 possible choices aren’t repeats.

N. (N-1) names have been chosen, so there are (27-(N-1)) non-repeat choices.

The math shows that (27/27)(26/27)(25/27)…(20/27) = 0.317, so there is only a 31.7% chance that out of 8 randomly assigned names none of them are duplicates.

The solution is just to move entries in the list of names around as they are chosen so that picked names cannot be randomized again. Move them to the back of the list and decrease the variable that counts how many there are.
 
Level 13
Joined
Oct 16, 2010
Messages
731
You need a couple more variables to make this work without duplicates

1. An integer for the maximum number of names (in this case 27 - we'll call it "totalnames")
2. An integer for the randomly chosen name (you pick a random number first so you can reference back to it - we'll call it "chosenname")

So in your init trigger you need to set "totalnames" to your max names (27)

Then when you pick your name you first set "chosenname" to a random number between 1 and "totalnames", you then use the variable "chosenname" in your line where you change the players name

Finally, after you've used the name you need to remove it from the list. Easiest way to do this is to set AInames"chosenname" to AInames"totalnames", then lower "totalnames" by 1. To visualise this a bit we'll say for example you have picked name number 5, you need to replace name 5 with name 27, then reduce the total names left to 26. This is what I call de-indexing.
 
Level 2
Joined
Aug 24, 2017
Messages
18
You cannot EVER put a wait in a Map Init trigger. The wait will be completely ignored because waits can’t happen in the map init thread (it technically runs during the loading screen). For what you want to do just change the event to 0.50s elapsed game-time and remove the wait.

Statistically it’s not a 1/27 chance to have a shared name; it’s actually much higher than that. It’s 1/27 that the (N+1)th name is the same as the Nth name.

To work out the probability that NO NAMES are duplicated, consider each AI name being chosen sequentially:

1. All names are unique so 27/27 chance to be unique.
2. One name is used so 26/27 names are unique.
3. Two names are used so 25/27 possible choices aren’t repeats.

N. (N-1) names have been chosen, so there are (27-(N-1)) non-repeat choices.

The math shows that (27/27)(26/27)(25/27)…(20/27) = 0.317, so there is only a 31.7% chance that out of 8 randomly assigned names none of them are duplicates.

The solution is just to move entries in the list of names around as they are chosen so that picked names cannot be randomized again. Move them to the back of the list and decrease the variable that counts how many there are.
You need a couple more variables to make this work without duplicates

1. An integer for the maximum number of names (in this case 27 - we'll call it "totalnames")
2. An integer for the randomly chosen name (you pick a random number first so you can reference back to it - we'll call it "chosenname")

So in your init trigger you need to set "totalnames" to your max names (27)

Then when you pick your name you first set "chosenname" to a random number between 1 and "totalnames", you then use the variable "chosenname" in your line where you change the players name

Finally, after you've used the name you need to remove it from the list. Easiest way to do this is to set AInames"chosenname" to AInames"totalnames", then lower "totalnames" by 1. To visualise this a bit we'll say for example you have picked name number 5, you need to replace name 5 with name 27, then reduce the total names left to 26. This is what I call de-indexing.

yea I definitely need to know how would the triggers and variables are suppose to look like from the Trigger Editor, just words alone is making me confused 😭
💔
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
yea I definitely need to know how would the triggers and variables are suppose to look like from the Trigger Editor, just words alone is making me confused 😭
💔
Both of us are telling you to do the same thing. Also, you should do this instead of taking screenshots: How To Post Your Trigger
  • Events
    • Time - Elapsed game-time is 0.50 seconds
  • Conditions
  • Actions
    • Set AINameCount = (AINameCount + 1) //this integer variable has a default value of 0
    • Set AINames[AINameCount] = [AI] Light
    • Set AINameCount = (AINameCount + 1)
    • Set AINames[AINameCount] = [AI] Venom
    • Set AINameCount = (AINameCount + 1)
    • Set AINames[AINameCount] = [AI] Sapphire
    • -------- etc for all names --------
    • -------- after all names are added, AINameCount is the total number of AI names --------
    • Player Group - Pick every player in (All Players) and do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • ((Picked Player) controller) equal to Computer
          • Then - Actions
            • Set NameSelect = (Random integer between 1 and AINameCount) //in your trigger your lower bound was -1 instead of 1. There is no reason for that, it would just cause the name to be blank 2/29 times.
            • Player - Set name of (Picked Player) to AINames[NameSelect]
            • Set AINames[NameSelect] = AINames[AINameCount]
            • Set AINameCount = (AINameCount - 1)
          • Else - Actions
 
Status
Not open for further replies.
Top