• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matthid/s2client-dotnet: Starcraft 2 Client API for .NET - similar to https://gi ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

matthid/s2client-dotnet

开源软件地址:

https://github.com/matthid/s2client-dotnet

开源编程语言:

F# 97.0%

开源软件介绍:

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

https://www.nuget.org/packages/s2client-dotnet

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 ;)

Building

Requirements:

  1. Build everything with a single command:
    • fake run build.fsx

Now the release/nuget folder contains the packages.

  1. Run the test projects
    • Download and extract the "Ladder 2017 Season 1" pack from https://github.com/Blizzard/s2client-proto

    • dotnet run --project src/s2client-testCSharp/s2client-testCSharp.csproj

    • dotnet run --project src/s2client-test/s2client-test.fsproj




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap