Module: Sc2::Player::GameState

Extended by:
Forwardable
Includes:
Connection::StatusListener
Included in:
Sc2::Player, PreviousState
Defined in:
lib/sc2ai/player/game_state.rb

Overview

Holds game state

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#available_abilities_loop=(value) ⇒ Integer



96
97
98
# File 'lib/sc2ai/player/game_state.rb', line 96

def available_abilities_loop
  @available_abilities_loop
end

#chats_receivedArray<Api::ChatReceived>



62
# File 'lib/sc2ai/player/game_state.rb', line 62

attr_writer :chats_received

#dataApi::ResponseData



40
41
42
# File 'lib/sc2ai/player/game_state.rb', line 40

def data
  @data
end

#game_infoApi::ResponseGameInfo

Access useful game information. Used in parsed pathing grid, terrain height, placement grid. Holds Api::ResponseGameInfo::#start_locations.



31
32
33
# File 'lib/sc2ai/player/game_state.rb', line 31

def game_info
  @game_info
end

#game_loopInteger



23
24
25
# File 'lib/sc2ai/player/game_state.rb', line 23

def game_loop
  @game_loop || 0
end

#observationApi::Observation



44
# File 'lib/sc2ai/player/game_state.rb', line 44

attr_writer :observation

#resultApi::Result



66
67
68
# File 'lib/sc2ai/player/game_state.rb', line 66

def result
  @result
end

#spent_mineralsInteger

Returns sum of minerals spent via Unit##build an Unit#morph.

See Also:

  • and #morph


71
72
73
# File 'lib/sc2ai/player/game_state.rb', line 71

def spent_minerals
  @spent_minerals
end

#spent_supplyInteger

Returns sum of supply spent via Unit##build an Unit##morph.

See Also:

  • and #morph


81
82
83
# File 'lib/sc2ai/player/game_state.rb', line 81

def spent_supply
  @spent_supply
end

#spent_vespeneInteger

Returns sum of vespene gas spent via Unit##build an Unit##morph.

See Also:

  • and #morph


76
77
78
# File 'lib/sc2ai/player/game_state.rb', line 76

def spent_vespene
  @spent_vespene
end

#status:LAUNCHED, ...



9
10
11
# File 'lib/sc2ai/player/game_state.rb', line 9

def status
  @status
end

Instance Method Details

#available_abilitiesHash<Integer, Array<Integer>>

A Hash by unit tag, holding an array of available ability ids Synchronously calls RequestQueryAvailableAbilities and caches for this game loop.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/sc2ai/player/game_state.rb', line 102

def available_abilities
  # Save/check when last we refreshed abilities
  if @available_abilities_loop != game_loop

    # Query abilities for all our units + structure tags combined
    abilities = api.query_abilities_for_unit_tags(units.tags + structures.tags, ignore_resource_requirements: false)
    # Build the hash by unit tag
    fresh_available_abilities = {}
    abilities.each do |row|
      fresh_available_abilities[row.unit_tag] = row.abilities.map(&:ability_id)
    end
    @available_abilities = fresh_available_abilities
    @available_abilities_loop = game_loop
  end
  @available_abilities
end

#commonApi::PlayerCommon

An alias for observation.player_common to allow easier access to i.e. common.minerals



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/sc2ai/player/game_state.rb', line 121

def common
  observation.player_common || Api::PlayerCommon.new(
    player_id: 0,
    minerals: 50,
    vespene: 0,
    food_cap: ((race == Api::Race::ZERG) ? 14 : 15),
    food_used: 12,
    food_army: 0,
    food_workers: 12,
    idle_worker_count: 0,
    army_count: 0,
    warp_gate_count: 0,
    larva_count: ((race == Api::Race::ZERG) ? 3 : 0)
  )
end

#on_status_change(status) ⇒ Object

Callback when game status changes



14
15
16
# File 'lib/sc2ai/player/game_state.rb', line 14

def on_status_change(status)
  self.status = status
end