Merge lp:~widelands-dev/widelands/ai_for_mods into lp:widelands

Proposed by GunChleoc on 2017-01-22
Status: Merged
Merged at revision: 8255
Proposed branch: lp:~widelands-dev/widelands/ai_for_mods
Merge into: lp:widelands
Diff against target: 76 lines (+11/-38)
2 files modified
src/ai/defaultai.h (+0/-2)
src/ai/defaultai_warfare.cc (+11/-36)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_for_mods
Reviewer Review Type Date Requested Status
TiborB 2017-01-22 Approve on 2017-01-22
Review via email: mp+315311@code.launchpad.net

Commit message

AI calculates military strength based on the actual init.lua files now rather than hard-coding the values. This removed the tribe name restriction for modders.

Description of the change

The values should all be the same as before, except for Barbarian increase_per_level = 850, which was assumed = 700 before.

Also, the values were assigned by = for the Atlanteans, but by += for the other tribes. I went with =, please fix if this is not intended.

Also, all values get / 100, do we still need this, since it's uniform?

To post a comment you must log in.
8246. By GunChleoc on 2017-01-22

clang-format.

TiborB (tiborb95) wrote :

This looks like very smart change!!!, I tested it, seems working OK. the "+=" issue is really a stupid bug.
As for mathematics - I never understood or even care about formulas, but they seems OK to me (when comparing them with the current version in trunk).

review: Approve
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1849. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/194204747.
Appveyor build 1686. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_for_mods-1686.

8247. By GunChleoc on 2017-01-22

Removed superfluous division by 100.

GunChleoc (gunchleoc) wrote :

Actually, the divisions by 100 cancel each other out in

    final += (attack * health) / (defense * evade);

so I have removed them. Less code is good code :)

@bunnybot merge

TiborB (tiborb95) wrote :

My only concern is division of integers and consequent rounding

Dňa ne 22. 1. 2017, 21:52 GunChleoc <email address hidden> napísal(a):

> Actually, the divisions by 100 cancel each other out in
>
> final += (attack * health) / (defense * evade);
>
> so I have removed them. Less code is good code :)
>
> @bunnybot merge
> --
>
> https://code.launchpad.net/~widelands-dev/widelands/ai_for_mods/+merge/315311
> You are reviewing the proposed merge of
> lp:~widelands-dev/widelands/ai_for_mods into lp:widelands.
>

GunChleoc (gunchleoc) wrote :

The only division now is in

    final += (attack * health) / (defense * evade);

and those variables are all float.

8248. By GunChleoc on 2017-01-22

Float division.

GunChleoc (gunchleoc) wrote :

Well, actually found some. This was int before, so an improvement :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai.h'
2--- src/ai/defaultai.h 2016-12-07 22:18:10 +0000
3+++ src/ai/defaultai.h 2017-01-22 21:15:11 +0000
4@@ -94,8 +94,6 @@
5 kAttackableVeryWeak
6 };
7
8- enum class Tribes : uint8_t { kNone, kBarbarians, kAtlanteans, kEmpire };
9-
10 /// Implementation for Strong
11 struct NormalImpl : public ComputerPlayer::Implementation {
12 NormalImpl() {
13
14=== modified file 'src/ai/defaultai_warfare.cc'
15--- src/ai/defaultai_warfare.cc 2017-01-06 09:00:11 +0000
16+++ src/ai/defaultai_warfare.cc 2017-01-22 21:15:11 +0000
17@@ -699,19 +699,6 @@
18 return 0;
19 }
20
21- Tribes tribe = Tribes::kNone;
22-
23- if (soldiers.at(0)->get_owner()->tribe().name() == "atlanteans") {
24- tribe = Tribes::kAtlanteans;
25- } else if (soldiers.at(0)->get_owner()->tribe().name() == "barbarians") {
26- tribe = Tribes::kBarbarians;
27- } else if (soldiers.at(0)->get_owner()->tribe().name() == "empire") {
28- tribe = Tribes::kEmpire;
29- } else {
30- throw wexception("AI warning: Unable to calculate strength for player of tribe %s",
31- soldiers.at(0)->get_owner()->tribe().name().c_str());
32- }
33-
34 float health = 0;
35 float attack = 0;
36 float defense = 0;
37@@ -719,29 +706,17 @@
38 float final = 0;
39
40 for (Soldier* soldier : soldiers) {
41- switch (tribe) {
42- case (Tribes::kAtlanteans):
43- health = 135 + 40 * soldier->get_health_level();
44- attack = 14 + 8 * soldier->get_attack_level();
45- defense = static_cast<float>(94 - 8 * soldier->get_defense_level()) / 100;
46- evade = static_cast<float>(70 - 17 * soldier->get_evade_level()) / 100;
47- break;
48- case (Tribes::kBarbarians):
49- health += 130 + 28 * soldier->get_health_level();
50- attack += 14 + 7 * soldier->get_attack_level();
51- defense += static_cast<float>(97 - 8 * soldier->get_defense_level()) / 100;
52- evade += static_cast<float>(75 - 15 * soldier->get_evade_level()) / 100;
53- break;
54- case (Tribes::kEmpire):
55- health += 130 + 21 * soldier->get_health_level();
56- attack += 14 + 8 * soldier->get_attack_level();
57- defense += static_cast<float>(95 - 8 * soldier->get_defense_level()) / 100;
58- evade += static_cast<float>(70 - 16 * soldier->get_evade_level()) / 100;
59- break;
60- case (Tribes::kNone):
61- NEVER_HERE();
62- }
63-
64+ const SoldierDescr& descr = soldier->descr();
65+ health = descr.get_base_health() +
66+ descr.get_health_incr_per_level() * soldier->get_health_level();
67+ attack = (descr.get_base_max_attack() - descr.get_base_min_attack()) / 2.f +
68+ descr.get_base_min_attack() +
69+ descr.get_attack_incr_per_level() * soldier->get_attack_level();
70+ defense =
71+ 100 - descr.get_base_defense() - 8 * soldier->get_defense_level();
72+ evade =
73+ 100 - descr.get_base_evade() -
74+ descr.get_evade_incr_per_level() / 100.f * soldier->get_evade_level();
75 final += (attack * health) / (defense * evade);
76 }
77