sc2nachos 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. sc2nachos/__about__.py +2 -0
  2. sc2nachos/__init__.py +57 -0
  3. sc2nachos/_shared/__init__.py +4 -0
  4. sc2nachos/_shared/checks.py +18 -0
  5. sc2nachos/_shared/errors.py +10 -0
  6. sc2nachos/_shared/readable_int_enum.py +53 -0
  7. sc2nachos/_shared/rounding.py +11 -0
  8. sc2nachos/api/__init__.py +10 -0
  9. sc2nachos/api/_api.py +592 -0
  10. sc2nachos/api/_fog_off_playback.py +168 -0
  11. sc2nachos/api/_game.py +564 -0
  12. sc2nachos/camera/__init__.py +5 -0
  13. sc2nachos/camera/_camera.py +51 -0
  14. sc2nachos/debug/__init__.py +31 -0
  15. sc2nachos/debug/_cheat.py +27 -0
  16. sc2nachos/debug/_color.py +50 -0
  17. sc2nachos/debug/_debug_commands.py +355 -0
  18. sc2nachos/debug/_drawing.py +82 -0
  19. sc2nachos/debug/_marker.py +23 -0
  20. sc2nachos/debug/_shapes.py +273 -0
  21. sc2nachos/events/__init__.py +136 -0
  22. sc2nachos/events/_done.py +14 -0
  23. sc2nachos/events/_event.py +527 -0
  24. sc2nachos/events/_event_bus.py +282 -0
  25. sc2nachos/events/_event_filter.py +49 -0
  26. sc2nachos/events/_event_meta.py +16 -0
  27. sc2nachos/events/_event_priority.py +16 -0
  28. sc2nachos/events/_event_subscriber.py +77 -0
  29. sc2nachos/events/_event_subscriptions.py +166 -0
  30. sc2nachos/events/_handler.py +77 -0
  31. sc2nachos/events/_handler_timing.py +22 -0
  32. sc2nachos/extensions/__init__.py +5 -0
  33. sc2nachos/extensions/speed_mining.py +723 -0
  34. sc2nachos/extensions/upgrade_inference.py +164 -0
  35. sc2nachos/gamedata/__init__.py +34 -0
  36. sc2nachos/gamedata/_ability_data.py +359 -0
  37. sc2nachos/gamedata/_cost.py +75 -0
  38. sc2nachos/gamedata/_creep_requirement.py +15 -0
  39. sc2nachos/gamedata/_effect_data.py +30 -0
  40. sc2nachos/gamedata/_footprints.py +281 -0
  41. sc2nachos/gamedata/_game_data.py +294 -0
  42. sc2nachos/gamedata/_missing_attacks.py +152 -0
  43. sc2nachos/gamedata/_repair_steps.py +27 -0
  44. sc2nachos/gamedata/_resources.py +61 -0
  45. sc2nachos/gamedata/_sent_as.py +17 -0
  46. sc2nachos/gamedata/_tech.py +55 -0
  47. sc2nachos/gamedata/_tech_requirements.py +25 -0
  48. sc2nachos/gamedata/_techtree/__init__.py +40 -0
  49. sc2nachos/gamedata/_techtree/_build_75689.py +5125 -0
  50. sc2nachos/gamedata/_techtree/_overrides.py +354 -0
  51. sc2nachos/gamedata/_techtree/_tech_tree.py +109 -0
  52. sc2nachos/gamedata/_turning.py +125 -0
  53. sc2nachos/gamedata/_unit_type_data.py +344 -0
  54. sc2nachos/gamedata/_unit_type_upgrade.py +54 -0
  55. sc2nachos/gamedata/_upgrade_data.py +69 -0
  56. sc2nachos/gamemap/__init__.py +15 -0
  57. sc2nachos/gamemap/_errors.py +11 -0
  58. sc2nachos/gamemap/_expansion.py +358 -0
  59. sc2nachos/gamemap/_expansion_locations.py +76 -0
  60. sc2nachos/gamemap/_game_map.py +227 -0
  61. sc2nachos/gamemap/_image_data.py +38 -0
  62. sc2nachos/gamemap/_ramp.py +97 -0
  63. sc2nachos/gametime/__init__.py +20 -0
  64. sc2nachos/gametime/_game_speed.py +12 -0
  65. sc2nachos/gametime/_game_time.py +239 -0
  66. sc2nachos/gametime/_time_series.py +358 -0
  67. sc2nachos/geometry/__init__.py +28 -0
  68. sc2nachos/geometry/_area.py +71 -0
  69. sc2nachos/geometry/_circle.py +153 -0
  70. sc2nachos/geometry/_direction.py +41 -0
  71. sc2nachos/geometry/_footprint.py +163 -0
  72. sc2nachos/geometry/_grid.py +626 -0
  73. sc2nachos/geometry/_point.py +310 -0
  74. sc2nachos/geometry/_shapes.py +532 -0
  75. sc2nachos/geometry/_tile_path.py +114 -0
  76. sc2nachos/ids/__init__.py +21 -0
  77. sc2nachos/ids/_id_enum.py +76 -0
  78. sc2nachos/ids/ability.py +535 -0
  79. sc2nachos/ids/buff.py +73 -0
  80. sc2nachos/ids/effect.py +26 -0
  81. sc2nachos/ids/raw/__init__.py +15 -0
  82. sc2nachos/ids/raw/ability.py +4145 -0
  83. sc2nachos/ids/raw/buff.py +314 -0
  84. sc2nachos/ids/raw/effect.py +24 -0
  85. sc2nachos/ids/raw/unit_type.py +2016 -0
  86. sc2nachos/ids/raw/upgrade.py +317 -0
  87. sc2nachos/ids/unit_type.py +299 -0
  88. sc2nachos/ids/upgrade.py +101 -0
  89. sc2nachos/match/__init__.py +20 -0
  90. sc2nachos/match/_enemy.py +204 -0
  91. sc2nachos/match/_errors.py +7 -0
  92. sc2nachos/match/_match.py +111 -0
  93. sc2nachos/match/_player.py +59 -0
  94. sc2nachos/orders/__init__.py +9 -0
  95. sc2nachos/orders/_commands.py +68 -0
  96. sc2nachos/orders/_order.py +85 -0
  97. sc2nachos/orders/_order_book.py +413 -0
  98. sc2nachos/orders/_targets.py +67 -0
  99. sc2nachos/pathing/__init__.py +5 -0
  100. sc2nachos/pathing/_pathing.py +140 -0
  101. sc2nachos/placement/__init__.py +7 -0
  102. sc2nachos/placement/_build_sites.py +134 -0
  103. sc2nachos/placement/_placement_grids.py +306 -0
  104. sc2nachos/placement/_placement_reservation.py +75 -0
  105. sc2nachos/placement/_townhall_zones.py +30 -0
  106. sc2nachos/placement/_walls.py +119 -0
  107. sc2nachos/protocol/__init__.py +35 -0
  108. sc2nachos/protocol/_client.py +374 -0
  109. sc2nachos/protocol/_errors.py +24 -0
  110. sc2nachos/protocol/_permissive_playback_transport.py +163 -0
  111. sc2nachos/protocol/_ports.py +32 -0
  112. sc2nachos/protocol/_recording.py +201 -0
  113. sc2nachos/protocol/_status.py +20 -0
  114. sc2nachos/protocol/_transport.py +21 -0
  115. sc2nachos/protocol/_websocket.py +96 -0
  116. sc2nachos/run/__init__.py +31 -0
  117. sc2nachos/run/_command_line_arguments.py +168 -0
  118. sc2nachos/run/_game_process.py +169 -0
  119. sc2nachos/run/_installation.py +161 -0
  120. sc2nachos/run/_map_file.py +68 -0
  121. sc2nachos/run/_runners.py +465 -0
  122. sc2nachos/state/__init__.py +31 -0
  123. sc2nachos/state/_action_result.py +247 -0
  124. sc2nachos/state/_actions.py +168 -0
  125. sc2nachos/state/_alert.py +76 -0
  126. sc2nachos/state/_effect.py +43 -0
  127. sc2nachos/state/_in_production.py +41 -0
  128. sc2nachos/state/_production.py +129 -0
  129. sc2nachos/state/_research.py +32 -0
  130. sc2nachos/state/_score.py +160 -0
  131. sc2nachos/state/_state.py +140 -0
  132. sc2nachos/state/_supply.py +26 -0
  133. sc2nachos/state/_ui_unit_counts.py +19 -0
  134. sc2nachos/testing/__init__.py +8 -0
  135. sc2nachos/testing/_made_up_units.py +70 -0
  136. sc2nachos/testing/_shipped_game_data.py +31 -0
  137. sc2nachos/testing/_unit_report.py +160 -0
  138. sc2nachos/testing/game_data_75689.binpb.xz +0 -0
  139. sc2nachos/units/__init__.py +38 -0
  140. sc2nachos/units/_errors.py +11 -0
  141. sc2nachos/units/_own_unit.py +230 -0
  142. sc2nachos/units/_snapshot.py +21 -0
  143. sc2nachos/units/_tracking/__init__.py +6 -0
  144. sc2nachos/units/_tracking/_builder_tracker.py +171 -0
  145. sc2nachos/units/_tracking/_tracker.py +108 -0
  146. sc2nachos/units/_tracking/_tracker_changes.py +104 -0
  147. sc2nachos/units/_tracking/_unit_comparer.py +119 -0
  148. sc2nachos/units/_tracking/_unit_tracker.py +379 -0
  149. sc2nachos/units/_tracking/_unit_watcher.py +80 -0
  150. sc2nachos/units/_tracking/_upgrade_level_reader.py +79 -0
  151. sc2nachos/units/_tracking/_upgrade_tracker.py +101 -0
  152. sc2nachos/units/_tracking/_watches.py +184 -0
  153. sc2nachos/units/_unit.py +990 -0
  154. sc2nachos/units/_unit_dict.py +149 -0
  155. sc2nachos/units/_unit_type.py +1098 -0
  156. sc2nachos/units/_units.py +521 -0
  157. sc2nachos/units/_values.py +202 -0
  158. sc2nachos-0.1.0.dist-info/METADATA +188 -0
  159. sc2nachos-0.1.0.dist-info/RECORD +162 -0
  160. sc2nachos-0.1.0.dist-info/WHEEL +4 -0
  161. sc2nachos-0.1.0.dist-info/licenses/LICENSE +21 -0
  162. sc2nachos-0.1.0.dist-info/licenses/NOTICE +47 -0
