Git Product home page Git Product logo

sharpy-sc2's Introduction

sharpy-sc2

Sharpy is a Python framework for rapid development of Starcraft 2 AI bots.

Sharpy is built on top of python-sc2 and it is the framework used by Sharpened Edge bot.

Sharpy was created to make it as easy as possible to create practice dummies for testing against Sharpened Edge. Sharpy contains everything needed to run all the practise dummies, as well as means to create more.

Sharpy is a work in progress. The folder structure and classes are subject to change.

Build statuses

Master branch

Develop branch

Requirements

  1. Python 3.8/3.9/3.11 64-bit
    • Python-sc2 requires python 3.8
    • 64-bit requirement comes from sc2-pathlib as the pathlib is built for 64-bit python 3.8/3.9/3.11
  2. Windows, Linux or MacOS
    • This requirement comes from sc2-pathlib
    • macOS should be supported, but I have no way to test it sc2-pathlib is built for it.

Ladder Dummy Bots

To build dummy bots for ladder, run ladder_zip.py. Bots will appear as individual zip files in publish folder.

Getting started

Read the getting started guide in wiki.

Contributing

To contribute to sharpy-sc2 source code, please create a pull request.

We also appreciate well written issues, comments and improvements to project wiki.

Pull Request Process

  • Keep pull requests small and atomic. Change only one logical thing at a time.
  • If you do a pull request for unit micro, showcase it with a dummy bot and explain how it improves the previous implementation
  • All Github actions checks for the PR must pass before it will be reviewed.
    • Make sure that the source code is formatted according to rules (see below)
    • Make sure that the source code passes linting
    • Make sure that all tests pass

Developing sharpy-sc2

Using Virtual Environment

Windows

Virtual Environments (venv) can be used to isolate this project's Python dependencies from other projects.

You can create a virtual environment for this project with

venv-create.bat

And activate it with

venv-activate.bat

Venv needs to be activated for every new console window, so it may be helpful to create an alias such as

doskey sharpy=cd C:\Dev\sharpy-sc2 $T venv-activate.bat

More information about virtual environments can be found from the documentation.

Other operating systems

You may replicate the commands used by the above bat scripts to work on your own operating system.

Installing Depedencies

To install all dependencies required to run the bots, use

pip install -r requirements.txt

To install all development dependencies, use

pip install -r requirements.dev.txt

Pre-commit hooks

To install git pre-commit hooks that will run black and flake8 (see below), use

pre-commit install

If you ever want to uninstall the hooks, use

pre-commit uninstall

or simply uninstall the .git\hooks\pre-commit file.

Code Formatting

sharpy-sc2 uses Black for automatic Python source code formatting.

to format code automatically, run

> py -m black .
All done! ✨ � ✨
272 files left unchanged.

Black can also be integrated to your favorite editor. See Editor Integration section in Black readme.

Linting

sharpy-sc2 uses flake8 for source code linting.

To run flake8 linting, use

> py -m flake8
0

Running Tests

Tests are written using pytest framework.

To run all tests, use

pytest

To run tests from a single test file, use pytest path-to-file eg.

pytest sharpy\knowledges\knowledge_test.py

pytest follows standard test discovery rules and will run all tests in the current directory and its subdirectories.

For new tests, make sure that...

  1. file name follows the naming pattern of *_test.py
  2. the test class name starts with Test*
  3. all test methods start with test_*.

sharpy-sc2's People

Contributors

ammo-sc2 avatar burnysc2 avatar dependabot-preview[bot] avatar drinfy avatar duncandhall avatar eladyaniv01 avatar jacobols avatar lladdy avatar m1ndgames avatar merfolk avatar raspersc2 avatar soupcatcher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharpy-sc2's Issues

Void Rays are losing DPS because they stutter step

Measure dps when stutter stepping and calculate much dps is lost by stuttering and how much the voidray can move while doing so.

Void rays should still move when they are in a bad position, but they should only reposition when a clearly better position is available in order to maximize damage.

Add Auto turrets to raven micro

Is your feature request related to a problem? Please describe.
Safe raven TvT bot opens up with raven and dies to marine pushe with the raven not using any energy.

Describe the solution you'd like
Use auto turrets on small scale fights. Unsure on how to look for turret placement positions.

Additional context

generally 'when attacking: place them offensively (next to enemy tanks)' and 'when defending: place defensively in a retreating manner'
well at least for tvt
i dont think autoturrets are very good in the other matchups
there is also raven autoturret harass for killing workers

Proposition for extending micro

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

With the current architecture it is no good way to extend or change the micro. One either has create a new class for it with no way of just extending what is currently implemented without overwriting.

Describe the solution you'd like
I want an architecture where I can for each unit type add or remove micro solvers without modifying the sharpy library.

Describe alternatives you've considered
I propose changing the group_combat_manager to have a list of solvers that are executed in order. These solvers contains the functions group_solve_combat and unit_solve_combat that will be executed in order. The functions return either an Action or None depending if they are triggered or are doing blocking actions like burrow or siege. This way the developer could easily reuse code with many simple solvers or have one complex solver.

To optimize, I suggest that the StepMicro is sent as an additional parameter to the unit_solve_combat so this information is only calculated once for each group.

A function to add and one to overwrite the list assigned by default for each unit_type would make it more developer friendly to use.

I considered modifying MicroStep instead of the manager, but it feel more right to keep it in the manager.

flake8 ignores exclude configuration when used through pre-commit hooks

