priortize ally ports and close ports (#335)

2x more likely to trade with ports belonging to an ally OR close.
3x more likely to trade with ports belonging to an ally AND close.
Add trading tests
This commit is contained in:
Ilan Schemoul
2025-03-27 16:09:58 -07:00
committed by GitHub
parent 665a8c3823
commit f2193edc7c
8 changed files with 102 additions and 22 deletions
+34
View File
@@ -953,4 +953,38 @@ export class PlayerImpl implements Player {
return false;
}
}
// It's a probability list, so if an element appears twice it's because it's
// twice more likely to be picked later.
tradingPorts(port: Unit): Unit[] {
let ports = this.mg
.players()
.filter((p) => p != port.owner() && p.canTrade(port.owner()))
.flatMap((p) => p.units(UnitType.Port))
.sort((p1, p2) => {
return (
this.mg.manhattanDist(port.tile(), p1.tile()) -
this.mg.manhattanDist(port.tile(), p2.tile())
);
});
// Make close ports twice more likely by putting them again
for (
let i = 0;
i < this.mg.config().proximityBonusPortsNb(ports.length);
i++
) {
ports.push(ports[i]);
}
// Make ally ports twice more likely by putting them again
this.mg
.players()
.filter((p) => p != port.owner() && p.canTrade(port.owner()))
.filter((p) => p.isAlliedWith(port.owner()))
.flatMap((p) => p.units(UnitType.Port))
.forEach((p) => ports.push(p));
return ports;
}
}