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, #callbacks_defined, #difficulty, #enable_feature_layer, #interface_options, #name, #opponent_id, #race, #realtime, #step_count, #type

Attributes included from GameState

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

Instance Method Summary collapse

Methods inherited from Sc2::Player

#callback_defined?, #create_game, #disconnect, #join_game, #leave_game, #prepare_start, #quit, #race_unknown?, #refresh_game_info, #refresh_state, #set_enemy, #set_race_for_random, #started, #step_forward

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:



488
489
490
491
492
493
494
495
496
# File 'lib/sc2ai/player.rb', line 488

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:



505
506
507
# File 'lib/sc2ai/player.rb', line 505

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



500
501
502
# File 'lib/sc2ai/player.rb', line 500

def requires_client?
  false
end