Skip to content

Commit

Permalink
feat: disband-all-strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Sep 5, 2024
1 parent ab67fe8 commit bab1556
Show file tree
Hide file tree
Showing 29 changed files with 630 additions and 264 deletions.
23 changes: 9 additions & 14 deletions src/main/basedbot/basedbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { connection } from '../../service/sol'
import { keyPair } from '../../service/wallet'

import { getFleetStrategy } from './fleet-strategies/get-fleet-strategy'
import { StrategyConfig } from './fleet-strategies/strategy-config'
import { createInfoStrategy } from './fsm/info'
import { Strategy } from './fsm/strategy'
import { programs } from './lib/programs'
import { createFleet } from './lib/sage/act/create-fleet'
import { depositCargo } from './lib/sage/act/deposit-cargo'
Expand Down Expand Up @@ -44,32 +44,27 @@ export const stop = async (): Promise<void> => {
logger.info('Stopping basedbot')
}

type FleetStrategies = Map<string, Strategy>

type BotConfig = {
player: Player
map: WorldMap
fleetStrategies: FleetStrategies
fleetStrategies: StrategyConfig
}

const applyStrategy = (
fleetInfo: FleetInfo,
fleetStrategies: FleetStrategies,
config: StrategyConfig,
): Promise<void> => {
const strategy = fleetStrategies.get(fleetInfo.fleetName)
const strategy = config.match(fleetInfo.fleetName, config.map)

if (!strategy) {
logger.info(
`No strategy for fleet: ${fleetInfo.fleetName}. Lazily loading Info Strategy...`,
logger.warn(
`No strategy for fleet: ${fleetInfo.fleetName}. Using Info Strategy...`,
)
const infoStrategy = createInfoStrategy()

fleetStrategies.set(fleetInfo.fleetName, infoStrategy)

return infoStrategy.send(fleetInfo)
return createInfoStrategy().apply(fleetInfo)
}

return strategy.send(fleetInfo)
return strategy.apply(fleetInfo)
}

const importR4 = async (player: Player, game: Game): Promise<void> => {
Expand Down Expand Up @@ -124,7 +119,7 @@ const ensureFleets = async (
count: number,
): Promise<void> => {
const existingFleets = fleets.map(getName)
const wantedFleets = Array.from(botConfig.fleetStrategies.keys())
const wantedFleets = Array.from(botConfig.fleetStrategies.map.keys())

const neededFleets = wantedFleets.filter((f) => !existingFleets.includes(f))

Expand Down
18 changes: 12 additions & 6 deletions src/main/basedbot/fleet-strategies/atlasnet-fc-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { Game } from '@staratlas/sage'

import { mine } from '../fsm/configs/mine'
import { mine } from '../fsm/configs/mine/mine'
import { createInfoStrategy } from '../fsm/info'
import { createMiningStrategy } from '../fsm/mine'
import { Strategy } from '../fsm/strategy'
import { Player } from '../lib/sage/state/user-account'
import { WorldMap } from '../lib/sage/state/world-map'
import { galaxySectorsData } from '../lib/util/galaxy-sectors-data'

import { nameMapMatcher } from './name-map-matcher'
import { makeStrategyMap, StrategyConfig, StrategyMap } from './strategy-config'

export const atlasnetFcStrategy =
(count: number) =>
(
map: WorldMap,
player: Player,
game: Game,
namePrefix: string,
): Map<string, Strategy> => {
const ans: Map<string, Strategy> = new Map<string, Strategy>()
): StrategyConfig => {
const strategyMap: StrategyMap = makeStrategyMap()
const sectors = galaxySectorsData()
.filter((sector) => sector.closestFaction === player.faction)
.sort((a, b) => a.name.localeCompare(b.name))

for (let i = 0; i < count; i++) {
ans.set(
strategyMap.set(
`${namePrefix}-${i}`,
createMiningStrategy(
mine(
Expand All @@ -35,5 +38,8 @@ export const atlasnetFcStrategy =
)
}

return ans
return {
match: nameMapMatcher(createInfoStrategy()),
map: strategyMap,
}
}
Loading

0 comments on commit bab1556

Please sign in to comment.