Jump to content

Algorithm for choosing unique names of AI-controlled players


Recommended Posts

On 15/03/2024 at 5:49 PM, Gurken Khan said:

It would be nice if duplicates were avoided; maybe some old code interferes that adds "II" to a duplicate?

[EDIT: above quote is from this post from the thread Alpha 27 Pre-release/Release Candidate Build Testing of which this thread here has been split off]

You brought me to the idea to search for 'AINames' (I use GitHub Search for that) and I found lines 85-100 of ps/trunk/binaries/data/mods/public/gamesettings/attributes/PlayerName.js. Quote:

	            // Pick one of the available botnames for the chosen civ
	            // Determine botnames
	            let chosenName = pickRandom(this.settings.civData[civ].AINames);
	            if (!this.settings.isNetworked)
	                chosenName = translate(chosenName);
	
	            // Count how many players use the chosenName
	            let usedName = this.values.filter(oName => oName && oName.indexOf(chosenName) !== -1).length;
	
	            this.values[i] =
	                usedName ?
	                    sprintf(this.RomanLabel, {
	                        "playerName": chosenName,
	                        "romanNumber": this.RomanNumbers[usedName + 1]
	                    }) :
	                    chosenName;

I don't understand JavaScript much. Thank you very much to everyone helping comprehend what [usedName + 1] means.

Edited by Obelix
giving context to offsplitted origin
  • Like 1
Link to comment
Share on other sites

34 minutes ago, Obelix said:

what [usedName + 1] means

47 minutes ago, Gurken Khan said:

that adds "II" to a duplicate

;)

Maybe that's the culprit, should pick another name from the list?

Edit: there can be eight players and there are nine names in the list; IMHO this slapping on of a higher number to chosenName needs to go.

Edited by Gurken Khan
  • Like 2
Link to comment
Share on other sites

@Gurken Khan @Obelix

I was not able to replicate the bug:

screenshot0012.png.16a41a3b18f47bbebe04d194fd66620c.png

 

However, forcing the game to choose a new name for each AI player (and avoid all the hassle with the Roman numerals) could be done by simply adding this:

Quote

let chosenName = pickRandom(this.settings.civData[civ].AINames.filter(el => !this.values.indexOf(el) !== -1));

 

Edited by Vantha
  • Like 3
Link to comment
Share on other sites

43 minutes ago, Vantha said:

I was not able to replicate the bug:

At least that's counting up correctly; still lame. :P

I can't judge your code, but I hope that in the next version the game will pick one of the other names in the list and doesn't feature imaginary Themistocles II-VII.

Where does "Themistocles" come from anyway, it's not in https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/data/civs/athen.json ?

Spoiler
   "AINames": [
59	        "Cimon",
60	        "Aristides",
61	        "Xenophon",
62	        "Hippias",
63	        "Cleisthenes",
64	        "Thucydides",
65	        "Alcibiades",
66	        "Miltiades",
67	        "Cleon",
68	        "Cleophon",
69	        "Thrasybulus",
70	        "Demosthenes"
71	    ],

 

Link to comment
Share on other sites

4 hours ago, hyperion said:

Anyway not a bug a as you can't reasonably require sufficient names for any case.

Apart from the Gauls, Iberians and Mauryan every civ has eight or more names in the list; so if we came up with six more names we would have sufficient names for every case.

Link to comment
Share on other sites

