Skip to content

Commit

Permalink
Add optional playing strength descriptions for AIs
Browse files Browse the repository at this point in the history
* support the following numerical keys in JSON files for AIs:
  * "wins"
  * "losses"
  * "draws" (games without a winner after several hours of game time)

* keys contain data about playing strength of AIs relative to eath other

* if at least one key value is non-zero, calculate percentages and print
  these data in an extra line of AI tooltips with some translatable text

* fill out key values for NullBot and SemperFi JavaScript, based on an
  AI tournament by EuPhobos (forum username: Prot) from 23 October 2018,
  when its results were archived at https://archive.fo/QtSjR

Fixes Warzone2100#419
  • Loading branch information
Forgon2100 committed Jul 4, 2019
1 parent 3bee689 commit 8485d7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion data/mp/multiplay/skirmish/nb_generic.json
Expand Up @@ -4,6 +4,9 @@
"name": "NullBot", "name": "NullBot",
"tip": "Adaptive AI with multiple personalities", "tip": "Adaptive AI with multiple personalities",
"easy_tip": "Gets ~ 25% less power from each oil derrick\nResearch is not focused on a specific weapon branch", "easy_tip": "Gets ~ 25% less power from each oil derrick\nResearch is not focused on a specific weapon branch",
"insane_tip": "Gets ~ 100% more power from each oil derrick\nStarts with defensive structures and oil derricks" "insane_tip": "Gets ~ 100% more power from each oil derrick\nStarts with defensive structures and oil derricks",
"wins": 18927,
"losses": 12773,
"draws": 261
} }
} }
5 changes: 4 additions & 1 deletion data/mp/multiplay/skirmish/semperfi-js.json
Expand Up @@ -4,6 +4,9 @@
"name": "SemperFi JavaScript", "name": "SemperFi JavaScript",
"tip": "Prototypical JavaScript AI focusing on rockets/missiles", "tip": "Prototypical JavaScript AI focusing on rockets/missiles",
"easy_tip": "Gets ~ 25% less power from each oil derrick", "easy_tip": "Gets ~ 25% less power from each oil derrick",
"insane_tip": "Gets ~ 100% more power from each oil derrick\nStarts with defensive structures and oil derricks" "insane_tip": "Gets ~ 100% more power from each oil derrick\nStarts with defensive structures and oil derricks",
"wins": 1806,
"losses": 2355,
"draws": 23
} }
} }
17 changes: 16 additions & 1 deletion src/multiint.cpp
Expand Up @@ -275,7 +275,7 @@ struct AIDATA
char slo[MAX_LEN_AI_NAME]; char slo[MAX_LEN_AI_NAME];
char vlo[MAX_LEN_AI_NAME]; char vlo[MAX_LEN_AI_NAME];
char js[MAX_LEN_AI_NAME]; char js[MAX_LEN_AI_NAME];
char tip[255]; char tip[255 + 128]; // may contain optional AI tournament data
char difficultyTips[4][255]; // optional difficulty level info char difficultyTips[4][255]; // optional difficulty level info
int assigned; ///< How many AIs have we assigned of this type int assigned; ///< How many AIs have we assigned of this type
}; };
Expand Down Expand Up @@ -811,6 +811,21 @@ void readAIs()
sstrcpy(ai.tip, _("MISSING AI DESCRIPTION")); sstrcpy(ai.tip, _("MISSING AI DESCRIPTION"));
} }


int wins = aiconf.value("wins", 0).toInt();
int losses = aiconf.value("losses", 0).toInt();
int draws = aiconf.value("draws", 0).toInt();
int total = wins + losses + draws;
if (total)
{
float win_percentage = static_cast<float>(wins) / total * 100;
float loss_percentage = static_cast<float>(losses) / total * 100;
float draw_percentage = static_cast<float>(draws) / total * 100;
sstrcat(ai.tip, "\n");
char statistics[127];
ssprintf(statistics, _("AI tournament: %3.1f%% wins, %3.1f%% losses, %3.1f%% draws"), win_percentage, loss_percentage, draw_percentage);
sstrcat(ai.tip, statistics);
}

if (strcmp(*i, "nb_generic.json") == 0) if (strcmp(*i, "nb_generic.json") == 0)
{ {
aidata.insert(aidata.begin(), ai); aidata.insert(aidata.begin(), ai);
Expand Down

0 comments on commit 8485d7d

Please sign in to comment.