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

Proposed by TiborB
Status: Merged
Merged at revision: 7503
Proposed branch: lp:~widelands-dev/widelands/attack_fix
Merge into: lp:widelands
Diff against target: 73 lines (+21/-6)
1 file modified
src/ai/defaultai.cc (+21/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/attack_fix
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+266796@code.launchpad.net

Description of the change

This is purely (a quick) AI fix of attacking logic:
- visibility of enemy site is checked (there is no "fog of war" for AI so we must check it...)
- changed algorithm to pick random amount of available soldiers for attack (generally AI tent to pick "almost all" available soldiers, now it pick lesser number)

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM - Just one question in the diff comments.

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

I am going to change it - you are right

Revision history for this message
GunChleoc (gunchleoc) wrote :

BTW there is another one: Wh->can_attack() && is_visible

Sorry, I was being lazy.

Revision history for this message
TiborB (tiborb95) wrote :

no, I had to remember it. How to clean it up? Can we reverse trunk? Or commit another revision to trunk?

Revision history for this message
TiborB (tiborb95) wrote :

I fixed it in my branch in the meantime

Revision history for this message
GunChleoc (gunchleoc) wrote :

Since the branch is already pushed and it's a small change, I'd say you can do the change directly on trunk - just make sure that you don't break anything.

Or you can do it in this branch and merge it again.

Revision history for this message
TiborB (tiborb95) wrote :

I will merge my branch to trunk again...

2015-08-03 23:19 GMT+02:00 GunChleoc <email address hidden>:

> Since the branch is already pushed and it's a small change, I'd say you
> can do the change directly on trunk - just make sure that you don't break
> anything.
>
> Or you can do it in this branch and merge it again.
> --
>
> https://code.launchpad.net/~widelands-dev/widelands/attack_fix/+merge/266796
> Your team Widelands Developers is subscribed to branch
> lp:~widelands-dev/widelands/attack_fix.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~widelands-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~widelands-dev
> More help : https://help.launchpad.net/ListHelp
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai.cc'
2--- src/ai/defaultai.cc 2015-07-27 20:25:32 +0000
3+++ src/ai/defaultai.cc 2015-08-03 21:09:23 +0000
4@@ -4893,6 +4893,9 @@
5 uint8_t defenders_strength = 0;
6 bool is_warehouse = false;
7 bool is_attackable = false;
8+ // we cannot attack unvisible site and there is no other way to find out
9+ const bool is_visible = (1 < player_->vision
10+ (Map::get_index(coords_unhash(site->first), map.get_width())));
11 uint16_t owner_number = 100;
12
13 // testing if we can attack the building - result is a flag
14@@ -4900,6 +4903,7 @@
15 FCoords f = map.get_fcoords(coords_unhash(site->first));
16 uint32_t site_to_be_removed = std::numeric_limits<uint32_t>::max();
17 Flag* flag = nullptr;
18+
19 if (upcast(MilitarySite, bld, f.field->get_immovable())) {
20 if (player_->is_hostile(bld->owner())) {
21 std::vector<Soldier *> defenders;
22@@ -4907,7 +4911,7 @@
23 defenders_strength = calculate_strength(defenders);
24
25 flag = &bld->base_flag();
26- if (bld->can_attack()) {
27+ if (is_visible && bld->can_attack()) {
28 is_attackable = true;
29 }
30 owner_number = bld->owner().player_number();
31@@ -4922,7 +4926,7 @@
32
33 flag = &Wh->base_flag();
34 is_warehouse = true;
35- if (Wh->can_attack()) {
36+ if (Wh->can_attack() && is_visible) {
37 is_attackable = true;
38 }
39 owner_number = Wh->owner().player_number();
40@@ -5054,9 +5058,9 @@
41 // attacking
42 FCoords f = map.get_fcoords(coords_unhash(best_target));
43 // setting no attack counter here
44- // this gauranties that it will not be attacked in next 4
45+ // this gauranties that it will not be attacked in next 3
46 // turns
47- enemy_sites[best_target].no_attack_counter = -4;
48+ enemy_sites[best_target].no_attack_counter = -3;
49
50 Flag* flag = nullptr; // flag of a building to be attacked
51 if (upcast(MilitarySite, bld, f.field->get_immovable())) {
52@@ -5069,8 +5073,19 @@
53
54 // how many attack soldiers we can send?
55 uint32_t attackers = player_->find_attack_soldiers(*flag);
56- // Just add some randomness
57- attackers -= gametime % 3;
58+
59+ // Of course not all of them:
60+ // reduce by 0-3 for attackers below 10
61+ // but for soldiers in range 10-40 reduce by much more.
62+ // Soldiers above 40 are ignored for calculation
63+
64+ // Number of soldiers in the range 10-40, random portion of
65+ // them will be used
66+ uint32_t above_ten = (attackers > 10)? attackers - 10 : 0;
67+ above_ten = (above_ten > 30) ? 30 : above_ten;
68+
69+ attackers = attackers - (gametime % 3) - ((above_ten > 0) ? gametime % above_ten : 0);
70+
71 if (attackers <= 0) {
72 return false;
73 }

Subscribers

People subscribed via source and target branches

to status/vote changes: