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
96 97 98 |
# File 'lib/sc2ai/player/game_state.rb', line 96 def available_abilities_loop @available_abilities_loop end |
#chats_received ⇒ Array<Api::ChatReceived>
Returns messages since last observation.
62 |
# File 'lib/sc2ai/player/game_state.rb', line 62 attr_writer :chats_received |
#data ⇒ Api::ResponseData
40 41 42 |
# File 'lib/sc2ai/player/game_state.rb', line 40 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.
31 32 33 |
# File 'lib/sc2ai/player/game_state.rb', line 31 def game_info @game_info end |
#game_loop ⇒ Integer
Returns current game loop.
23 24 25 |
# File 'lib/sc2ai/player/game_state.rb', line 23 def game_loop @game_loop || 0 end |
#observation ⇒ Api::Observation
Returns snapshot of current game state.
44 |
# File 'lib/sc2ai/player/game_state.rb', line 44 attr_writer :observation |
#result ⇒ Api::Result
Returns the result of the game (:Victory/:Defeat/:Tie).
66 67 68 |
# File 'lib/sc2ai/player/game_state.rb', line 66 def result @result end |
#spent_minerals ⇒ Integer
Returns sum of minerals spent via Unit##build an Unit#morph.
71 72 73 |
# File 'lib/sc2ai/player/game_state.rb', line 71 def spent_minerals @spent_minerals end |
#spent_supply ⇒ Integer
Returns sum of supply spent via Unit##build an Unit##morph.
81 82 83 |
# File 'lib/sc2ai/player/game_state.rb', line 81 def spent_supply @spent_supply end |
#spent_vespene ⇒ Integer
Returns sum of vespene gas spent via Unit##build an Unit##morph.
76 77 78 |
# File 'lib/sc2ai/player/game_state.rb', line 76 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.
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.(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
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 |