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
- #available_abilities_loop ⇒ Integer writeonly
-
#chats_received ⇒ Array<Api::ChatReceived>
Messages since last observation.
- #data ⇒ Api::ResponseData
-
#game_info ⇒ Api::ResponseGameInfo
Access useful game information.
-
#game_info_loop ⇒ Object
This is the last loop at which game_info was set.
-
#game_loop ⇒ Integer
Current game loop.
-
#observation ⇒ Api::Observation
Snapshot of current game state.
-
#result ⇒ Api::Result
The result of the game (:Victory/:Defeat/:Tie).
-
#spent_minerals ⇒ Integer
Sum of minerals spent via Unit##build an Unit#morph.
-
#spent_supply ⇒ Integer
Sum of supply spent via Unit##build an Unit##morph.
-
#spent_vespene ⇒ Integer
Sum of vespene gas spent via Unit##build an Unit##morph.
-
#status ⇒ :launched, ...
Status.
Instance Method Summary collapse
-
#available_abilities ⇒ Hash<Integer, Array<Integer>>
A Hash by unit tag, holding an array of available ability ids Synchronously calls RequestQueryAvailableAbilities and caches for this game loop.
-
#common ⇒ Api::PlayerCommon
An alias for observation.player_common to allow easier access to i.e.
-
#game_info_stale? ⇒ Boolean
Determines if your game_info will be refreshed at this moment Has a hard-capped refresh of only ever 4 steps In general game_info is only refreshed Player::Bot reads from pathing_grid or placement_grid.
-
#on_status_change(status) ⇒ Object
Callback when game status changes.
Instance Attribute Details
#available_abilities_loop=(value) ⇒ Integer
114 115 116 |
# File 'lib/sc2ai/player/game_state.rb', line 114 def available_abilities_loop @available_abilities_loop end |
#chats_received ⇒ Array<Api::ChatReceived>
Returns messages since last observation.
80 |
# File 'lib/sc2ai/player/game_state.rb', line 80 attr_writer :chats_received |
#data ⇒ Api::ResponseData
58 59 60 |
# File 'lib/sc2ai/player/game_state.rb', line 58 def data @data end |
#game_info ⇒ Api::ResponseGameInfo
Access useful game information. Used in parsed pathing grid, terrain height, placement grid. Holds Api::ResponseGameInfo::#start_locations.
30 31 32 |
# File 'lib/sc2ai/player/game_state.rb', line 30 def game_info @game_info end |
#game_info_loop ⇒ Object
This is the last loop at which game_info was set. Used to determine staleness.
41 42 43 |
# File 'lib/sc2ai/player/game_state.rb', line 41 def game_info_loop @game_info_loop end |
#game_loop ⇒ Integer
Returns current game loop.
22 23 24 |
# File 'lib/sc2ai/player/game_state.rb', line 22 def game_loop @game_loop || 0 end |
#observation ⇒ Api::Observation
Returns snapshot of current game state.
62 |
# File 'lib/sc2ai/player/game_state.rb', line 62 attr_writer :observation |
#result ⇒ Api::Result
Returns the result of the game (:Victory/:Defeat/:Tie).
84 85 86 |
# File 'lib/sc2ai/player/game_state.rb', line 84 def result @result end |
#spent_minerals ⇒ Integer
Returns sum of minerals spent via Unit##build an Unit#morph.
89 90 91 |
# File 'lib/sc2ai/player/game_state.rb', line 89 def spent_minerals @spent_minerals end |
#spent_supply ⇒ Integer
Returns sum of supply spent via Unit##build an Unit##morph.
99 100 101 |
# File 'lib/sc2ai/player/game_state.rb', line 99 def spent_supply @spent_supply end |
#spent_vespene ⇒ Integer
Returns sum of vespene gas spent via Unit##build an Unit##morph.
94 95 96 |
# File 'lib/sc2ai/player/game_state.rb', line 94 def spent_vespene @spent_vespene end |
#status ⇒ :launched, ...
Returns status.
9 10 11 |
# File 'lib/sc2ai/player/game_state.rb', line 9 def status @status end |
Instance Method Details
#available_abilities ⇒ Hash<Integer, Array<Integer>>
A Hash by unit tag, holding an array of available ability ids Synchronously calls RequestQueryAvailableAbilities and caches for this game loop.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sc2ai/player/game_state.rb', line 120 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.(units. + structures., 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 |
#common ⇒ Api::PlayerCommon
An alias for observation.player_common to allow easier access to i.e. common.minerals
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sc2ai/player/game_state.rb', line 139 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 |
#game_info_stale? ⇒ Boolean
Determines if your game_info will be refreshed at this moment Has a hard-capped refresh of only ever 4 steps In general game_info is only refreshed Player::Bot reads from pathing_grid or placement_grid
47 48 49 50 51 52 53 54 |
# File 'lib/sc2ai/player/game_state.rb', line 47 def game_info_stale? return true if game_info_loop.nil? || game_info.nil? return false if game_info_loop == game_loop # Note: No minimum step count set anymore # We can do something like, only updating every 2+ frames: game_info_loop + 4 <= game_loop end |
#on_status_change(status) ⇒ Object
Callback when game status changes
13 14 15 |
# File 'lib/sc2ai/player/game_state.rb', line 13 def on_status_change(status) self.status = status end |