Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install ruff and pyre #199

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ mini_games/
/htmlcov

/docs

.pyre
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ repos:
- id: python-no-log-warn
# Enforce type annotation instead of comment annotation
- id: python-use-type-annotations

- repo: local
hooks:
# Autoformat code
- id: ruff-format-check
name: Check if files are formatted
stages: [push]
language: system
entry: poetry run ruff format . --check --diff
pass_filenames: false

- id: ruff-lint
name: Lint files
stages: [push]
language: system
entry: poetry run ruff check .
pass_filenames: false

- id: pyre
name: Static types checking with pyre
stages: [push]
language: system
entry: poetry run pyre
pass_filenames: false
6 changes: 6 additions & 0 deletions .pyre_configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"site_package_search_strategy": "pep561",
"source_directories": [
"."
]
}
6 changes: 4 additions & 2 deletions docs_generate/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import os
import sys

sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, os.path.abspath("..")) # noqa: PTH100

import sphinx_rtd_theme # nopycln: import
import sphinx_rtd_theme

sphinx_rtd_theme # Add statement to keep unused import

# -- Project information -----------------------------------------------------

Expand Down
9 changes: 4 additions & 5 deletions examples/arcade_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@


class MarineSplitChallenge(BotAI):

async def on_start(self):
await self.chat_send("Edit this message for automatic chat commands.")
self.client.game_step = 2

async def on_step(self, iteration):
# do marine micro vs zerglings
for unit in self.units(UnitTypeId.MARINE):

if self.enemy_units:

# attack (or move towards) zerglings / banelings
if unit.weapon_cooldown <= self.client.game_step / 2:
enemies_in_range = self.enemy_units.filter(unit.target_in_range)
Expand All @@ -57,7 +54,8 @@ async def on_step(self, iteration):
# Use stimpack
if (
self.already_pending_upgrade(UpgradeId.STIMPACK) == 1
and not unit.has_buff(BuffId.STIMPACK) and unit.health > 10
and not unit.has_buff(BuffId.STIMPACK)
and unit.health > 10
):
unit(AbilityId.EFFECT_STIM)

