Skip to content

Commit

Permalink
progressively increasing cost of buying transport cap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jun 30, 2024
1 parent d87d39e commit e8865b5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BuyTransportCapacityPlayerAction(ILog log, int capacity)

protected override (List<int>? ids, int? targetId) ApplyImpl(GameState state)
{
int buyingCost = Ruleset.AssetsRuleset.TransportCapacityBuyingCost(_capacity);
int buyingCost = Ruleset.AssetsRuleset.TransportCapacityBuyingCost(state.Assets.MaxTransportCapacity, _capacity);
Contract.Assert(state.Assets.Money >= buyingCost);
_log.Debug($"Buy transport capacity. Count: {_capacity}. Cost: {buyingCost}");
state.Assets.Money -= buyingCost;
Expand Down
23 changes: 16 additions & 7 deletions src/game-lib/Players/BasicAIPlayerIntellect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using UfoGameLib.Controller;
using UfoGameLib.Lib;
using UfoGameLib.Model;
using UfoGameLib.Ruleset;
using UfoGameLib.State;

namespace UfoGameLib.Players;

public class BasicAIPlayerIntellect : IPlayer
{
private const int MinimumAcceptableAgentSurvivalChance = 20; // percent
private const int MoneyThresholdToBuyTransportCapacity = 600;
private const int MoneyBufferToBuyTransportCapacity = 600;
private readonly ILog _log;

public BasicAIPlayerIntellect(ILog log)
Expand Down Expand Up @@ -37,14 +38,22 @@ public void PlayGameTurn(GameStatePlayerView state, GameTurnController controlle
}

private int ComputeTransportCapacityToBuy(GameStatePlayerView state)
=> state.Assets.Money >= MoneyThresholdToBuyTransportCapacity
// The number of current agents has to be at least the current max transport capacity,
// which is still significantly below full complement.
// There is no point in increasing the transport capacity if we cannot even
// get close to the full complement of agents.
&& state.Assets.Agents.Count >= state.Assets.MaxTransportCapacity
{
int currentMaxCap = state.Assets.MaxTransportCapacity;

int buyingCost = AssetsRuleset.TransportCapacityBuyingCost(currentMaxCap, 1);

// The number of current agents has to be at least the current max transport capacity,
// which is still significantly below full complement.
// There is no point in increasing the transport capacity if we cannot even
// get close to the full complement of agents.
bool moreAgentsThanCurrentMaxCap = state.Assets.Agents.Count > currentMaxCap;
bool enoughMoneyToBuy = state.Assets.Money >= MoneyBufferToBuyTransportCapacity + buyingCost;

return moreAgentsThanCurrentMaxCap && enoughMoneyToBuy
? 1
: 0;
}

private static bool NoMissionsAvailable(GameStatePlayerView state) => !state.MissionSites.Active.Any();

Expand Down
35 changes: 33 additions & 2 deletions src/game-lib/Ruleset/AssetsRuleset.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Lib.Contracts;
using UfoGameLib.Model;

namespace UfoGameLib.Ruleset;
Expand Down Expand Up @@ -42,6 +43,36 @@ public static int ComputeIntelChange(Assets assets, List<Mission> successfulMiss
return intelGathered + intelFromMissions;
}

public static int TransportCapacityBuyingCost(int capacity)
=> capacity * 200;
/// <summary>
/// The way this formula is set up, one gets discount for buying transport capacity in bulk.
///
/// For example, assume:
///
/// maxTransportCap == InitialMaxTransportCapacity
///
/// Now consider:
///
/// Scenario A:
/// Buy 1 price: 200 * 1 = 200
/// Buy 1 price: 250 * 1 = 250
/// Buy 1 price: 300 * 1 = 300
/// Buy 1 price: 350 * 1 = 350
/// Total: 1100 = 200 + 250 + 300 + 350
///
/// Scenario B:
/// Buy 2 price: 200 * 2 = 400
/// Buy 2 price: 300 * 2 = 600
/// Total: 1000 = 400 + 600
///
/// Scenario C:
/// Buy 4 price: 200 * 4 = 800
/// Total: 800 = 800
///
/// </summary>
public static int TransportCapacityBuyingCost(int maxTransportCap, int capacityToBuy)
{
Contract.Assert(maxTransportCap >= InitialMaxTransportCapacity);
Contract.Assert(capacityToBuy >= 1);
return (200 + (50 * (maxTransportCap - InitialMaxTransportCapacity))) * capacityToBuy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export default function ManageTransportCapDialog(
<Label sx={getSx('Cost')}>Capacity increase cost</Label>
</Grid>
<Grid xs={4}>
<Label>{transportCapBuyingCost(1)}</Label>
<Label>
{transportCapBuyingCost(
gameSession.getAssets().MaxTransportCapacity,
1,
)}
</Label>
</Grid>
<Grid xs={12} display="flex" justifyContent="center">
<Button
Expand Down
13 changes: 9 additions & 4 deletions web/src/lib/codesync/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const agentHireCost = 50

const agentTrainingCoefficient = 1

const transportCapBuyCost = 200

const skillFromEachFirstMission = [18, 15, 12, 9, 6]

const skillFromEachMissionBeyondFirstMissions =
Expand Down Expand Up @@ -56,8 +54,15 @@ export function getSurvivalSkill(agent: Agent): number {
)
}

export function transportCapBuyingCost(cap: number): number {
return cap * transportCapBuyCost
const InitialMaxTransportCapacity = 4

export function transportCapBuyingCost(
maxTransportCap: number,
capacityToBuy: number,
): number {
return (
(200 + 50 * (maxTransportCap - InitialMaxTransportCapacity)) * capacityToBuy
)
}

export function canBeSentOnMission(agent: Agent): boolean {
Expand Down
3 changes: 2 additions & 1 deletion web/src/lib/gameSession/GameSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export class GameSession {
return (
this.isInProgress() &&
!this.loading &&
this.getAssets().Money >= transportCapBuyingCost(1)
this.getAssets().Money >=
transportCapBuyingCost(this.getAssets().MaxTransportCapacity, 1)
)
}

Expand Down

0 comments on commit e8865b5

Please sign in to comment.