sc2ai 0.0.0.pre → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/data/data.json +1 -0
  3. data/data/data_readable.json +22842 -0
  4. data/data/sc2ai/protocol/common.proto +59 -0
  5. data/data/sc2ai/protocol/data.proto +120 -0
  6. data/data/sc2ai/protocol/debug.proto +127 -0
  7. data/data/sc2ai/protocol/error.proto +221 -0
  8. data/data/sc2ai/protocol/query.proto +55 -0
  9. data/data/sc2ai/protocol/raw.proto +202 -0
  10. data/data/sc2ai/protocol/sc2api.proto +718 -0
  11. data/data/sc2ai/protocol/score.proto +108 -0
  12. data/data/sc2ai/protocol/spatial.proto +115 -0
  13. data/data/sc2ai/protocol/ui.proto +145 -0
  14. data/data/setup/setup.SC2Map +0 -0
  15. data/data/setup/setup.SC2Replay +0 -0
  16. data/data/stableid.json +35730 -0
  17. data/data/versions.json +554 -0
  18. data/exe/sc2ai +35 -0
  19. data/lib/docker_build/Dockerfile.ruby +74 -0
  20. data/lib/docker_build/docker-compose-base-image.yml +10 -0
  21. data/lib/docker_build/docker-compose-ladderzip.yml +9 -0
  22. data/lib/sc2ai/api/ability_id.rb +1644 -0
  23. data/lib/sc2ai/api/buff_id.rb +306 -0
  24. data/lib/sc2ai/api/data.rb +101 -0
  25. data/lib/sc2ai/api/effect_id.rb +20 -0
  26. data/lib/sc2ai/api/tech_tree.rb +83 -0
  27. data/lib/sc2ai/api/tech_tree_data.rb +2338 -0
  28. data/lib/sc2ai/api/unit_type_id.rb +2022 -0
  29. data/lib/sc2ai/api/upgrade_id.rb +310 -0
  30. data/lib/sc2ai/cli/cli.rb +175 -0
  31. data/lib/sc2ai/cli/ladderzip.rb +154 -0
  32. data/lib/sc2ai/cli/new.rb +88 -0
  33. data/lib/sc2ai/configuration.rb +145 -0
  34. data/lib/sc2ai/connection/connection_listener.rb +30 -0
  35. data/lib/sc2ai/connection/requests.rb +417 -0
  36. data/lib/sc2ai/connection/status_listener.rb +15 -0
  37. data/lib/sc2ai/connection.rb +146 -0
  38. data/lib/sc2ai/local_play/client/configurable_options.rb +115 -0
  39. data/lib/sc2ai/local_play/client.rb +159 -0
  40. data/lib/sc2ai/local_play/client_manager.rb +70 -0
  41. data/lib/sc2ai/local_play/map_file.rb +48 -0
  42. data/lib/sc2ai/local_play/match.rb +184 -0
  43. data/lib/sc2ai/overrides/array.rb +14 -0
  44. data/lib/sc2ai/overrides/async/process/child.rb +31 -0
  45. data/lib/sc2ai/overrides/kernel.rb +33 -0
  46. data/lib/sc2ai/paths.rb +294 -0
  47. data/lib/sc2ai/player/actions.rb +386 -0
  48. data/lib/sc2ai/player/debug.rb +224 -0
  49. data/lib/sc2ai/player/game_state.rb +131 -0
  50. data/lib/sc2ai/player/geometry.rb +766 -0
  51. data/lib/sc2ai/player/previous_state.rb +49 -0
  52. data/lib/sc2ai/player/units.rb +337 -0
  53. data/lib/sc2ai/player.rb +661 -0
  54. data/lib/sc2ai/ports.rb +152 -0
  55. data/lib/sc2ai/protocol/_meta_documentation.rb +39 -0
  56. data/lib/sc2ai/protocol/common_pb.rb +43 -0
  57. data/lib/sc2ai/protocol/data_pb.rb +47 -0
  58. data/lib/sc2ai/protocol/debug_pb.rb +56 -0
  59. data/lib/sc2ai/protocol/error_pb.rb +36 -0
  60. data/lib/sc2ai/protocol/extensions/color.rb +20 -0
  61. data/lib/sc2ai/protocol/extensions/point.rb +23 -0
  62. data/lib/sc2ai/protocol/extensions/point_2_d.rb +26 -0
  63. data/lib/sc2ai/protocol/extensions/position.rb +202 -0
  64. data/lib/sc2ai/protocol/extensions/power_source.rb +19 -0
  65. data/lib/sc2ai/protocol/extensions/unit.rb +489 -0
  66. data/lib/sc2ai/protocol/query_pb.rb +47 -0
  67. data/lib/sc2ai/protocol/raw_pb.rb +57 -0
  68. data/lib/sc2ai/protocol/sc2api_pb.rb +130 -0
  69. data/lib/sc2ai/protocol/score_pb.rb +40 -0
  70. data/lib/sc2ai/protocol/spatial_pb.rb +48 -0
  71. data/lib/sc2ai/protocol/ui_pb.rb +56 -0
  72. data/lib/sc2ai/unit_group/action_ext.rb +74 -0
  73. data/lib/sc2ai/unit_group/filter_ext.rb +379 -0
  74. data/lib/sc2ai/unit_group.rb +277 -0
  75. data/lib/sc2ai/version.rb +2 -1
  76. data/lib/sc2ai.rb +93 -2
  77. data/lib/templates/ladderzip/bin/ladder.tt +23 -0
  78. data/lib/templates/new/.ladderignore +20 -0
  79. data/lib/templates/new/Gemfile.tt +7 -0
  80. data/lib/templates/new/api/common.proto +59 -0
  81. data/lib/templates/new/api/data.proto +120 -0
  82. data/lib/templates/new/api/debug.proto +127 -0
  83. data/lib/templates/new/api/error.proto +221 -0
  84. data/lib/templates/new/api/query.proto +55 -0
  85. data/lib/templates/new/api/raw.proto +202 -0
  86. data/lib/templates/new/api/sc2api.proto +718 -0
  87. data/lib/templates/new/api/score.proto +108 -0
  88. data/lib/templates/new/api/spatial.proto +115 -0
  89. data/lib/templates/new/api/ui.proto +145 -0
  90. data/lib/templates/new/boot.rb.tt +6 -0
  91. data/lib/templates/new/my_bot.rb.tt +23 -0
  92. data/lib/templates/new/run_example_match.rb.tt +14 -0
  93. data/sc2ai.gemspec +80 -0
  94. metadata +344 -13
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sc2
4
+ class Player
5
+ # Holds game state
6
+ module GameState
7
+ # @!attribute status
8
+ # @return [:launched, :in_game, :in_replay, :ended, :quit, :unknown] status
9
+ attr_accessor :status
10
+
11
+ include Connection::StatusListener
12
+ # Callback when game status changes
13
+ def on_status_change(status)
14
+ self.status = status
15
+ end
16
+
17
+ extend Forwardable
18
+
19
+ # @!attribute game_loop
20
+ # @return [Integer] current game loop
21
+ def_delegators :observation, :game_loop
22
+
23
+ # @!attribute game_info [rw]
24
+ # Access useful game information. Used in parsed pathing grid, terrain height, placement grid.
25
+ # Holds Api::ResponseGameInfo::#start_locations.
26
+ # @return [Api::ResponseGameInfo]
27
+ attr_reader :game_info
28
+
29
+ def game_info=(new_info)
30
+ @game_info_loop = game_loop || 0
31
+ @game_info = new_info
32
+ end
33
+
34
+ # @!attribute game_info_loop
35
+ # This is the last loop at which game_info was set.
36
+ # Used to determine staleness.
37
+ # @return [Integer]
38
+ attr_accessor :game_info_loop
39
+
40
+ # Determines if your game_info will be refreshed at this moment
41
+ # Has a hard-capped refresh of only ever 2 steps
42
+ # In general game_info is only refreshed Player::Bot reads from pathing_grid or placement_grid
43
+ # @return [Boolean]
44
+ def game_info_stale?
45
+ return true if game_info_loop.nil? || game_info.nil?
46
+ return false if game_info_loop == game_loop
47
+
48
+ # Note: No minimum step count set anymore
49
+ # We can do something like, only updating every 2+ frames:
50
+ game_info_loop + 2 <= game_loop
51
+ end
52
+
53
+ # @!attribute data
54
+ # @return [Api::ResponseData]
55
+ attr_accessor :data
56
+
57
+ # @!attribute observation
58
+ # @return [Api::Observation] snapshot of current game state
59
+ attr_writer :observation
60
+
61
+ # @!attribute chats_received
62
+ # @return [Array<Api::ChatReceived>] messages since last observation
63
+ #
64
+ # @example
65
+ # # Useful for commanding your own bot on step
66
+ # chats_received.each do |chat|
67
+ # if chat.message == "!gg"
68
+ # if chat.player_id == common.player_id
69
+ # # we sent this...
70
+ # leave_game # ladder surrender
71
+ # exit # exit script
72
+ # else
73
+ # # someone else messaged, dont quit
74
+ # end
75
+ # end
76
+ # end
77
+ attr_writer :chats_received
78
+
79
+ # @!attribute result
80
+ # @return [Api::Result] the result of the game (:Victory/:Defeat/:Tie)
81
+ attr_accessor :result
82
+
83
+ # @!attribute spent_minerals
84
+ # @see Unit#build and #morph
85
+ # @return [Integer] sum of minerals spent via Unit##build an Unit#morph
86
+ attr_accessor :spent_minerals
87
+
88
+ # @!attribute spent_vespene
89
+ # @see Unit#build and #morph
90
+ # @return [Integer] sum of vespene gas spent via Unit##build an Unit##morph
91
+ attr_accessor :spent_vespene
92
+
93
+ # @!attribute spent_supply
94
+ # @see Unit#build and #morph
95
+ # @return [Integer] sum of supply spent via Unit##build an Unit##morph
96
+ attr_accessor :spent_supply
97
+
98
+ def observation
99
+ @observation || Api::Observation.new(game_loop: 0)
100
+ end
101
+
102
+ def chats_received
103
+ @chats_received || []
104
+ end
105
+
106
+ # An alias for observation.player_common to allow easier access to i.e. common.minerals
107
+ # @return [Api::PlayerCommon] common info such as minerals, vespene, supply
108
+ def common
109
+ observation.player_common || Api::PlayerCommon.new(
110
+ player_id: 0,
111
+ minerals: 50,
112
+ vespene: 0,
113
+ food_cap: ((race == Api::Race::Zerg) ? 14 : 15),
114
+ food_used: 12,
115
+ food_army: 0,
116
+ food_workers: 12,
117
+ idle_worker_count: 0,
118
+ army_count: 0,
119
+ warp_gate_count: 0,
120
+ larva_count: ((race == Api::Race::Zerg) ? 3 : 0)
121
+ )
122
+ end
123
+
124
+ # class << self
125
+ # def included(_mod)
126
+ # @status = :unknown
127
+ # end
128
+ # end
129
+ end
130
+ end
131
+ end