Expand Down Expand Up @@ -105,7 +103,8 @@ def position_around_unit(
pos = pos.position.rounded
positions = {
pos.offset(Point2((x, y)))
for x in range(-distance, distance + 1, step_size) for y in range(-distance, distance + 1, step_size)
for x in range(-distance, distance + 1, step_size)
for y in range(-distance, distance + 1, step_size)
if (x, y) != (0, 0)
}
# filter positions outside map size
Expand Down
9 changes: 3 additions & 6 deletions examples/competitive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import sc2
from sc2.client import Client
from sc2.protocol import ConnectionAlreadyClosed
from sc2.protocol import ConnectionAlreadyClosedError


# Run ladder game
Expand All @@ -26,10 +26,7 @@ def run_ladder_game(bot):
parser.add_argument("--RealTime", action="store_true", help="Real time flag")
args, _unknown = parser.parse_known_args()

if args.LadderServer is None:
host = "127.0.0.1"
else:
host = args.LadderServer
host = "127.0.0.1" if args.LadderServer is None else args.LadderServer

host_port = args.GamePort
lan_port = args.StartPort
Expand Down Expand Up @@ -68,7 +65,7 @@ async def join_ladder_game(host, port, players, realtime, portconfig, save_repla
await client.save_replay(save_replay_as)
# await client.leave()
# await client.quit()
except ConnectionAlreadyClosed:
except ConnectionAlreadyClosedError:
logger.error("Connection was closed before the game ended")
return None
finally:
Expand Down
1 change: 0 additions & 1 deletion examples/competitive/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class CompetitiveBot(BotAI):

async def on_start(self):
print("Game started")
# Do things here before the game starts
Expand Down
1 change: 0 additions & 1 deletion examples/distributed_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class TerranBot(BotAI):

async def on_step(self, iteration):
await self.distribute_workers()
await self.build_supply()
Expand Down
3 changes: 1 addition & 2 deletions examples/observer_easy_vs_easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
def main():
run_game(
maps.get("Abyssal Reef LE"),
[Bot(Race.Protoss, CannonRushBot()),
Computer(Race.Protoss, Difficulty.Medium)],
[Bot(Race.Protoss, CannonRushBot()), Computer(Race.Protoss, Difficulty.Medium)],
realtime=True,
)

Expand Down
4 changes: 1 addition & 3 deletions examples/protoss/cannon_rush.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class CannonRushBot(BotAI):

# pylint: disable=R0912
async def on_step(self, iteration):
if iteration == 0:
Expand Down Expand Up @@ -64,8 +63,7 @@ async def on_step(self, iteration):
def main():
run_game(
maps.get("(2)CatalystLE"),
[Bot(Race.Protoss, CannonRushBot(), name="CheeseCannon"),
Computer(Race.Protoss, Difficulty.Medium)],
[Bot(Race.Protoss, CannonRushBot(), name="CheeseCannon"), Computer(Race.Protoss, Difficulty.Medium)],
realtime=False,
)

Expand Down
4 changes: 1 addition & 3 deletions examples/protoss/find_adept_shades.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# pylint: disable=W0231
class FindAdeptShadesBot(BotAI):

def __init__(self):
self.shaded = False
self.shades_mapping = {}
Expand Down Expand Up @@ -60,8 +59,7 @@ async def on_step(self, iteration: int):
def main():
run_game(
maps.get("(2)CatalystLE"),
[Bot(Race.Protoss, FindAdeptShadesBot()),
Computer(Race.Protoss, Difficulty.Medium)],
[Bot(Race.Protoss, FindAdeptShadesBot()), Computer(Race.Protoss, Difficulty.Medium)],
realtime=False,
)

Expand Down
15 changes: 8 additions & 7 deletions examples/protoss/threebase_voidray.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class ThreebaseVoidrayBot(BotAI):

# pylint: disable=R0912
async def on_step(self, iteration):
target_base_count = 3
Expand Down Expand Up @@ -54,8 +53,11 @@ async def on_step(self, iteration):

# If we are low on supply, build pylon
if (
self.supply_left < 2 and self.already_pending(UnitTypeId.PYLON) == 0
or self.supply_used > 15 and self.supply_left < 4 and self.already_pending(UnitTypeId.PYLON) < 2
self.supply_left < 2
and self.already_pending(UnitTypeId.PYLON) == 0
or self.supply_used > 15
and self.supply_left < 4
and self.already_pending(UnitTypeId.PYLON) < 2
):
# Always check if you can afford something before you build it
if self.can_afford(UnitTypeId.PYLON):
Expand Down Expand Up @@ -109,8 +111,8 @@ async def on_step(self, iteration):
pylon = self.structures(UnitTypeId.PYLON).ready.random
if (
self.townhalls.ready.amount + self.already_pending(UnitTypeId.NEXUS) >= target_base_count
and self.structures(UnitTypeId.STARGATE).ready.amount + self.already_pending(UnitTypeId.STARGATE) <
target_stargate_count
and self.structures(UnitTypeId.STARGATE).ready.amount + self.already_pending(UnitTypeId.STARGATE)
< target_stargate_count
):
if self.can_afford(UnitTypeId.STARGATE):
await self.build(UnitTypeId.STARGATE, near=pylon)
Expand All @@ -125,8 +127,7 @@ async def on_step(self, iteration):
def main():
run_game(
maps.get("(2)CatalystLE"),
[Bot(Race.Protoss, ThreebaseVoidrayBot()),
Computer(Race.Protoss, Difficulty.Easy)],
[Bot(Race.Protoss, ThreebaseVoidrayBot()), Computer(Race.Protoss, Difficulty.Easy)],
realtime=False,
)

Expand Down
7 changes: 4 additions & 3 deletions examples/protoss/warpgate_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

# pylint: disable=W0231
class WarpGateBot(BotAI):

def __init__(self):
# Initialize inherited class
self.proxy_built = False
Expand Down Expand Up @@ -92,7 +91,8 @@ async def on_step(self, iteration):

# Research warp gate if cybercore is completed
if (
self.structures(UnitTypeId.CYBERNETICSCORE).ready and self.can_afford(AbilityId.RESEARCH_WARPGATE)
self.structures(UnitTypeId.CYBERNETICSCORE).ready
and self.can_afford(AbilityId.RESEARCH_WARPGATE)
and self.already_pending_upgrade(UpgradeId.WARPGATERESEARCH) == 0
):
ccore = self.structures(UnitTypeId.CYBERNETICSCORE).ready.first
Expand All @@ -118,7 +118,8 @@ async def on_step(self, iteration):

# Build proxy pylon
if (
self.structures(UnitTypeId.CYBERNETICSCORE).amount >= 1 and not self.proxy_built
self.structures(UnitTypeId.CYBERNETICSCORE).amount >= 1
and not self.proxy_built
and self.can_afford(UnitTypeId.PYLON)
):
p = self.game_info.map_center.towards(self.enemy_start_locations[0], 20)
Expand Down
9 changes: 3 additions & 6 deletions examples/simulate_fight_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class FightBot(BotAI):

def __init__(self):
super().__init__()
self.enemy_location: Point2 = None
Expand Down Expand Up @@ -48,16 +47,14 @@ async def reset_arena(self):
await self.client.debug_create_unit(
[
[UnitTypeId.SUPPLYDEPOT, 1, self.enemy_location, OPPONENT_PLAYER_ID],
[UnitTypeId.MARINE, 4,
self.enemy_location.towards(self.start_location, 8), OPPONENT_PLAYER_ID]
[UnitTypeId.MARINE, 4, self.enemy_location.towards(self.start_location, 8), OPPONENT_PLAYER_ID],
]
)

await self.client.debug_create_unit(
[
[UnitTypeId.SUPPLYDEPOT, 1, self.start_location, MY_PLAYER_ID],
[UnitTypeId.MARINE, 4,
self.start_location.towards(self.enemy_location, 8), MY_PLAYER_ID]
[UnitTypeId.MARINE, 4, self.start_location.towards(self.enemy_location, 8), MY_PLAYER_ID],
]
)

Expand All @@ -81,7 +78,7 @@ def main():
maps.get("Flat64"),
# NOTE: you can have two bots fighting with each other here
[Bot(Race.Terran, FightBot()), Computer(Race.Terran, Difficulty.Medium)],
realtime=True
realtime=True,
)


Expand Down
6 changes: 3 additions & 3 deletions examples/terran/cyclone_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class CyclonePush(BotAI):

def select_target(self) -> Point2:
# Pick a random enemy structure's position
targets = self.enemy_structures
Expand All @@ -23,7 +22,7 @@ def select_target(self) -> Point2:
return targets.random.position

# Pick enemy start location if it has no friendly units nearby
if min((unit.distance_to(self.enemy_start_locations[0]) for unit in self.units)) > 5:
if min(unit.distance_to(self.enemy_start_locations[0]) for unit in self.units) > 5:
return self.enemy_start_locations[0]

# Pick a random mineral field on the map
Expand Down Expand Up @@ -58,7 +57,8 @@ async def on_step(self, iteration):
# While we have less than 22 workers: build more
# Check if we can afford them (by minerals and by supply)
if (
self.can_afford(UnitTypeId.SCV) and self.supply_workers + self.already_pending(UnitTypeId.SCV) < 22
self.can_afford(UnitTypeId.SCV)
and self.supply_workers + self.already_pending(UnitTypeId.SCV) < 22
and cc.is_idle
):
cc.train(UnitTypeId.SCV)
Expand Down
Loading
Loading