patchFreeciv - Patches: patch #4378, Minimize the gold clause when...

Show feedback again

patch #4378: Minimize the gold clause when exchanging technologies

Submitted by:  Guillaume Melquiond <silene>
Submitted on:  Tue Dec 31 14:20:26 2013  
Category: aiPriority: 5 - Normal
Status: In ProgressPrivacy: Public
Assigned to: NoneOpen/Closed: Open
Planned Release: 2.6.0Contains string changes: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


Sat Jan 11 05:56:05 2014, comment #3:

../../../../src.patched/ai/default/advdiplomacy.c: In function 'dai_share':
../../../../src.patched/ai/default/advdiplomacy.c:1118:26: error: 'tech_p2' may be used uninitialized in this function [-Werror=maybe-uninitialized]
dai_diplomacy_suggest(player1, player2, CLAUSE_ADVANCE, tech_p2);
../../../../src.patched/ai/default/advdiplomacy.c:1056:34: note: 'tech_p2' was declared here
Tech_type_id tech_p1 = A_NONE, tech_p2;
../../../../src.patched/ai/default/advdiplomacy.c:1112:40: error: 'best_diff' may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (tech_p1 != A_NONE && best_diff == 0) {
../../../../src.patched/ai/default/advdiplomacy.c:1055:7: note: 'best_diff' was declared here
int best_diff;

Marko Lindqvist <cazfi>
Project Administrator
Fri Jan 3 05:25:04 2014, comment #2:

Good catch. It wasn't initialized on purpose (no sane default, except perhaps the largest integer), but it was meant to be protected by a check on tech_p1, which is initialized. The check somehow got lost when removing all the debugging cruft to prepare the final version of the patch. Here is a corrected version.

(file #19632)

Guillaume Melquiond <silene>
Thu Jan 2 23:36:58 2014, comment #1:

Where is best_diff initialized before used first time in abs(diff) < abs(best_diff) condition?

Marko Lindqvist <cazfi>
Project Administrator
Tue Dec 31 14:20:26 2013, original submission:

In ai/default/advdiplomacy.c:suggest_tech_exchange, the AI computes how much the technologies of both players are worth. It then suggests the first two technologies such that the difference of their worth, once converted to gold, can be paid by the players. Notice I just said "first".

As a consequence, the AI sometimes suggests really dumb treaties. (No, I won't pay 300 gold and one of my technologies, for some technology I can research in just two turns! [1]) This patch alleviates the issue by not stopping at the first two technologies. Instead, it suggests the technology exchange that minimizes the gold clause.

That way, the subjectivity of how much a technology is worth as gold no longer matters: the treaties seem much more sensible when the AI asks for tens of gold only rather than hundreds.

And just so that there is no misunderstanding, I do not change the way technologies are evaluated, just the way they are selected. For instance, if only one treaty was possible before the patch, this is the treaty that will be suggested after the patch.

[1] This may indicate a bug in the function used to evaluate how much the technologies are worth. Still, I think the patch is relevant, even if this hypothetical bug were to be fixed.

Guillaume Melquiond <silene>


(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #19632:  tech_exchange.patch added by silene (2kB - text/x-patch)
file #19585:  tech_exchange.patch added by silene (2kB - text/x-patch)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by cazfi (Posted a comment)
  • -unavailable- added by silene (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon May 12 20:24:27 2014cazfiAssigned tocazfi=>None
    Sat Jan 11 05:56:05 2014cazfiStatusReady For Test=>In Progress
    Sun Jan 5 05:36:47 2014cazfiStatusNone=>Ready For Test
      Assigned toNone=>cazfi
      Planned Release=>2.6.0
    Fri Jan 3 05:25:04 2014sileneAttached File-=>Added tech_exchange.patch, #19632
    Tue Dec 31 14:20:26 2013sileneAttached File-=>Added tech_exchange.patch, #19585
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup