Skip to content

Commit

Permalink
chore: separate fleet strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Sep 2, 2024
1 parent f1ec23c commit 99e9384
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 201 deletions.
207 changes: 7 additions & 200 deletions src/main/basedbot/basedbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@ import BN from 'bn.js'

import { Sentry } from '../../sentry'

import { config } from '../../config'
import { logger } from '../../logger'
import { sleep } from '../../service/sleep'
import { connection } from '../../service/sol'
import { keyPair } from '../../service/wallet'

import { mineBiomass } from './fsm/configs/mine-biomass'
import { mineCarbon } from './fsm/configs/mine-carbon'
import { mineConfig } from './fsm/configs/mine-config'
import { mineCopperOre } from './fsm/configs/mine-copper-ore'
import { mineHydrogen } from './fsm/configs/mine-hydrogen'
import { mineIronOre } from './fsm/configs/mine-iron-ore'
import { mineLumanite } from './fsm/configs/mine-lumanite'
import { mineNitrogen } from './fsm/configs/mine-nitrogen'
import { mineRochinol } from './fsm/configs/mine-rochinol'
import { mineSilicia } from './fsm/configs/mine-silicia'
import { mineTitaniumOre } from './fsm/configs/mine-titanium-ore'
import { getFleetStrategy } from './fleet-strategies/get-fleet-strategy'
import { createInfoStrategy } from './fsm/info'
import { createMiningStrategy } from './fsm/mine'
import { Strategy } from './fsm/strategy'
import { depositCargo } from './lib/sage/act/deposit-cargo'
import { settleFleet } from './lib/sage/state/settle-fleet'
Expand All @@ -35,13 +23,8 @@ import {
getFleetInfo,
getUserFleets,
} from './lib/sage/state/user-fleets'
import {
getMapContext,
mineableByCoordinates,
WorldMap,
} from './lib/sage/state/world-map'
import { getMapContext, WorldMap } from './lib/sage/state/world-map'
// eslint-disable-next-line import/max-dependencies
import { Coordinates } from './lib/util/coordinates'

