Logo FSBarV1_Archived

Library

FSBar.Client is the core library. It owns the engine lifecycle, the protobuf wire protocol, the GameState projection, and the map-analysis primitives.

BarClient

open FSBar.Client

// Headless — fastest path for CI / scripts.
use client = BarClient.startHeadless ()

// Graphical — full BAR window (Linux only, windowed; fullscreen is disabled).
use graphical = BarClient.startGraphical ()

Two frame APIs:

A GameFrame is:

type GameFrame =
    { FrameNumber: int
      Events: GameEvent list
      State: GameState }

client.GameState is an always-current snapshot updated each frame.

Commands

FSBar.Client.Commands produces typed AICommand values. Send any sequence with client.SendCommands : AICommand list -> unit.

open FSBar.Client.Commands

client.SendCommands [
    MoveCommand 42 2000.0f 100.0f 1000.0f
    BuildCommand 12 "armllt" 2100.0f 100.0f 1050.0f
    StopCommand 17
]

Builders cover Move, Build, Attack, Guard, Patrol, Repair, Reclaim, Stop, Wait, SetFireState, SetMoveState, and more.

Events

GameEvent is a flat DU of all engine-sourced facts: UnitCreated, UnitFinished, UnitIdle, UnitDamaged, UnitDestroyed, EnemyEnterLOS, EnemyLeaveLOS, EnemyEnterRadar, PlayerCommand, and many more.

Typical handler shape:

client.WaitFrames 500 (fun frame ->
    frame.Events
    |> List.choose (function
        | GameEvent.UnitIdle uid -> Some (MoveCommand uid 4096.0f 100.0f 4096.0f)
        | _ -> None)
    |> function [] -> () | cmds -> client.SendCommands cmds)

GameState

type GameState =
    { TrackedUnits: Map<int, TrackedUnit>
      TrackedEnemies: Map<int, TrackedEnemy>
      Economy: EconomySnapshot
      FrameNumber: int
      UnitDefs: UnitDefCache }

TrackedUnit carries position, heading, health, def id, team, and build progress. TrackedEnemy adds LOS/radar state. EconomySnapshot holds metal/energy income, storage, and pull.

Callbacks

FSBar.Client.Callbacks exposes 26 mid-frame queries (unit position/health, team economy, map info, raw heightmap data, LOS arrays, …). Use these when you need richer data than GameState carries, or data not fact-extracted into events.

Map analysis

Module

Purpose

MapGrid

Array2D heightmap / slope / resource / passability layers

MapQuery

Spatial queries over a MapGrid (points, regions, LOS samples)

SmfParser

Parses .smf map files out of .sd7 archives via bsdtar

Pathing

Navmesh-style reachable-region primitives

Chokepoints

Static chokepoint extraction

BasePlan

Candidate base-layout scoring

WallIn

Wall/choke blocking planner

MapCacheFile

JSON+gzip on-disk cache under bots/trainer/map-cache/

MapCacheFile.read is the hot path — the trainer bots warm up against committed per-map caches and hard-abort on codeVersion mismatch.

Synthetic data

FSBar.SyntheticData produces deterministic GameState snapshots + Scene values without a running engine — the basis of every Viz unit test and every Hub-tab preview. See Visualization.

API reference

Full auto-generated reference: API.

val client: obj
val graphical: obj
type GameFrame = { FrameNumber: int Events: obj State: obj }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
type 'T list = List<'T>
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
type GameState = { TrackedUnits: obj TrackedEnemies: obj Economy: obj FrameNumber: int UnitDefs: obj }
Multiple items
module Map from Microsoft.FSharp.Collections

--------------------
type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ...

--------------------
new: elements: ('Key * 'Value) seq -> Map<'Key,'Value>

Type something to start searching.