Class: Sc2::Player::Enemy

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

Overview

A specialized type of player instance which each player has one of This should never be initialized by hand

Constant Summary

Constants inherited from Sc2::Player

IDENTIFIED_RACES

Instance Attribute Summary

Attributes included from Units

#all_seen_unit_tags, #all_units, #effects, #event_units_damaged, #event_units_destroyed, #neutral, #placeholders, #power_sources, #radar_rings, #structures, #units, #upgrades_completed

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Units

#ability_data, #can_afford?, #can_afford_upgrade?, #subtract_cost, #unit_ability_available?, #unit_data, #unit_group_from_tags, #unit_has_attribute?, #units_in_progress, #upgrade_completed?, #upgrade_data, #upgrade_in_progress?, #upgrades_in_progress

Methods inherited from Sc2::Player

#connect, #create_game, #disconnect, #initialize, #join_game, #leave_game, #race_unknown?, #refresh_game_info, #requires_client?

Methods included from GameState

#available_abilities, #common, #on_status_change

Methods included from Connection::StatusListener

#on_status_change

Constructor Details

This class inherits a constructor from Sc2::Player

Class Method Details

.from_proto(player_info: nil) ⇒ Sc2::Player::Enemy

Creates an Enemy object after game has started using Api::GameInfo’s Api::PlayerInfo

Parameters:

Returns:



424
425
426
427
428
429
430
# File 'lib/sc2ai/player.rb', line 424

def from_proto(player_info: nil)
  Sc2::Player::Enemy.new(race: player_info.race_requested,
    name: player_info.player_name,
    type: player_info.type,
    difficulty: player_info.difficulty,
    ai_build: player_info.ai_build)
end

Instance Method Details

#detect_race_from_unitsfalse, Integer

Will attempt to loop over player units and set its race if it can detect. Generally only used for enemy

Returns:

  • (false, Integer)

    Api::Race if race detected, false otherwise



436
437
438
439
440
441
442
443
# File 'lib/sc2ai/player.rb', line 436

def detect_race_from_units
  return false unless race_unknown?
  return false if units.nil?
  unit_race = Api::Race.resolve(units.first.unit_data.race)
  if Sc2::Player::IDENTIFIED_RACES.include?(unit_race)
    self.race = unit_race
  end
end