// eslint-disable-next-line require-await
export const create = async (): Promise<void> => {
Expand Down Expand Up @@ -152,190 +135,14 @@ export const start = async (): Promise<void> => {
const player = await getPlayerContext(keyPair.publicKey, keyPair)
const map = await getMapContext(player.game)

const fleetStrategies: Map<string, Strategy> =
config.sol.rpcEndpoint.includes('atlasnet')
? new Map([
[
'Armadillo Fleet',
createMiningStrategy(mineBiomass(map), player),
],
[
'Barnacle Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-19, 40),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-19, 40),
)
.values()
.next().value,
}),
player,
),
],
[
'Cobra Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-18, 23),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-18, 23),
)
.values()
.next().value,
}),
player,
),
],
[
'Falcon Fleet',
createMiningStrategy(mineCarbon(map), player),
],
[
'Geoffroys Cat Fleet',
createMiningStrategy(mineNitrogen(map), player),
],
[
'Gerbils Fleet',
createMiningStrategy(mineSilicia(map), player),
],
[
'Grasshopper Fleet',
createMiningStrategy(mineLumanite(map), player),
],
[
'Guanaco Fleet',
createMiningStrategy(mineCopperOre(map), player),
],
[
'King Cobra Fleet',
createMiningStrategy(mineIronOre(map), player),
],
[
'Pacific Sardine Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
[
'Porpoise Fleet',
createMiningStrategy(mineRochinol(map), player),
],
[
'Rabbit Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
[
'Smalltooth Sawfish Fleet',
createMiningStrategy(mineTitaniumOre(map), player),
],
[
'Sugar Gliders Fleet',
createMiningStrategy(mineIronOre(map), player),
],
[
'Turkey Fleet',
createMiningStrategy(mineHydrogen(map), player),
],

[
'Aardwolf Fleet',
createMiningStrategy(mineBiomass(map), player),
],
[
'Antelope Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-19, 40),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-19, 40),
)
.values()
.next().value,
}),
player,
),
],
[
'Boa Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-18, 23),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-18, 23),
)
.values()
.next().value,
}),
player,
),
],
[
'Chinchillas Fleet',
createMiningStrategy(mineCarbon(map), player),
],
[
'Fathead Sculpin Fleet',
createMiningStrategy(mineNitrogen(map), player),
],
[
'Giant Tortoise Fleet',
createMiningStrategy(mineSilicia(map), player),
],
[
'Kultarr Fleet',
createMiningStrategy(mineLumanite(map), player),
],
[
'Leopard Seal Fleet',
createMiningStrategy(mineCopperOre(map), player),
],
[
'Pangolin Fleet',
createMiningStrategy(mineIronOre(map), player),
],
[
'Rhinoceros Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
[
'Snow Leopard Fleet',
createMiningStrategy(mineRochinol(map), player),
],
[
'Southern White Faced Owl Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
[
'Turkeys Fleet',
createMiningStrategy(mineTitaniumOre(map), player),
],
[
'Zebra Fleet',
createMiningStrategy(mineIronOre(map), player),
],
[
'Guinea Fowl Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
])
: new Map([
[
'Vaquita Fleet',
createMiningStrategy(mineRochinol(map), player),
],
])

// eslint-disable-next-line no-constant-condition
while (true) {
try {
await basedbot({ player, map, fleetStrategies })
await basedbot({
player,
map,
fleetStrategies: getFleetStrategy(map, player),
})
} catch (e) {
Sentry.captureException(e)
logger.error(e)
Expand Down
135 changes: 135 additions & 0 deletions src/main/basedbot/fleet-strategies/atlasnet-lu-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { mineBiomass } from '../fsm/configs/mine-biomass'
import { mineCarbon } from '../fsm/configs/mine-carbon'
import { mineConfig } from '../fsm/configs/mine-config'
import { mineCopperOre } from '../fsm/configs/mine-copper-ore'
import { mineHydrogen } from '../fsm/configs/mine-hydrogen'
import { mineIronOre } from '../fsm/configs/mine-iron-ore'
import { mineLumanite } from '../fsm/configs/mine-lumanite'
import { mineNitrogen } from '../fsm/configs/mine-nitrogen'
import { mineRochinol } from '../fsm/configs/mine-rochinol'
import { mineSilicia } from '../fsm/configs/mine-silicia'
import { mineTitaniumOre } from '../fsm/configs/mine-titanium-ore'
import { createMiningStrategy } from '../fsm/mine'
import { Strategy } from '../fsm/strategy'
import { Player } from '../lib/sage/state/user-account'
import { mineableByCoordinates, WorldMap } from '../lib/sage/state/world-map'
import { Coordinates } from '../lib/util/coordinates'

export const atlasnetLuStrategy = (
map: WorldMap,
player: Player,
): Map<string, Strategy> =>
new Map([
['Armadillo Fleet', createMiningStrategy(mineBiomass(map), player)],
[
'Barnacle Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-19, 40),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-19, 40),
)
.values()
.next().value,
}),
player,
),
],
[
'Cobra Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-18, 23),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-18, 23),
)
.values()
.next().value,
}),
player,
),
],
['Falcon Fleet', createMiningStrategy(mineCarbon(map), player)],
[
'Geoffroys Cat Fleet',
createMiningStrategy(mineNitrogen(map), player),
],
['Gerbils Fleet', createMiningStrategy(mineSilicia(map), player)],
['Grasshopper Fleet', createMiningStrategy(mineLumanite(map), player)],
['Guanaco Fleet', createMiningStrategy(mineCopperOre(map), player)],
['King Cobra Fleet', createMiningStrategy(mineIronOre(map), player)],
[
'Pacific Sardine Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
['Porpoise Fleet', createMiningStrategy(mineRochinol(map), player)],
['Rabbit Fleet', createMiningStrategy(mineHydrogen(map), player)],
[
'Smalltooth Sawfish Fleet',
createMiningStrategy(mineTitaniumOre(map), player),
],
['Sugar Gliders Fleet', createMiningStrategy(mineIronOre(map), player)],
['Turkey Fleet', createMiningStrategy(mineHydrogen(map), player)],

['Aardwolf Fleet', createMiningStrategy(mineBiomass(map), player)],
[
'Antelope Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-19, 40),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-19, 40),
)
.values()
.next().value,
}),
player,
),
],
[
'Boa Fleet',
createMiningStrategy(
mineConfig({
homeBase: Coordinates.fromNumber(-40, 30),
targetBase: Coordinates.fromNumber(-18, 23),
resource: mineableByCoordinates(
map,
Coordinates.fromNumber(-18, 23),
)
.values()
.next().value,
}),
player,
),
],
['Chinchillas Fleet', createMiningStrategy(mineCarbon(map), player)],
[
'Fathead Sculpin Fleet',
createMiningStrategy(mineNitrogen(map), player),
],
[
'Giant Tortoise Fleet',
createMiningStrategy(mineSilicia(map), player),
],
['Kultarr Fleet', createMiningStrategy(mineLumanite(map), player)],
[
'Leopard Seal Fleet',
createMiningStrategy(mineCopperOre(map), player),
],
['Pangolin Fleet', createMiningStrategy(mineIronOre(map), player)],
['Rhinoceros Fleet', createMiningStrategy(mineHydrogen(map), player)],
['Snow Leopard Fleet', createMiningStrategy(mineRochinol(map), player)],
[
'Southern White Faced Owl Fleet',
createMiningStrategy(mineHydrogen(map), player),
],
['Turkeys Fleet', createMiningStrategy(mineTitaniumOre(map), player)],
['Zebra Fleet', createMiningStrategy(mineIronOre(map), player)],
['Guinea Fowl Fleet', createMiningStrategy(mineHydrogen(map), player)],
])
20 changes: 20 additions & 0 deletions src/main/basedbot/fleet-strategies/get-fleet-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Strategy } from '../fsm/strategy'
import { Player } from '../lib/sage/state/user-account'
import { WorldMap } from '../lib/sage/state/world-map'

import { atlasnetLuStrategy } from './atlasnet-lu-strategy'
import { mainnetLuStrategy } from './mainnet-lu-strategy'

export const getFleetStrategy = (
map: WorldMap,
player: Player,
): Map<string, Strategy> => {
switch (player.publicKey.toString()) {
case 'k49Y5xwN7Nyi19TqDR4zbCFuAt8kgy6qMaJ6Kj1wHrn':
return atlasnetLuStrategy(map, player)
case 'AePY3wEoUFcFuXeUU9X26YK6tNKQMZovBgvY54LK2B8N':
return mainnetLuStrategy(map, player)
default:
throw new Error('Unknown strategy')
}
}
Loading

0 comments on commit 99e9384

Please sign in to comment.