Describe the bug
When sharpy-sc2's pre-commit hooks are installed, flake8 will ignore excludes configured in .flake8 file.

This is by design, and pre-commits exclude should be used instead.

Checked-in python files will be passed as positional arguments. flake8 will always lint explicitly passed arguments (flake8 --exclude has no effect). Instead use pre-commit’s exclude: ... regex to exclude files. pre-commit won’t ever pass untracked files to flake8 so excluding .git / .tox / etc. is unnecessary.

https://flake8.pycqa.org/en/latest/user/using-hooks.html

Expected behavior
Flake8 should work in similar way, whether launched with eg. py -m flake8 or by the pre-commit hooks (installed by pre-commit install).

Additional context

sharpy-sc2 repo already contains multiple config files with the same excludes.

  1. .flake8
  2. pyproject.toml for Black config
  3. pytest.ini

Adding a fourth file with the same excluded directories would be... less than ideal.

Add mechanism for requesting manager by name or type

sharpy provides a mechanism for registering new managers by overriding KnowledgeBot.configure_managers(self) -> Optional[List[ManagerBase]]).

The additional managers are then passed to Knowledge.pre_start(...)

Sharpy's internal managers are available through hard coded properties in Knowledge. However, there's no easy mechanism for accessing the added managers.

Describe the solution you'd like

Save all managers to eg. a Dict instead of a List in Knowledge.

Add a new method to Knowledge and/or KnowledgeBot, that can be used to get an added manager by eg. EITHER it's name as a string OR the manager type.

Using type as key has the benefit of some "compile-time" checks. It prevents adding multiple instances of the same manager (probably not needed).

Using string as key has the con that errors are only detected at runtime, resulting in a longer feedback loop. It has the added benefit of allowing multiple instances of the same manager to be added (probably not needed).

Also, please update relevant Wiki docs, including at least Extending Managers.

Additional information

It's important to preserve the order of sharpy's own managers, because the order affects how they are updated.

Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end.

Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.

source: https://docs.python.org/3.7/library/stdtypes.html#dict.values

Rename acts and requirements to be simpler

Is your feature request related to a problem? Please describe.
Build orders are needlessly verbose and some of them are obvious without the need to have Required or Act in the name.

Describe the solution you'd like

Rename and deprecate old

ActBuildAddon -> BuildAddon
ActDefensiveCannons -> DefensiveCannons
ActExpand -> Expand
ActTech -> Tech
ActWarpUnit -> WarpUnit
ChronoUnitProduction -> ChronoUnit
RequiredEnemyBuildingExists -> EnemyBuildingExists
RequiredEnemyUnitExistsAfter -> EnemyUnitExistsAfter
RequiredAny ->Any
RequiredAll -> All
RequiredUnitReady -> UnitReady
RequiredMinerals -> Minerals
RequiredGas -> Vespene
RequiredCount -> Count
RequiredEnemyBases -> EnemyBases
RequiredSupply -> Supply
RequiredSupplyLeft -> SupplyLeft
RequiredTechReady -> TechReady
RequiredTime -> Time
RequiredTotalUnitExists -> TotalUnitExists
StepBuildGas -> BuildGas (Remove Step functionality)

Deprecate

RoboUnit
GateUnit
StarUnit
RequiredLessUnitExists

Delete

RequiredTotalUnitExists
ActMany
RequiredLessUnitExists

Make sharpy compatible with multiple SC2 versions

somewhere should be a function called ping

Version can be get from the ping. Make some hacks in ActUpgrade to skip upgrades that don't exist in 4.10.

Reconfigure ALL_GAS in python-sc2 to ids in 4.10

Default micro for Liberator

Is your feature request related to a problem? Please describe.
Liberators just fly in and die against ground units

Describe the solution you'd like
Siege the liberator in a reasonable way.

Cyclone bot crashes

Describe the bug
Cyclone bot crashes when I try to run it.

To Reproduce

  1. Run py run_custom.py -p1 cyclone
  2. Observe crash
ERROR:sc2.main:AI on_start threw an error
Traceback (most recent call last):
  File "python-sc2\sc2\main.py", line 115, in _play_game_ai
    await ai.on_start()
  File "C:\Dev\sc2\sharpy-sc2\sharpy\knowledges\knowledge_bot.py", line 97, in on_start
    await self.real_init()
  File "C:\Dev\sc2\sharpy-sc2\sharpy\knowledges\knowledge_bot.py", line 35, in real_init
    self.plan = await self.create_plan()
  File "C:\Dev\sc2\sharpy-sc2\dummies\terran\cyclones.py", line 58, in create_plan
    ActTech(UpgradeId.TERRANVEHICLEANDSHIPARMORSLEVEL1),
  File "C:\Dev\sc2\sharpy-sc2\sharpy\plans\acts\act_tech.py", line 34, in __init__
    from_building = UPGRADE_RESEARCHED_FROM[self.upgrade_type]
KeyError: UpgradeId.TERRANVEHICLEANDSHIPARMORSLEVEL1

Expected behavior
A game should run.

Version

> git last
commit 88e9287bd63caae6fc342f0eb0278d1d55355919 (HEAD -> develop, origin/develop)

only_once optional parameter for BuildAddon()

BuRny:

i think an only_once optional parameter for BuildAddon() would be good, with the addon swaps, otherwise it gets stuck in a sequential build order if a barracks has a reactor but should build a techlab

Disruptor shot improvements

Disruptor shots will stop in the middle of own army if no enemy is seen, shots should instead continue in the direction the were going to in the first place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.