Skip to content
Snippets Groups Projects
Commit 71f4164f authored by Daniel de Leng's avatar Daniel de Leng
Browse files

Merge branch 'python12_update'

parents eebe2017 6f202761
No related branches found
No related tags found
No related merge requests found
Pipeline #133146 passed
build/
.idea
venv
.venv
.vs
.vscode
__pycache__
.DS_Store
\ No newline at end of file
variables:
GIT_SUBMODULE_STRATEGY: recursive
image: gitlab.liu.se:5000/starcraft-ai-course/pycommandcenter
pages:
image: gitlab.liu.se:5000/starcraft-ai-course/pycommandcenter
stage: deploy
stages:
- compile
- deploy
compile:
variables:
GIT_SUBMODULE_STRATEGY: recursive
stage: compile
script:
- mkdir build
- cd build
- cmake ..
- make library
- cd ../docs
- python3 library_import_check.py
- make commandcenter
artifacts:
paths:
- docs
- build
- scripts/generate_pydocs.py
expire_in: 10 minutes
only:
- master
pages:
variables:
GIT_STRATEGY: none
GIT_CHECKOUT: false
stage: deploy
script:
- cd docs
- python3 -c "import sys, os, conf, commandcenter"
- make html
- cd ..
- mkdir public
......@@ -20,3 +39,20 @@ pages:
- public
only:
- master
pack-linux:
variables:
GIT_STRATEGY: none
GIT_CHECKOUT: false
stage: deploy
script:
- cd build/python-api-src
- stubgen -m commandcenter -o .
- cd ../..
- python3 scripts/generate_pydocs.py
artifacts:
paths:
- build/python-api-src/commandcenter.cpython-312-x86_64-linux-gnu.so
- build/python-api-src/commandcenter.pyi
only:
- master
......@@ -23,6 +23,6 @@ We can access m_unit in the unit file and with sc2::Function() we can access any
Common problems:
1. The return in python is a memory address:
Make sure that it returns a correct type.
Make sure that it returns a correct type.
2. The compiler complains about files I have not even touched:
Make sure that the startUp is library and you have release x64. If you just added a new function in pybind, check it.
MIT License
Copyright (c) 2018 David Bergström
Copyright (c) 2024 Daniel de Leng
Copyright (c) 2018 Jonas Kvarnström, David Bergström
Copyright (c) 2017 David Churchill
Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -23,7 +23,7 @@ Key differences:
``` python
import os
from library import *
from commandcenter import *
class MyAgent(IDABot):
......@@ -95,15 +95,28 @@ Make sure you have mypy installed. This can be done with:
```terminal
pip3 install -r requirements.txt
```
Navigate to where your library.pyd/so is located then run:
Navigate to where your commandcenter.pyd/so is located then run:
```terminal
stubgen -m library -o .
stubgen -m commandcenter -o .
```
NOTE: stubgen might not work on windows unless you have an active python venv.
After creating the .pyi file run the generate_pydocs.py file according to the instructions in that file.
# How to use the library with PyCharm
See [separate page](pycharm.md).
Start by downloading the library. Click the latest tag in the [PyCommandCenter repository](https://gitlab.liu.se/starcraft-ai-course/pycommandcenter/-/tags) and find a `.pyd` link at the bottom of the tag page.
Place the library in your repository.
Add the library to the Python path in Python by:
1. File->Settings->Project: (project name)->Project Interpreter.
2. Select the cog in the upper right corner and select "Show All".
3. In the new window that opens, select the icon which shows a few folders connected with lines.
4. In the new window, first press the plus icon, and then select the path of your repository (the path to where you placed the library).
5. Restart PyCharm with "File->Invalidate Caches/Restart->Invalidate and Restart".
# Building the documentation
......@@ -127,7 +140,7 @@ See [separate page](pycharm.md).
# Credits
PyCommandCenter is written and maintained for Linköping University through various contributors over the years. In alphabetical ordering, these include: Sofia Abaied, Dawid Lukasz Abucewicz, Anton Andell, Erik Ahlroth, David Bergström, Edvin Bergström, Emil Brynielsson, Stefan Brynielsson, Ludvig Fors, Hannes Jämtner, Jonas Kvarnström, Daniel de Leng, Fredrik Präntare, Gabriel Tofvesson, David Warnquist, Jonathan Öhrling. Feedback was provided by the teachers and students of TDDD63, TDDE25, and TDDD92.
PyCommandCenter is written and maintained for Linköping University through various contributors over the years. In alphabetical ordering, these include: Sofia Abaied, Dawid Lukasz Abucewicz, Anton Andell, Erik Ahlroth, David Bergström, Edvin Bergström, Jonas Bonnaudet, Emil Brynielsson, Stefan Brynielsson, Ludvig Fors, Hannes Jämtner, Jonas Kvarnström, Daniel de Leng, Fredrik Präntare, Gabriel Tofvesson, David Warnquist, Jonathan Öhrling. Feedback was provided by the teachers and students of TDDD63, TDDE25, and TDDD92.
CommandCenter is written by [David Churchill](http://www.cs.mun.ca/~dchurchill/), Assistant Professor of [Computer Science](https://www.cs.mun.ca/) at Memorial University, and organizer of the [AIIDE StarCraft AI
Competition](http://www.cs.mun.ca/~dchurchill/starcraftaicomp/).
......
......@@ -4,6 +4,7 @@ FROM ubuntu:24.04
LABEL org.opencontainers.image.authors="daniel.de.leng@liu.se"
RUN apt update && apt install -y build-essential cmake python3-full python3-pybind11 python3-pip python3-sphinx python3-sphinx-design
RUN pip3 install mypy==1.10.0 --break-system-packages # Workaround for python3-mypy having outdated version <1.10.0
ENV HOME=/root
WORKDIR /root
......@@ -22,11 +22,11 @@ sys.path.append(os.getcwd())
# -- Project information -----------------------------------------------------
project = 'PyCommandCenter'
copyright = '2018, David Bergström'
author = 'David Bergström'
copyright = '2024 Reasoning and Learning Lab, Linköping University'
author = 'Sofia Abaied, Dawid Lukasz Abucewicz, Anton Andell, Erik Ahlroth, David Bergström, Edvin Bergström, Emil Brynielsson, Stefan Brynielsson, Ludvig Fors, Hannes Jämtner, Jonas Kvarnström, Daniel de Leng, Fredrik Präntare, Gabriel Tofvesson, David Warnquist, Jonathan Öhrling'
# The short X.Y version
version = ''
version = '2.0'
# The full version, including alpha/beta/rc tags
release = ''
......
......@@ -10,10 +10,10 @@ Player constants
The following constants are used when referring to a player:
.. autoclass:: library.PLAYER_SELF
.. autoclass:: library.PLAYER_ENEMY
.. autoclass:: library.PLAYER_NEUTRAL
.. autoclass:: library.PLAYER_ALLY
.. autoclass:: commandcenter.PLAYER_SELF
.. autoclass:: commandcenter.PLAYER_ENEMY
.. autoclass:: commandcenter.PLAYER_NEUTRAL
.. autoclass:: commandcenter.PLAYER_ALLY
These are internally represented as integers, but these constants should be
used instead to avoid confusion.
......@@ -21,21 +21,21 @@ used instead to avoid confusion.
Difficulty
----------
.. autoclass:: library.Difficulty
.. autoclass:: commandcenter.Difficulty
:members:
:undoc-members:
AIBuild
-------
.. autoclass:: library.AIBuild
.. autoclass:: commandcenter.AIBuild
:members:
:undoc-members:
Race
----
.. autoclass:: library.Race
.. autoclass:: commandcenter.Race
:members:
:undoc-members:
......
......@@ -2,8 +2,8 @@ Coordinates
===========
The library uses 2 types of coordinate classes. One for integers and one for
floats, these are called :class:`library.Point2DI` and
:class:`library.Point2D`. Conversion between the two types is possible by
floats, these are called :class:`commandcenter.Point2DI` and
:class:`commandcenter.Point2D`. Conversion between the two types is possible by
sending the other type as argument in the constructor. In the case of
Point2D to Point2DI the floating point values will just be cast into
integer values.
......@@ -16,7 +16,7 @@ Point2DI
--------
.. class:: library.Point2DI
.. class:: commandcenter.Point2DI
These points are used for defining the location of tiles, which are used when
placing buildings in Starcraft.
......@@ -28,7 +28,7 @@ Point2DI
Point2D
-------
.. class:: library.Point2D
.. class:: commandcenter.Point2D
Instances of this class is used to represent the location of Units and
support many operations for general purpose calculation.
......@@ -38,7 +38,7 @@ Example
.. code:: python
from library import Point2D, Point2DI
from commandcenter import Point2D, Point2DI
# Creating two points
......@@ -73,7 +73,7 @@ below:
.. code:: python
from math import sqrt
from library import Point2D
from commandcenter import Point2D
p1 = Point2D(3, 4)
p2 = Point2D(1, 2)
......
#!/bin/bash
scp -r _build/html/. davbe125@remote-und.ida.liu.se:/wwwpub/davbe125/sc2
......@@ -17,7 +17,7 @@ and more.
import os
from typing import Optional
from library import *
from commandcenter import *
class MyAgent(IDABot):
......@@ -56,7 +56,7 @@ Now, let us break it down piece by piece to understand it.
.. code-block:: python
from library import *
from commandcenter import *
This imports everything from the library into your namespace.
......@@ -74,7 +74,7 @@ Next, we need to define our bot.
def on_step(self):
IDABot.on_step(self)
A bot which plays Starcraft is defined as a subclass to the class :class:`library.IDABot` which
A bot which plays Starcraft is defined as a subclass to the class :class:`commandcenter.IDABot` which
contains some help code in order to make implementing your bit more straightforward.
If we look closer at our newly created bot, it has three methods which are all
......
......@@ -2,7 +2,7 @@ Helpers
=======
There are several classes related to processing information about the game
state and the input from Starcraft. All these classes are taken more or less
state and the input from StarCraft II. All these classes are taken more or less
directly from the original `CommandCenter`_, but we have left all
decision-making to the user of the API.
......@@ -10,17 +10,17 @@ decision-making to the user of the API.
Here is a full list of all managers:
* :class:`library.BaseLocationManager`
* :class:`library.TechTree`
* :class:`library.MapTools`
* :class:`library.BuildingPlacer`
* :class:`commandcenter.BaseLocationManager`
* :class:`commandcenter.TechTree`
* :class:`commandcenter.MapTools`
* :class:`commandcenter.BuildingPlacer`
The rest of this page contains a brief description of each manager.
BaseLocationManager
-------------------
.. class:: library.BaseLocationManager
.. class:: commandcenter.BaseLocationManager
.. autoattribute:: base_locations
......@@ -35,7 +35,7 @@ BaseLocationManager
BaseLocation
~~~~~~~~~~~~
.. class:: library.BaseLocation
.. class:: commandcenter.BaseLocation
Closely related to BaseLocationManager. This is the datastructure used by
the BaseLocationManager to keep track of all base locations and related
......@@ -61,16 +61,16 @@ BaseLocation
TechTree
--------
.. autoclass:: library.TechTree
.. autoclass:: commandcenter.TechTree
This class has some invalid information by default, this can be corrected by
placing the file `techtree.json` in the working directory. The
`techtree.json` files are available here_, select the lastest version.
A techtree for SC2 version >=4.10 is now available (not fully tested yet),
A techtree for StarCraft II version >=4.10 is now available (not fully tested yet),
this can be found under the folder data in this link_.
A recent file is included in the `template repository`_.
.. automethod:: get_data(argument) -> library.TypeData
.. automethod:: get_data(argument) -> commandcenter.TypeData
.. _link: https://github.com/BurnySc2/sc2-techtree
.. _here: https://github.com/noorus/sc2-gamedata
......@@ -79,7 +79,7 @@ TechTree
TypeData
~~~~~~~~
.. autoclass:: library.TypeData
.. autoclass:: commandcenter.TypeData
:members:
:undoc-members:
......@@ -89,7 +89,7 @@ TypeData
MapTools
--------
.. autoclass:: library.MapTools
.. autoclass:: commandcenter.MapTools
:members:
:undoc-members:
......@@ -97,7 +97,7 @@ MapTools
Color
~~~~~
.. autoclass:: library.Color
.. autoclass:: commandcenter.Color
:members:
:undoc-members:
......@@ -106,16 +106,16 @@ Color
DistanceMap
~~~~~~~~~~~
.. autoclass:: library.DistanceMap
.. autoclass:: commandcenter.DistanceMap
:members:
:undoc-members:
BuildingPlacer
--------------
.. autoclass:: library.BuildingPlacer
.. autoclass:: commandcenter.BuildingPlacer
:members:
:undoc-members:
.. toctree::
\ No newline at end of file
.. toctree::
IDABot
======
.. autoclass:: library.IDABot
.. autoclass:: commandcenter.IDABot
See :ref:`this page <gettingstarted>` for how to properly
inherit from IDABot.
......@@ -60,7 +60,7 @@ IDABot
Debug
-----
.. class:: library.IDABot
.. class:: commandcenter.IDABot
When developing AI-methods or when simply having a problem.
The debug-methods are a great tool for speeding up the process.
......@@ -84,7 +84,7 @@ Debug
.. method:: IDABot.debug_set_energy(self, Float, Unit)
Set the amount (Float) of energy to the :class:`library.Unit`
Set the amount (Float) of energy to the :class:`commandcenter.Unit`
The maximum depends on the unit maxenergy.
Note: This is not in percent of the unit energy.
Same goes for life and shields.
......
IDAReplayObserver
=================
.. class:: library.IDAReplayObserver
.. class:: commandcenter.IDAReplayObserver
This is a class for following a replay.
......@@ -35,14 +35,14 @@ IDAReplayObserver
Methods:
.. method:: IDAReplayObserver.get_all_units(self) -> List[library.ReplayUnit]
.. method:: IDAReplayObserver.get_all_units(self) -> List[commandcenter.ReplayUnit]
Retrieves a list of all visible units
Retrieves a list of all visible units.
.. method:: IDAReplayObserver.get_player_race(self, player_id) -> library.Race
.. method:: IDAReplayObserver.get_player_race(self, player_id) -> commandcenter.Race
Returns the players race
Returns the player's race.
.. toctree::
\ No newline at end of file
.. toctree::
......@@ -19,11 +19,11 @@ Table of contents
-----------------
.. toctree::
:maxdepth: 3
:maxdepth: 2
gettingstarted
Library<_autosummary/library>
Coordinator<_autosummary/library.Coordinator>
PyCommandCenter<_autosummary/commandcenter>
Coordinator<_autosummary/commandcenter.Coordinator>
helpers
idabot
unit
......@@ -38,6 +38,6 @@ Table of contents
:toctree: _autosummary
:hidden:
library
library.Coordinator
commandcenter
commandcenter.Coordinator
import sys,os
import conf
import library
\ No newline at end of file
import commandcenter
\ No newline at end of file
......@@ -76,7 +76,7 @@ that no action can be preform just observations.
.. code-block:: python
from library import *
from commandcenter import *
class MyObserver(ReplayObserver):
......@@ -92,7 +92,7 @@ that no action can be preform just observations.
def main():
coordinator = Coordinator(r"D:/StarCraft II/Versions/Base69232/SC2_x64.exe")
coordinator = Coordinator(r"D:/StarCraft II/Versions/Base<version>/SC2_x64.exe")
if coordinator.load_replay_list("D:/Replays/"):
observer = MyObserver()
coordinator.add_replay_observer(observer)
......@@ -105,4 +105,4 @@ that no action can be preform just observations.
if __name__ == "__main__":
main()
.. toctree::
\ No newline at end of file
.. toctree::
ReplayUnit
==========
.. autoclass:: library.ReplayUnit
.. autoclass:: commandcenter.ReplayUnit
Properties:
......
Types
=====
For a full list of all unit types see the enum :class:`library.UNIT_TYPEID`.
For more information about a certain unit type, the wrapper class
:class:`library.UnitType` can be used.
For a full list of all unit types see the enum :class:`commandcenter.UNIT_TYPEID`.
For more information about a certain unit type, the wrapper class :class:`commandcenter.UnitType` can be used.
For a full list of all abilities and upgrades, see :class:`library.ABILITY_ID`
, :class:`library.UPGRADE_ID` and :class:`library.EFFECT_ID` respectively. Note that these does not have any
For a full list of all abilities and upgrades, see :class:`commandcenter.ABILITY_ID`, :class:`commandcenter.UPGRADE_ID` and :class:`commandcenter.EFFECT_ID` respectively. Note that these does not have any
wrapper classes for them.
If any of the ID's doesn't respond with the game. Before contacting the labassistent, check the game version
and the compatibility through Liquipedia. Some ID's might be left after a patch and is not available in
the game anymore.
If any of the ID's doesn't respond with the game. Before contacting the labassistent, check the game version and the compatibility through Liquipedia. Some ID's might be left after a patch and is not available in the game anymore.
UnitType
--------
.. autoclass:: library.UnitType
.. autoclass:: commandcenter.UnitType
:members:
:undoc-members:
:special-members: __init__
......@@ -24,27 +20,27 @@ UnitType
UNIT_TYPEID
-----------
.. dropdown:: UNIT_TYPEID Enum (dropdown because of the size of the enum)
.. dropdown:: UNIT_TYPEID Enum (click to expand)
.. autoclass:: library.UNIT_TYPEID
.. autoclass:: commandcenter.UNIT_TYPEID
:members:
:undoc-members:
ABILITY_ID
----------
.. dropdown:: ABILITY_ID Enum (dropdown because of the size of the enum)
.. dropdown:: ABILITY_ID Enum (click to expand)
.. autoclass:: library.ABILITY_ID
.. autoclass:: commandcenter.ABILITY_ID
:members:
:undoc-members:
UPGRADE_ID
----------
.. dropdown:: UPGRADE_ID Enum (dropdown because of the size of the enum)
.. dropdown:: UPGRADE_ID Enum (click to expand)
.. autoclass:: library.UPGRADE_ID
.. autoclass:: commandcenter.UPGRADE_ID
:members:
:undoc-members:
......@@ -52,10 +48,10 @@ EFFECT_ID
----------
EffectID is for things like ravager bile, or fungal or even a scan.
.. dropdown:: EFFECT_ID Enum (dropdown because of the size of the enum)
.. dropdown:: EFFECT_ID Enum (click to expand)
.. autoclass:: library.EFFECT_ID
.. autoclass:: commandcenter.EFFECT_ID
:members:
:undoc-members:
.. toctree::
\ No newline at end of file
.. toctree::
Unit
====
.. autoclass:: library.Unit
.. autoclass:: commandcenter.Unit
Properties:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment