Merge lp:~widelands-dev/widelands/prevent_ai_deadlocks into lp:widelands/build19

Proposed by GunChleoc
Status: Rejected
Rejected by: GunChleoc
Proposed branch: lp:~widelands-dev/widelands/prevent_ai_deadlocks
Merge into: lp:widelands/build19
Diff against target: 254 lines (+112/-5)
9 files modified
data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua (+6/-0)
data/tribes/scripting/starting_conditions/atlanteans/headquarters.lua (+6/-0)
data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua (+5/-0)
data/tribes/scripting/starting_conditions/barbarians/headquarters.lua (+5/-0)
data/tribes/scripting/starting_conditions/empire/fortified_village.lua (+5/-0)
data/tribes/scripting/starting_conditions/empire/headquarters.lua (+5/-0)
data/tribes/scripting/starting_conditions/prevent_deadlocks.lua (+55/-0)
src/scripting/lua_game.cc (+24/-5)
src/scripting/lua_game.h (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/prevent_ai_deadlocks
Reviewer Review Type Date Requested Status
SirVer Disapprove
Tino Disapprove
Review via email: mp+309727@code.launchpad.net

Commit message

Added function to starting conditions to make sure that the AI never runs out of basic building materials in order to prevent deadlocks.

Description of the change

Deadlocks with log production have been reported on the forum by multiple users. Rather than messing with the AI code and potentially messing up something else, I have added a script to the starting conditions that will supply all wares that can cause deadlocks - same trick as used by Trading Outpost. The wares supplied are log and granite for all tribes, marble for Empire and spidercloth for Atlanteans. Let me know if I forgot any.

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

I strongly disagree. This is a step to slippery slope - once you get there we might never stop adding some cheatings to help AI. Moreover we already have cheating mode - Trading post.

As I understand all that is needed is to add more logs for atlanteans when starting in village mode. Somehow this setup was not tested and obviously almost nobody is using this...

We spend a lot of time and effort to make AI not deadlock on start, and this make me feel bad...

Revision history for this message
GunChleoc (gunchleoc) wrote :

I am in favor of merging this into B19 but NOT into trunk. Would that be OK for you?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1549. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/172218875.
Appveyor build 1390. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_prevent_ai_deadlocks-1390.

Revision history for this message
kaputtnik (franku) wrote :

I think Tibor is right.

Even if there are posts in the forum we have no bugreprot for this issue. And from my point of view bug reports are the things to go.

The mentioned failure isn't such a show stopper as some users meant it is and it's quite worth for working on if there is no bug report.

Don't know how invasive the following suggestion is: Just prevent the possibility of setting "fortified village" if the Player is AI. A dirty short-time fix only for build19rc then.

Revision history for this message
Tino (tino79) wrote :

I also strongly oppose merging this to b19.

I've added a bug report here: https://bugs.launchpad.net/widelands/+bug/1638260

Adding some more logs to the warehouse for fortified villages would be my way to go.

review: Disapprove
Revision history for this message
GunChleoc (gunchleoc) wrote :

+1 for adding logs. How many do you think we need?

Revision history for this message
SirVer (sirver) wrote :

In my memory deadlocking AI was the norm in b17 and very frequent in b18. That people complain about it happening now in places is a sign that this has changed - which is a testament to Tibor's work! Great job!

I think this is not such a big deal as people make it out to be. The AI deadlocks sometimes - so what? The ship's transportation logic and the soldier's fighting bugs are at least as annoying in game, but there is no vocal voice complaining about it. There is also a starting condition specifically meant to help out the AI - so players can actually do something about it themselves.

Adding a logic change at this point in the release cycle means that if this goes in, we need another RC - and rigorous testing for at least 3 weeks or so - and a special call out to the community to test this specific change. If we add a breaking bug in here we are stuck with it for years. Even if we release b20 earlier than our usual 2 years, linux distributions will not update LTS releases and people will complain about it.

Just increasing the logs seems less risky but as mentioned multiple times seemingly simple changes have broken us in the past. I would not do that too - and if we do, it still warrants the extra testing in a rc2.

I think this is not worth it, but I will not block if that is what you want to do.

review: Disapprove
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for adding your experience to the issue. I'll be OK with not having it for Build 19.

@Tibor: Don't feel bad, it's not your fault that nobody noticed until now! Listen to SirVer's well-deserved praise instead :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua'
2--- data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua 2016-03-30 07:23:59 +0000
3+++ data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua 2016-11-01 07:24:37 +0000
4@@ -3,6 +3,7 @@
5 -- =======================================================================
6
7 include "scripting/infrastructure.lua"
8+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
9
10 set_textdomain("tribes")
11
12@@ -99,5 +100,10 @@
13 place_building_in_region(plr, "atlanteans_sawmill", sf:region(11), {
14 wares = { log = 1 }
15 })
16+
17+ if plr.ai ~= "" then
18+ print("Player #" .. plr.number .. " is an AI")
19+ prevent_deadlocks(plr)
20+ end
21 end
22 }
23
24=== modified file 'data/tribes/scripting/starting_conditions/atlanteans/headquarters.lua'
25--- data/tribes/scripting/starting_conditions/atlanteans/headquarters.lua 2016-03-30 07:23:59 +0000
26+++ data/tribes/scripting/starting_conditions/atlanteans/headquarters.lua 2016-11-01 07:24:37 +0000
27@@ -3,6 +3,7 @@
28 -- =======================================================================
29
30 include "scripting/infrastructure.lua"
31+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
32
33 set_textdomain("tribes")
34
35@@ -79,6 +80,11 @@
36 [{0,0,0,0}] = 35,
37 }
38 })
39+
40+ if plr.ai ~= "" then
41+ print("Player #" .. plr.number .. " is an AI")
42+ prevent_deadlocks(plr)
43+ end
44 end
45 }
46
47
48=== modified file 'data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua'
49--- data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua 2016-03-30 07:23:59 +0000
50+++ data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua 2016-11-01 07:24:37 +0000
51@@ -3,6 +3,7 @@
52 -- =======================================================================
53
54 include "scripting/infrastructure.lua"
55+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
56
57 set_textdomain("tribes")
58
59@@ -92,5 +93,9 @@
60 place_building_in_region(plr, "barbarians_lime_kiln", sf:region(12), {
61 wares = { granite = 6, coal = 3 },
62 })
63+ if plr.ai ~= "" then
64+ print("Player #" .. plr.number .. " is an AI")
65+ prevent_deadlocks(plr)
66+ end
67 end
68 }
69
70=== modified file 'data/tribes/scripting/starting_conditions/barbarians/headquarters.lua'
71--- data/tribes/scripting/starting_conditions/barbarians/headquarters.lua 2016-03-30 07:23:59 +0000
72+++ data/tribes/scripting/starting_conditions/barbarians/headquarters.lua 2016-11-01 07:24:37 +0000
73@@ -3,6 +3,7 @@
74 -- =======================================================================
75
76 include "scripting/infrastructure.lua"
77+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
78
79 set_textdomain("tribes")
80
81@@ -70,6 +71,10 @@
82 [{0,0,0,0}] = 45,
83 }
84 })
85+ if player.ai ~= "" then
86+ print("Player #" .. player.number .. " is an AI")
87+ prevent_deadlocks(player)
88+ end
89 end
90 }
91
92
93=== modified file 'data/tribes/scripting/starting_conditions/empire/fortified_village.lua'
94--- data/tribes/scripting/starting_conditions/empire/fortified_village.lua 2016-03-30 07:23:59 +0000
95+++ data/tribes/scripting/starting_conditions/empire/fortified_village.lua 2016-11-01 07:24:37 +0000
96@@ -3,6 +3,7 @@
97 -- =======================================================================
98
99 include "scripting/infrastructure.lua"
100+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
101
102 set_textdomain("tribes")
103
104@@ -117,5 +118,9 @@
105 })
106
107 place_building_in_region(plr, "empire_stonemasons_house", sf:region(11))
108+ if plr.ai ~= "" then
109+ print("Player #" .. plr.number .. " is an AI")
110+ prevent_deadlocks(plr)
111+ end
112 end
113 }
114
115=== modified file 'data/tribes/scripting/starting_conditions/empire/headquarters.lua'
116--- data/tribes/scripting/starting_conditions/empire/headquarters.lua 2016-03-30 07:23:59 +0000
117+++ data/tribes/scripting/starting_conditions/empire/headquarters.lua 2016-11-01 07:24:37 +0000
118@@ -3,6 +3,7 @@
119 -- =======================================================================
120
121 include "scripting/infrastructure.lua"
122+include "tribes/scripting/starting_conditions/prevent_deadlocks.lua"
123
124 set_textdomain("tribes")
125
126@@ -77,5 +78,9 @@
127 [{0,0,0,0}] = 45,
128 }
129 })
130+ if p.ai ~= "" then
131+ print("Player #" .. p.number .. " is an AI")
132+ prevent_deadlocks(p)
133+ end
134 end
135 }
136
137=== added file 'data/tribes/scripting/starting_conditions/prevent_deadlocks.lua'
138--- data/tribes/scripting/starting_conditions/prevent_deadlocks.lua 1970-01-01 00:00:00 +0000
139+++ data/tribes/scripting/starting_conditions/prevent_deadlocks.lua 2016-11-01 07:24:37 +0000
140@@ -0,0 +1,55 @@
141+include "scripting/infrastructure.lua"
142+
143+function prevent_deadlocks(player)
144+ -- Get all warehouse types
145+ local warehouse_types = {}
146+ for i, building in ipairs(wl.Game():get_tribe_description(player.tribe_name).buildings) do
147+ if (building.type_name == "warehouse") then
148+ table.insert(warehouse_types, building.name)
149+ end
150+ end
151+
152+ -- index of a warehouse we will add to. Used to 'rotate' warehouses
153+ local idx = 1
154+
155+ for i=1,100000 do
156+ sleep(300000)
157+
158+ -- collect all ~warehouses and pick one to insert the wares
159+ local warehouses = {}
160+ for i, building_name in ipairs(warehouse_types) do
161+ warehouses = array_combine(warehouses, player:get_buildings(building_name))
162+ end
163+
164+ if #warehouses > 0 then
165+ -- adding to a warehouse with index idx, if out of range, adding to wh 1
166+ if idx > #warehouses then
167+ idx = 1
168+ end
169+
170+ local wh = warehouses[idx]
171+ local added = 0
172+
173+ if wh:get_wares("log") < 1 then
174+ wh:set_wares("log", wh:get_wares("log") + 20)
175+ added = added + 1
176+ end
177+ if wh:get_wares("granite") < 1 then
178+ wh:set_wares("granite", wh:get_wares("granite") + 10)
179+ added = added + 1
180+ end
181+ if player.tribe_name == "empire" and wh:get_wares("marble") < 1 then
182+ wh:set_wares("marble", wh:get_wares("marble") + 10)
183+ added = added + 1
184+ end
185+ if player.tribe_name == "atlanteans" and wh:get_wares("spidercloth") < 1 then
186+ wh:set_wares("spidercloth", wh:get_wares("spidercloth") + 10)
187+ added = added + 1
188+ end
189+ if (added > 0) then
190+ print (player.number..": "..added.." types of ware added to warehouse "..idx.." of "..#warehouses.." (to prevent deadlock)")
191+ end
192+ end
193+ idx = idx + 1
194+ end
195+end
196
197=== modified file 'src/scripting/lua_game.cc'
198--- src/scripting/lua_game.cc 2016-08-07 20:39:44 +0000
199+++ src/scripting/lua_game.cc 2016-11-01 07:24:37 +0000
200@@ -103,11 +103,17 @@
201 {nullptr, nullptr},
202 };
203 const PropertyType<LuaPlayer> LuaPlayer::Properties[] = {
204- PROP_RO(LuaPlayer, name), PROP_RO(LuaPlayer, allowed_buildings),
205- PROP_RO(LuaPlayer, objectives), PROP_RO(LuaPlayer, defeated),
206- PROP_RO(LuaPlayer, messages), PROP_RO(LuaPlayer, inbox),
207- PROP_RW(LuaPlayer, team), PROP_RO(LuaPlayer, tribe),
208- PROP_RW(LuaPlayer, see_all), {nullptr, nullptr, nullptr},
209+ PROP_RO(LuaPlayer, ai),
210+ PROP_RO(LuaPlayer, name),
211+ PROP_RO(LuaPlayer, allowed_buildings),
212+ PROP_RO(LuaPlayer, objectives),
213+ PROP_RO(LuaPlayer, defeated),
214+ PROP_RO(LuaPlayer, messages),
215+ PROP_RO(LuaPlayer, inbox),
216+ PROP_RW(LuaPlayer, team),
217+ PROP_RO(LuaPlayer, tribe),
218+ PROP_RW(LuaPlayer, see_all),
219+ {nullptr, nullptr, nullptr},
220 };
221
222 /*
223@@ -115,6 +121,19 @@
224 PROPERTIES
225 ==========================================================
226 */
227+
228+/* RST
229+ .. attribute:: ai
230+
231+ (RO) The ai name of this Player if it is an ai, an empty string otherwise.
232+*/
233+int LuaPlayer::get_ai(lua_State* L) {
234+ Game& game = get_game(L);
235+ Player& p = get(L, game);
236+ lua_pushstring(L, p.get_ai());
237+ return 1;
238+}
239+
240 /* RST
241 .. attribute:: name
242
243
244=== modified file 'src/scripting/lua_game.h'
245--- src/scripting/lua_game.h 2016-08-04 15:49:05 +0000
246+++ src/scripting/lua_game.h 2016-11-01 07:24:37 +0000
247@@ -65,6 +65,7 @@
248 /*
249 * Properties
250 */
251+ int get_ai(lua_State* L);
252 int get_name(lua_State* L);
253 int get_allowed_buildings(lua_State* L);
254 int get_objectives(lua_State* L);

Subscribers

People subscribed via source and target branches

to all changes: