Class: Sc2::Player::Computer

Inherits:
Sc2::Player show all
Defined in:
lib/sc2ai/player.rb

Overview

A Computer opponent using the game’s built-in AI for a Match

Constant Summary

Constants inherited from Sc2::Player

IDENTIFIED_RACES

Instance Attribute Summary

Attributes inherited from Sc2::Player

#IDENTIFIED_RACES, #ai_build, #api, #difficulty, #enable_feature_layer, #interface_options, #name, #opponent_id, #race, #realtime, #step_count, #type

Attributes included from GameState

#chats_received, #data, #game_info, #game_info_loop, #game_loop, #observation, #result, #spent_minerals, #spent_supply, #spent_vespene, #status

Instance Method Summary collapse

Methods inherited from Sc2::Player

#create_game, #disconnect, #join_game, #leave_game, #race_unknown?, #refresh_game_info

Methods included from GameState

#available_abilities, #common, #game_info_stale?, #on_status_change

Methods included from Connection::StatusListener

#on_status_change

Constructor Details

#initialize(race:, difficulty: Api::Difficulty::VeryEasy, ai_build: Api::AIBuild::RandomBuild, name: "Computer") ⇒ Sc2::Computer

Parameters:

  • race (Integer)

    (see Api::Race)

  • difficulty (Integer) (defaults to: Api::Difficulty::VeryEasy)

    see Api::Difficulty::VeryEasy,Api::Difficulty::VeryHard,etc.)

  • ai_build (Api::AIBuild::RandomBuild) (defaults to: Api::AIBuild::RandomBuild)

    (see Api::AIBuild)

  • name (String) (defaults to: "Computer")

Raises:



433
434
435
436
437
438
439
440
441
# File 'lib/sc2ai/player.rb', line 433

def initialize(race:, difficulty: Api::Difficulty::VeryEasy, ai_build: Api::AIBuild::RandomBuild,
  name: "Computer")
  difficulty = Api::Difficulty::VeryEasy if difficulty.nil?
  ai_build = Api::AIBuild::RandomBuild if ai_build.nil?
  raise Error, "unknown difficulty: '#{difficulty}'" if Api::Difficulty.lookup(difficulty).nil?
  raise Error, "unknown difficulty: '#{ai_build}'" if Api::AIBuild.lookup(ai_build).nil?

  super(race:, name:, type: Api::PlayerType::Computer, difficulty:, ai_build:)
end

Instance Method Details

#connect(host:, port:) ⇒ Object

Raises:



450
451
452
# File 'lib/sc2ai/player.rb', line 450

def connect(host:, port:)
  raise Error, "Computer type can not connect to api"
end

#requires_client?Boolean

Returns whether or not the player requires a sc2 instance

Returns:

  • (Boolean)

    false always for Player::Computer



445
446
447
# File 'lib/sc2ai/player.rb', line 445

def requires_client?
  false
end