Regarding the AI Names, in my local files each civ actually has at least 8 AINames (only the Iberians for some reason have a double entry of Viriato, so there'd be a single one missing for the Iberians).

I suggest to remove the system of counting names that are chosen multiple times with Roman numbers. Especially if it's this simple to change.

Currently, in a 4v4 of AIs with everyone playing Persians, on average 2 to 3 players will get a 'problematic' name because many of the their names include a Roman numeral themselves and an additional one is added if a name is picked multiple times.

Edited by Vantha
  • Like 1
Link to comment
Share on other sites

23 minutes ago, Vantha said:

in my local files each civ actually has at least 8 AINames

Interesting. I went through the lists at https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/data/civs/....json just before posting.

Link to comment
Share on other sites

23 hours ago, Vantha said:

I suggest to remove the system of counting names that are chosen multiple times with Roman numbers. Especially if it's this simple to change.

The code needs to generate an endless list of names, could be bot1, bot2 and so on. The improved names here are only for role-playing purpose. If you don't provide an endless list you might break mods or add another thing that breaks should you increase max players. Tweaking the generator is an option but discussing this I consider off-topic (like most in this thread) so I stop here.

  • Like 1
Link to comment
Share on other sites

1 hour ago, hyperion said:

The code needs to generate an endless list of names, could be bot1, bot2 and so on. The improved names here are only for role-playing purpose. If you don't provide an endless list you might break mods or add another thing that breaks should you increase max players. Tweaking the generator is an option but discussing this I consider off-topic (like most in this thread) so I stop here.

Should I open a designated thread?

  • Like 1
Link to comment
Share on other sites

On 16/03/2024 at 1:00 PM, Vantha said:

@Gurken Khan @Obelix

I was not able to replicate the bug:

screenshot0012.png.16a41a3b18f47bbebe04d194fd66620c.png

 

However, forcing the game to choose a new name for each AI player (and avoid all the hassle with the Roman numerals) could be done by simply adding this:

submit the patch or make a mod. if the change creates a requirement for civs to have at least 8 ruler names, that's a new requirement codewise and it should be made clear.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 18/03/2024 at 8:27 PM, alre said:

if the change creates a requirement for civs to have at least 8 ruler names, that's a new requirement codewise and it should be made clear.

Where should it be made clear? Maybe it'd be best to fill in missing names in the same patch?

I found that the hero names got removed from the AI names list in rP27683 which I guess makes sense. I see two options: We either need to find one new name for the Mauryas and the Britons and four for the Iberians, or we revert this change and only require a last one for the Iberians.

If noone has any suggestions, I can research for the missing names myself, I shouldn't be too hard, and propose them here.

Edited by Vantha
  • Like 1
Link to comment
Share on other sites

Adding more names is an option, removing names ending in a roman number is an option. Not generation an endless list I consider a regression (the engine already supports more than 8 players), tho changing how the list is generated might make a lot of sense. What do you have in mind for how it should work, replace roman numbers with a suffix like (2)?

Link to comment
Share on other sites

I'm in favor of adding new names because for some civs we won't find enough names otherwise.

Yeah, my idea is to modify the way the list created, to first pick each name only once, and when every name has already been chosen pick a random name instead plus suffix showing the count (like (2) ) to avoid two bots with the same name. And as long as each civ has at least 8 different names to choose from, these suffixes won't appear in ordinary 8 player games anyway.

  • Like 2
Link to comment
Share on other sites

Ok, but how many should be hardcoded? (I'll vote for 12 so that probability of repttition in an 8-party match is largely reduced). I also believe that more than 12 parties of the same civ would not be a very frequent setup. 

Additionally, the selection algorithm itself may need modification so that it not just picks a random list entry every time (and counting up the roman numerals if that name was already taken) but only use the remaining set of each civ for random selection. With an increase set and a better randomization this issue should be an extremely rare observation.

Noob opinion :P

  • Like 1
Link to comment
Share on other sites

13 hours ago, Grautvornix said:

Additionally, the selection algorithm itself may need modification so that it not just picks a random list entry every time (and counting up the roman numerals if that name was already taken) but only use the remaining set of each civ for random selection.

Yup, that's the idea. It creates the minimum requirement of 8 different names for each civ. But, of course, adding even more names remains possible. We can add as many suitable names as we can come up with for each civ, to maximize variety.

Link to comment
Share on other sites

1 hour ago, Grautvornix said:

I do agree that historical leaders are preferred. Just in case we cannot come up with enough famous names we should not restrict ourselves and instead add additional "normal" names of that civ/period.

We don't strictly need 8 names, I mean I can play against 3 or maybe 4 before I get badly beaten. So in most games a single name per civ would be already enough. Using made up names would undermine the point made by @Stan` which I quite like. So requiring 8 names doesn't sound that great.

Link to comment
Share on other sites

is this a problem?

one can look up any name, not just the ones belonging to a ruler. anyone having had an attested name is potentially interesting to a curious player. I wonder if there are any civs for which we couldn't come up with 8 names that we know they were given to just anyone minimally interesting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...