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, #on_status_change

Methods included from Connection::StatusListener

#on_status_change

Constructor Details

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

Parameters:

  • race (Integer)

    see Api::Race

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

    Api::Difficulty::VERY_EASY, Api::Difficulty::VERY_HARD,etc.

  • ai_build (Integer) (defaults to: Api::AIBuild::RANDOM_BUILD)

    default: Api::AIBuild::RANDOM_BUILD

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

Raises:



463
464
465
466
467
468
469
470
471
# File 'lib/sc2ai/player.rb', line 463

def initialize(race:, difficulty: Api::Difficulty::VERY_EASY, ai_build: Api::AIBuild::RANDOM_BUILD,
  name: "Computer")
  difficulty = Api::Difficulty::VERY_EASY if difficulty.nil?
  ai_build = Api::AIBuild::RANDOM_BUILD 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:



480
481
482
# File 'lib/sc2ai/player.rb', line 480

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



475
476
477
# File 'lib/sc2ai/player.rb', line 475

def requires_client?
  false
end