lib/sc2ai/player/game_state.rb in sc2ai-0.2.0 vs lib/sc2ai/player/game_state.rb in sc2ai-0.3.0

- old
+ new

@@ -3,11 +3,11 @@ module Sc2 class Player # Holds game state module GameState # @!attribute status - # @return [:launched, :in_game, :in_replay, :ended, :quit, :unknown] status + # @return [:LAUNCHED, :IN_GAME, :IN_REPLAY, :ENDED, :QUIT, :UNKNOWN] status attr_accessor :status include Connection::StatusListener # Callback when game status changes def on_status_change(status) @@ -25,36 +25,29 @@ # @!attribute game_info [rw] # Access useful game information. Used in parsed pathing grid, terrain height, placement grid. # Holds Api::ResponseGameInfo::#start_locations. # @return [Api::ResponseGameInfo] - attr_reader :game_info + def game_info + if @game_info_task&.running? + @game_info_task&.wait + @game_info_task = nil + end + @game_info + end def game_info=(new_info) - @game_info_loop = game_loop || 0 + @game_info_loop = game_loop @game_info = new_info end # @!attribute game_info_loop # This is the last loop at which game_info was set. # Used to determine staleness. # @return [Integer] attr_accessor :game_info_loop - # 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 - # @return [Boolean] - 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 - # @!attribute data # @return [Api::ResponseData] attr_accessor :data # @!attribute observation @@ -139,17 +132,17 @@ def common observation.player_common || Api::PlayerCommon.new( player_id: 0, minerals: 50, vespene: 0, - food_cap: ((race == Api::Race::Zerg) ? 14 : 15), + 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) + larva_count: ((race == Api::Race::ZERG) ? 3 : 0) ) end # class << self # def included(_mod)