Skip to content

Commit

Permalink
Use guessShipType in fleet_value
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Mar 21, 2024
1 parent 13fd96e commit 28908ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 13 additions & 12 deletions packages/cli/bin/fleet_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Map<ShipType, int> _shipTypeCounts(
) {
final typeCounts = <ShipType, int>{};
for (final ship in ships) {
final type = shipyardShips.shipTypeFromFrame(ship.frame.symbol)!;
final type = guessShipType(shipyardShips, ship)!;
typeCounts[type] = (typeCounts[type] ?? 0) + 1;
}
return typeCounts;
Expand All @@ -40,24 +40,25 @@ Future<void> command(FileSystem fs, Database db, ArgResults argResults) async {
final shipyardPrices = await ShipyardPriceSnapshot.load(db);
final shipyardShips = ShipyardShipCache.load(fs);

logger
..info('Estimating fleet value at current median prices.')
..info('Excluding initial ships.');
logger.info('Estimating fleet value at current median prices.');

final purchasedShips = ships.ships.skip(2).toList();
final purchaseShipTypes = purchasedShips
.map((s) => shipyardShips.shipTypeFromFrame(s.frame.symbol)!)
.toList();
// Include all ships now that scrapping is a thing.
final purchasedShips = ships.ships;
final purchaseShipTypes =
purchasedShips.map((s) => guessShipType(shipyardShips, s)!).toList();
final purchaseShipTypeCounts = _shipTypeCounts(shipyardShips, purchasedShips);
final shipTypes = purchaseShipTypeCounts.keys.toList()
..sortBy((t) => t.value);
for (final type in shipTypes) {
logger.info('${purchaseShipTypeCounts[type]} $type @ '
'${creditsString(shipyardPrices.medianPurchasePrice(type)!)}');
final price = shipyardPrices.medianPurchasePrice(type);
final priceString = price == null ? '???' : creditsString(price);
logger.info('${purchaseShipTypeCounts[type]} $type @ $priceString each');
}

final totalShipCost =
purchaseShipTypes.map((t) => shipyardPrices.medianPurchasePrice(t)!).sum;
// Purchase price != scrapping price, so this is wrong.
final totalShipCost = purchaseShipTypes
.map((t) => shipyardPrices.medianPurchasePrice(t) ?? 0)
.sum;
logger.info('Ships: ${creditsString(totalShipCost)}');

// Mount costs
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class Config {
for (int i = 0; i < 2; i++) ShipType.REFINING_FREIGHTER,
for (int i = 0; i < 5; i++) ShipType.PROBE,
for (int i = 0; i < 15; i++) ShipType.PROBE,
for (int i = 0; i < 10; i++) ShipType.REFINING_FREIGHTER,
// Only buy more when we have enough cash on hand to support trading?
for (int i = 0; i < 15; i++) ShipType.REFINING_FREIGHTER,
];

/// Our ship buy plan for computeNextShipToBuy.
Expand Down

0 comments on commit 28908ea

Please sign in to comment.