Class: Sc2::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/sc2ai/cli/cli.rb,
lib/sc2ai/cli/new.rb,
lib/sc2ai/cli/ladderzip.rb

Overview

Command line utilities

Defined Under Namespace

Classes: Ladderzip, New

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sc2ai/cli/cli.rb', line 12

def exit_on_failure?
  true
end

Instance Method Details

#ladderconfigObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sc2ai/cli/cli.rb', line 95

def ladderconfig
  require "sc2ai"
  unless Pathname("./boot.rb").exist?
    raise Sc2::Error, "boot.rb not found. Bot started from wrong directory."
  end

  require "./boot"
  # Debug
  Sc2.logger.info "Bot class: #{$bot.class}"
  Sc2.logger.info "Config:"
  Sc2.logger.info "  in-game name: #{$bot.name}"
  Sc2.logger.info "  race: #{Api::Race.lookup($bot.race)}"
  Sc2.logger.info "  realtime: #{$bot.realtime}"
  Sc2.logger.info "  step_count: #{$bot.step_count}"
  Sc2.logger.info "  enable_feature_layer: #{$bot.enable_feature_layer}"
  Sc2.logger.info "  interface_options: #{$bot.interface_options}"
end

#laddermatchObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/sc2ai/cli/cli.rb', line 136

def laddermatch
  require "sc2ai"

  unless Sc2.ladder?
    raise Sc2::Error, "This command is only for competing on aiarena.net"
  end

  unless Pathname("./boot.rb").exist?
    raise Sc2::Error, "boot.rb not found. Bot started from wrong directory."
  end

  Sc2.logger.level = :info

  require "./boot"

  # Ladder specific overrides
  $bot.realtime = true if options[:RealTime]
  $bot.opponent_id = options[:OpponentId] if options[:OpponentId]

  Async do
    $bot.connect(host: options[:LadderServer], port: options[:GamePort])
    $bot.join_game(
      server_host: options[:LadderServer],
      port_config: Sc2::Ports.port_config_basic(start_port: options[:StartPort], num_players: 2)
    )
    $bot.add_listener($bot, klass: Sc2::Connection::StatusListener)
    $bot.play
  end.wait
end

#setup410Object

downloads and install SC2 v4.10



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sc2ai/cli/cli.rb', line 23

def setup410
  say " "
  say "This script sets up SC2 at version 4.10, which we use competitively."
  say "Press any key to continue..."
  ask ""

  say "You must accept the Blizzard® StarCraft® II AI and Machine Learning License at"
  say "https://blzdistsc2-a.akamaihd.net/AI_AND_MACHINE_LEARNING_LICENSE.html"
  say "It is PERMISSIVE and grants you freedoms over the standard EULA."
  say "We do not record this action, but depend on software goverend by that license to continue."
  puts 'If you accept, type "iagreetotheeula" (without quotes) and press ENTER to continue:'

  while $stdin.gets.chomp != "iagreetotheeula"
    say ""
    puts 'Type "iagreetotheeula" (without quotes) and press ENTER to continue:'
  end
  say ""
  say ""
  say "Great decision."

  require "sc2ai"
  Async do
    Sc2.logger.level = :fatal
    say "SC2 will launch a blank window, be unresponsive, but download about 100mb in the background."
    say "Let it finish and close itself."
    say "Press ENTER if you understand."
    ask ""

    say ""
    say ""
    say "This will only take a minute..."

    Sc2.config.version = nil
    client = Sc2::ClientManager.obtain(0)
    if Gem.win_platform?
      sleep(10)
    end
    observer = Sc2::Player::Observer.new
    observer.connect(host: client.host, port: client.port)
    setup_replay = Sc2::Paths.gem_root.join("data", "setup", "setup.SC2Replay")
    observer.api.replay_info(
      replay_data: File.binread(setup_replay),
      download_data: true
    )

    # Auto-detect executable path and ensure it matched exactly
    base_build = "75689"
    path = Sc2::Paths.executable(base_build: base_build)
    if path.include?(base_build) && Pathname(path).exist?
      say " "
      say "Success. Download complete.", :green
      say " "
    else
      say "Error. Slightly worrying, but no fear.", :red
      say "To manually setup, grab the latest ladder maps and add them to your map folder."
      say "Grab the latest maps from https://aiarena.net/wiki/maps/"
      say "Detected map folder: #{Sc2::Paths.maps_dir}"
      say "Then, download any recent replay from https://aiarena.net/ and double click to launch"
    end

    observer.api.quit
    observer.disconnect
    say "Generating sc2ai.yml to always use 4.10..."
    Sc2.config.config_file.write({"version" => "4.10"}.to_yaml.to_s)
    say ""
    say "Done. You're good to go.", :green
  ensure
    Sc2::ClientManager.stop(0)
  end
end