mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 01:18:01 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user