sc2nachos/__about__.py ADDED
@@ -0,0 +1,2 @@
1
+ # Written by hatch-vcs from the git tag at build time; not tracked.
2
+ __version__ = "0.1.0"
sc2nachos/__init__.py ADDED
@@ -0,0 +1,57 @@
1
+ """NachOS — an event-driven StarCraft II bot API for Python.
2
+
3
+ A bot makes one `Api`, subscribes handlers to the events a game hands out with `Api.on`, and plays through a runner:
4
+ `run_local` against the built-in computer, or `run_from_command_line` for the ladder and local games alike. Each turn
5
+ it reads its units from `Api.units` and orders them through `Api.orders`.
6
+
7
+ The [README](https://github.com/maxnus/NachOS#readme) says how to get started and lists the guides.
8
+ """
9
+
10
+ from sc2nachos.__about__ import __version__
11
+ from sc2nachos._shared.errors import NachOSError
12
+ from sc2nachos.api import Api, FogOnError, NoEnemyError, NotPlayingError
13
+ from sc2nachos.gamedata import Cost, Resources
14
+ from sc2nachos.gamemap import Expansion, StartLocation
15
+ from sc2nachos.gametime import GameTime
16
+ from sc2nachos.geometry import Circle, Footprint, Point, Rectangle
17
+ from sc2nachos.ids import AbilityId, BuffId, UnitTypeId, UpgradeId
18
+ from sc2nachos.match import AIBuild, Computer, Difficulty, Race, Result
19
+ from sc2nachos.run import run_from_command_line, run_ladder, run_local, run_recording, run_replay
20
+ from sc2nachos.units import OwnUnit, Unit, UnitDict, Units, UnitType
21
+
22
+ __all__ = [
23
+ "AIBuild",
24
+ "AbilityId",
25
+ "Api",
26
+ "BuffId",
27
+ "Circle",
28
+ "Computer",
29
+ "Cost",
30
+ "Difficulty",
31
+ "Expansion",
32
+ "FogOnError",
33
+ "Footprint",
34
+ "GameTime",
35
+ "NachOSError",
36
+ "NoEnemyError",
37
+ "NotPlayingError",
38
+ "OwnUnit",
39
+ "Point",
40
+ "Race",
41
+ "Rectangle",
42
+ "Resources",
43
+ "Result",
44
+ "StartLocation",
45
+ "Unit",
46
+ "UnitDict",
47
+ "UnitType",
48
+ "UnitTypeId",
49
+ "Units",
50
+ "UpgradeId",
51
+ "__version__",
52
+ "run_from_command_line",
53
+ "run_ladder",
54
+ "run_local",
55
+ "run_recording",
56
+ "run_replay",
57
+ ]
@@ -0,0 +1,4 @@
1
+ """What NachOS's own modules share: the base of its errors, its enums' base, argument checks and rounding.
2
+
3
+ It imports nothing else of NachOS, so that any module can import it.
4
+ """
@@ -0,0 +1,18 @@
1
+ """Checks that the arguments of several modules share."""
2
+
3
+ from numbers import Integral
4
+ from pathlib import Path
5
+
6
+
7
+ def is_whole_number(value: object) -> bool:
8
+ """Whether `value` is a whole number, and not a `bool`."""
9
+ return isinstance(value, Integral) and not isinstance(value, bool)
10
+
11
+
12
+ def check_file_to_write(path: Path, purpose: str) -> None:
13
+ """Raise `FileNotFoundError` if `path` is in no folder that exists, and `IsADirectoryError` if it is a folder. Each
14
+ message ends with `purpose`, what the file is for: "record into"."""
15
+ if not path.parent.is_dir():
16
+ raise FileNotFoundError(f"there is no folder {path.parent} to {purpose}")
17
+ if path.is_dir():
18
+ raise IsADirectoryError(f"{path} is a folder, not a file to {purpose}")
@@ -0,0 +1,10 @@
1
+ """The base of the exceptions the library raises for its own failures, and the errors more than one package raises."""
2
+
3
+
4
+ class NachOSError(Exception):
5
+ """A failure of the library's own. Misuse, such as a bad argument, raises a built-in instead."""
6
+
7
+
8
+ class NotReportedError(NachOSError, LookupError):
9
+ """The game has not reported what was asked: a field of a unit it has never shown visible, or which start location
10
+ the enemy took on a map with more than two."""
@@ -0,0 +1,53 @@
1
+ """Base class for the package's enums."""
2
+
3
+ from enum import IntEnum
4
+ from typing import Self, cast
5
+
6
+ from sc2nachos._shared.errors import NachOSError
7
+
8
+
9
+ class UnknownValueError(NachOSError, ValueError):
10
+ """The game reported a value the enum has no member for."""
11
+
12
+ def __init__(self, enum: "type[ReadableIntEnum]", value: int) -> None:
13
+ super().__init__(f"{enum.__name__} has no member for {value}")
14
+ self.enum = enum
15
+ self.value = value
16
+
17
+
18
+ class ReadableIntEnum(IntEnum):
19
+ """An `IntEnum` that prints as its name, not its value, and reads values the game reports.
20
+
21
+ An explicit format spec still formats the integer.
22
+ """
23
+
24
+ def __str__(self) -> str:
25
+ return f"{type(self).__name__}.{self.name}"
26
+
27
+ def __repr__(self) -> str:
28
+ return f"<{type(self).__name__}.{self.name}: {self.value}>"
29
+
30
+ def __format__(self, format_spec: str) -> str:
31
+ if format_spec:
32
+ return int.__format__(int(self), format_spec)
33
+ return str(self)
34
+
35
+ @classmethod
36
+ def read(cls, value: int) -> Self:
37
+ """The member for `value`. Raises `UnknownValueError` if the enum has none."""
38
+ # The enum's own value-to-member map: under half the time of calling the enum.
39
+ if (member := cls._value2member_map_.get(value)) is None:
40
+ raise cls._unknown(value)
41
+ return cast("Self", member)
42
+
43
+ @classmethod
44
+ def get(cls, value: int) -> Self | None:
45
+ """The member for `value`, or `None` if `value` is zero or the enum has no member for it."""
46
+ if not value:
47
+ return None
48
+ return cast("Self | None", cls._value2member_map_.get(value))
49
+
50
+ @classmethod
51
+ def _unknown(cls, value: int) -> UnknownValueError:
52
+ """The error `read` raises. An enum overrides it to say where the value should have come from."""
53
+ return UnknownValueError(cls, value)
@@ -0,0 +1,11 @@
1
+ """Rounding that several modules share."""
2
+
3
+ import math
4
+
5
+
6
+ def rounded_half_up(value: float) -> int:
7
+ """`value` rounded to the nearest integer, a tie up, toward the larger one, where Python's `round` takes the even
8
+ one. Raises `OverflowError` for an infinity and `ValueError` for a NaN, as `math.floor` does."""
9
+ # Not `math.floor(value + 0.5)`: the addition itself rounds, taking 0.49999999999999994 to 1.0.
10
+ floored = math.floor(value)
11
+ return floored + (value - floored >= 0.5)
@@ -0,0 +1,10 @@
1
+ """Everything a bot talks to."""
2
+
3
+ from sc2nachos.api._api import Api, FogOnError, NoEnemyError, NotPlayingError
4
+
5
+ __all__ = [
6
+ "Api",
7
+ "FogOnError",
8
+ "NoEnemyError",
9
+ "NotPlayingError",
10
+ ]