Giter VIP home page Giter VIP logo

s2client-dotnet's Introduction

StarCraft II Client API for .NET

A .NET (C#, F#, VB.Net) port of https://github.com/Blizzard/s2client-api into .Net "Standard" 2.0.

Warning: This is work in progress and APIs might change.

NuGet

Hopefully soon.

Why

TBD. Probably to make something awesome in a sane language ;)

Usage

Current a bot is a simple function GameState -> IEnumerable<SC2APIProtocol.Action> so for every state the bot decides to do a list of actions. There probably will be higher level interfaces with some predefined events/states later.

The following example will spawn a instance of Starcraft 2 (Runner.run(Instance.start(settings))) then setup the game:

  • The map to use
  • some configurations (for example if played in realtime or not)
  • The participants.

So for example to play against a hard bot on AbyssalReefLE.SC2Map you can download and install the map according to https://github.com/Blizzard/s2client-proto#installing-map-and-replay-packs and then start the game via the following code:

static void Main(string[] args)
{
    var userSettings = Sc2SettingsFile.settingsFromUserDir();

    var instanceSettings = Instance.StartSettings.OfUserSettings(userSettings);

    Func<Instance.Sc2Instance> createInstance =
        () => Runner.run(Instance.start(instanceSettings));

    var participants = new Sc2Game.Participant[] {
        Sc2Game.Participant.CreateParticipant(
            createInstance(), 
            Race.Terran, 
            (state => (IEnumerable<SC2APIProtocol.Action>)new SC2APIProtocol.Action[] {})),
        Sc2Game.Participant.CreateComputer(Race.Terran, Difficulty.Hard)
    };

    var gameSettings =
        Sc2Game.GameSettings.OfUserSettings(userSettings)
        .WithMap(@"Ladder2017Season1\AbyssalReefLE.SC2Map")
        .WithRealtime(true);

    // Runs the game to the end with the given bots / map and configuration
    Runner.run(Sc2Game.runGame(gameSettings, participants));
}

In F# it looks a bit nicer ;)

    let userSettings = Sc2SettingsFile.settingsFromUserDir()

    let instanceSettings = Instance.StartSettings.OfUserSettings userSettings

    let instance() = Instance.start(instanceSettings) |> Async.RunSynchronously

    let participants =
        [ Sc2Game.Participant(instance(), Race.Terran, (fun _ -> []))
          Sc2Game.Computer(Race.Terran, Difficulty.Hard) ]
    
    let settings = 
        { Sc2Game.GameSettings.OfUserSettings userSettings with
             Map = @"Ladder2017Season1\AbyssalReefLE.SC2Map"
             Realtime = true }
    Sc2Game.runGame settings participants |> Async.RunSynchronously

The empty bot function will ensure you can play manually. Obviously you want to implement that with something useful.

Further documentation (regarding the datastructures and custom StarCraft II Builds)

If you use the library don't hesitate to let me know ;)

s2client-dotnet's People

Contributors

anthonybrunasso avatar impulsecloud avatar jrepp avatar kevincalderone avatar kevinsandow avatar matthid avatar sc2automation avatar tewalds avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.