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_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.
-
#on_status_change(status) ⇒ Object
Callback when game status changes.
Instance Attribute Details
#available_abilities_loop=(value) ⇒ Integer
95 96 97 |
# File 'lib/sc2ai/player/game_state.rb', line 95 def available_abilities_loop @available_abilities_loop end |
#chats_received ⇒ Array<Api::ChatReceived>
Returns messages since last observation.
61 |
# File 'lib/sc2ai/player/game_state.rb', line 61 attr_writer :chats_received |
#data ⇒ Api::ResponseData
39 40 41 |
# File 'lib/sc2ai/player/game_state.rb', line 39 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_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.
43 |
# File 'lib/sc2ai/player/game_state.rb', line 43 attr_writer :observation |
#result ⇒ Api::Result
Returns the result of the game (:Victory/:Defeat/:Tie).
65 66 67 |
# File 'lib/sc2ai/player/game_state.rb', line 65 def result @result end |
#spent_minerals ⇒ Integer
Returns sum of minerals spent via Unit##build an Unit#morph.
70 71 72 |
# File 'lib/sc2ai/player/game_state.rb', line 70 def spent_minerals @spent_minerals end |
#spent_supply ⇒ Integer
Returns sum of supply spent via Unit##build an Unit##morph.
80 81 82 |
# File 'lib/sc2ai/player/game_state.rb', line 80 def spent_supply @spent_supply end |
#spent_vespene ⇒ Integer
Returns sum of vespene gas spent via Unit##build an Unit##morph.
75 76 77 |
# File 'lib/sc2ai/player/game_state.rb', line 75 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sc2ai/player/game_state.rb', line 101 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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sc2ai/player/game_state.rb', line 120 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
13 14 15 |
# File 'lib/sc2ai/player/game_state.rb', line 13 def on_status_change(status) self.status = status end |