Page MenuHomeWildfire Games

Petra: Send diplomacy requests to other players on occasion
ClosedPublic

Authored by Sandarac on May 23 2017, 8:37 PM.

Details

Summary

On occasion Petra will request to become allies or neutral with other players (regardless if they are an AI or not, and this is done taking into account the current system which allows Petra to respond if a human player changes their diplomacy stance with a bot.

It is important to emphasize that this should not happen often, and that maybe it could be restricted entirely somehow. Currently there will be lapse timer set up to restrict the times when Petra will consider sending a request; when Petra does consider, there is still only a very low purely random chance that it will actually send a request (and this value should be small, exactly how small comes down to a design decision as well, I guess).

The overall system works like:

  • If Petra has more enemies than mutual allies, it may decide to send a request (which may be either ally or neutral) to the player that it has the most mutual enemies with. This will send an event to other AIs, as well as a private chat message (needed for human players). The message will explain that the AI will switch to the chosen diplomacy stance if the other player does so first.
  • If the other player does not respond within some time, then the request will be rescinded.
  • The AI can demand tributes from other AI players in order to accept the offer, and will wait for the other to send them to accept.
  • The sent requests will be reset if the player changes diplomacy
Test Plan

For some thorough testing, the if checking for the this.sentDiplomacyRequestLapseTime can be commented out in the update function of diplomacyManager, and the randBool condition can be removed from that block. This will cause an AI to send requests.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Sandarac created this revision.May 23 2017, 8:37 PM
Sandarac edited the summary of this revision. (Show Details)May 23 2017, 8:40 PM
Sandarac edited the test plan for this revision. (Show Details)
Sandarac added a reviewer: mimo.
Vulcan added a subscriber: Vulcan.May 23 2017, 10:14 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1330/ for more details.

Sandarac edited the summary of this revision. (Show Details)May 24 2017, 2:23 AM
Sandarac updated this revision to Diff 2175.May 24 2017, 5:47 PM

Don't send requests to defeated players, and don't include gaia when determining mutual enemies.

mimo edited edge metadata.May 24 2017, 9:23 PM

I'll review it tomorrow, but in the meantime (and as it is one of the comments i had from a quick look at the patch), could you add some comments in the diplomacy manager explaining what are the differents objects, in particular the difference between this.diplomacyRequests and this.sentDiplomacyRequests and what is the exact role of each one.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1345/ for more details.

Sandarac updated this revision to Diff 2182.May 25 2017, 3:58 PM

Add some more comments to be more clear as to the purpose of the different DiplomacyRequests Maps.

In D544#22311, @mimo wrote:

I'll review it tomorrow, but in the meantime (and as it is one of the comments i had from a quick look at the patch), could you add some comments in the diplomacy manager explaining what are the differents objects, in particular the difference between this.diplomacyRequests and this.sentDiplomacyRequests and what is the exact role of each one.

Indeed now it might be better to rename this.diplomacyRequests to this.receivedDiplomacyRequests in order to differentiate the two.

In sendDiplomacyRequest, let request = this.diplomacyRequests.get(i); is an arbitrary check to see if the other player had ever sent us a diplomacy request before and we had declined.

Right now the patch doesn't factor in things like wonder when deciding to send a request to another player (eventually it could be more likely to send a request to a player who is likely to win soon, like one with a built wonder).

Also right now, AI players demanding tribute from other requesting AI players is kept as simple as possible; as soon as the requested player sends the event demanding a tribute, the original requesting player either sends the tribute or not (there is no lapse timer). If the tribute is sent, it will be handled in the checkEvents function that loops on TributeExchanged.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1351/ for more details.

mimo added a comment.May 25 2017, 6:14 PM

Thanks for the patch. It looks good, although i'm a bit afraid that the logic is becoming quite complex (and difficult to extend in the future).

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
204 ↗(On Diff #2182)

I now wonder why we didn't check (requestType=ally && !isAlly) || (requestType=neutral && !isNeutral) as above?
Could be in a following patch, with renaming of this.diplomacyRequests to this.receivedDiplomacyRequests

232 ↗(On Diff #2182)

repsonce -> response

252 ↗(On Diff #2182)

252 and 253 could be moved after 256

259 ↗(On Diff #2182)

We could increase this.nextTributeUpdate by some amount when sending such a tribute (mainly to avoid sending a usual tribute on the same turn, as availableResources won't be updated).

478 ↗(On Diff #2182)

you seem to allow a request enemy->ally in the sentRequest, but this case is not dealt with by the AI who will respond by suggesting to go neutral first. So why not
let requestType = gameState.isPlayerNeutral(player) ? "ally" : "neutral";

Sandarac updated this revision to Diff 2186.May 25 2017, 7:27 PM

Fix comments.

In D544#22420, @mimo wrote:

Thanks for the patch. It looks good, although i'm a bit afraid that the logic is becoming quite complex (and difficult to extend in the future).

:( Well, I believe the paragraphs written at the top of the file are quite thorough; if you are partly referring to the TributeRequests part, I certainly don't think that will be extended too much. The important thing is that in each diplomacyrequests map, each player can only occur once (and thus contains the complexity).

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
204 ↗(On Diff #2182)

Yes, I believe this can be done in a cleanup for the diplomacyManager.

232 ↗(On Diff #2182)

Okay.

252 ↗(On Diff #2182)

Okay.

259 ↗(On Diff #2182)

Yes, done.

mimo accepted this revision.May 25 2017, 7:53 PM
This revision is now accepted and ready to land.May 25 2017, 7:53 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1353/ for more details.

This revision was automatically updated to reflect the committed changes.