Code Monkey home page Code Monkey logo

sc2mapanalysis's Introduction

SC2MapAnalysis

Summary

A standalone plugin for python SC2 api

Why Do we need this ?

This module is inspired by plays like this one TY map positioning (notice how the army splits into groups, covering different areas, tanks are tucked in corners, and so on)

Hopefully with the interface provided here, you will be able to build plays like that one!

it is meant to be a tool(extension) for BurnySc2

Thanks A lot to DrInfy for solving one of the biggest challenges, finding rare choke points.

check out his work

  • Sharpy for rapid bot development.

  • sc2pathlib a high performance rust module with python interface for pathfinding

More Examples reside in the Documentation

Example bot usage can be found in dummybot.py

Example:

import pickle
import lzma
from MapData import MapData
from utils import import_bot_instance

#if its from BurnySc2 it is compressed
# https://github.com/BurnySc2/python-sc2/tree/develop/test/pickle_data
YOUR_FILE_PATH = 'some_directory/map_file'
with lzma.open(YOUR_FILE_PATH, "rb") as f:
    raw_game_data, raw_game_info, raw_observation = pickle.load(f)

# mocking a bot object to initalize the map,  this is for when you want to do this while not in a game,  
# if you want to use it in a game just pass in the bot object like shown below 

bot = import_bot_instance(raw_import_bot_instancegame_data, raw_game_info, raw_observation)


# And then you can instantiate a MapData Object like so
map_data = MapData(bot)


# plot the entire labeled map
map_data.plot_map()

# red dots or X are vision blockers,
# ramps are marked with white dots 
# ramp top center is marked with '^'
# gas geysers are yellow spades 
# MDRampss are marked with R<region_label>
# height span is with respect to :   light = high , dark = low
# ChokeArea is marked with green heart suites
# Corners are marked with a red 'V' 

Tested Maps ( AiArena and SC2ai ladder map pool) :

['AbyssalReefLE.xz',
 'AutomatonLE.xz',
 'DeathAuraLE.xz', # currently fails on ground pathing 
 'EphemeronLE.xz',
 'EternalEmpireLE.xz',
 'EverDreamLE.xz',
 'GoldenWallLE.xz',
 'IceandChromeLE.xz',
 'NightshadeLE.xz',
 'PillarsofGoldLE.xz',
 'SimulacrumLE.xz',
 'SubmarineLE.xz',
 'Triton.xz',
 'WorldofSleepersLE.xz',
 'ZenLE.xz']

sc2mapanalysis's People

Contributors

august-k avatar dependabot[bot] avatar eladyaniv01 avatar raspersc2 avatar shostyn avatar spudde123 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

Watchers

 avatar  avatar  avatar  avatar

sc2mapanalysis's Issues

Feature Request: add a setting for a custom default weight for the pathing grid

Currently you mark "bad things" on influence map, but setting a higher default weight would also allow marking "good things" on the influence map, so we can tell the pathing to "prefer this".

Copy pasted discord conversation as a note:

jensiiiToday at 6:33 PM
What if I want to mark good things on the map? ๐Ÿ˜„
EladYaniv01Today at 6:33 PM
ok i see what you mean
jensiiiToday at 6:33 PM
That's basically my question
EladYaniv01Today at 6:33 PM
hold on
jensiiiToday at 6:33 PM
๐Ÿ˜„
EladYaniv01Today at 6:34 PM
you can take the grid that the lib returns (get_pyastar_grid)
and do
CUSTOM_DEFAULT_WEIGHT = 300
grid = np.where(grid == 1, CUSTOM_DEFAULT_WEIGHT, np.inf).astype(np.float32)
it will switch all 1's to 300
and leave the np.inf for non pathable

Feature request: find lowest influence / cost within a radius

It's sometimes useful to find the "safest" position for a unit within a restricted radius. For example, a unit kiting while its weapon is on call down. Example method signature:

def self.find_lowest_cost(self, from_pos: Point2, radius: int, grid: np.ndarray) -> Point2:

DeathAuraLE bug

Traceback (most recent call last):
File "/home/aiarena/aiarena-client/arenaclient/bots/Jensiiibot/sc2/main.py", line 174, in _play_game_ai
await ai.on_step(iteration)
File "/home/aiarena/aiarena-client/arenaclient/bots/Jensiiibot/Jensiiibot.py", line 606, in on_step
self.map_data = MapData(self)
File "/home/aiarena/aiarena-client/arenaclient/bots/Jensiiibot/MapAnalyzer/MapData.py", line 40, in init
self.compile_map() # this is called on init, but allowed to be called again every step
File "/home/aiarena/aiarena-client/arenaclient/bots/Jensiiibot/MapAnalyzer/MapData.py", line 179, in compile_map
self._calc_grid()
File "/home/aiarena/aiarena-client/arenaclient/bots/Jensiiibot/MapAnalyzer/MapData.py", line 106, in _calc_grid
vision_blockers_array[vision_blockers_indices] = 1
IndexError: arrays used as indices must be of integer (or boolean) type

Feature request: Pathfinding through regions

Regular path finding via the pyastar lib works well, but it would also be useful to calculate paths through the regions this library calculates, where each point in the path is perhaps the center location of the interconnected region.

This could be a far more efficient way to calculate a path for many use cases, while pathfinding via the pyastar lib is most useful when precise movements are required. Some use cases I can think of, but there are probably more:

  • Routing an army around the edge of the map
  • Routing an army while avoiding a particular region the enemy currently occupies (avoiding regions with influence?)
  • Find all available paths from a start region to the target region
  • Find path to region while avoiding a certain choke / ramp

Feature Request: Add air grid

Currently def get_pyastar_grid() only returns the ground pathing grid.
There should be an option to return the air pathing grid too.

From my limited testing of using the sc2pathlibp air grid, and passing it to the existing pathfind() method in this library it works just as well as the ground path finding.

GoldenWall bug

Traceback (most recent call last):
File "C:\Starcraft 2 botti\Ladder\Bots\Jensiiibot\sc2\main.py", line 174, in _play_game_ai
await ai.on_step(iteration)
File "C:\Starcraft 2 botti\Ladder\Bots\Jensiiibot\Jensiiibot.py", line 606, in on_step
self.map_data = MapData(self)
File "C:\Starcraft 2 botti\Ladder\Bots\Jensiiibot\MapAnalyzer\MapData.py", line 40, in init
self.compile_map() # this is called on init, but allowed to be called again every step
File "C:\Starcraft 2 botti\Ladder\Bots\Jensiiibot\MapAnalyzer\MapData.py", line 182, in compile_map
self._calc_chokes()
File "C:\Starcraft 2 botti\Ladder\Bots\Jensiiibot\MapAnalyzer\MapData.py", line 157, in _calc_chokes
region.region_chokes.append(new_choke)
AttributeError: 'NoneType' object has no attribute 'region_chokes'

Enhance Region properties

Region should also have the following

  • Region.border_towards_point(Point2) this is very helpful if you want to set your army on the border, facing a direction ( the enemy's army direction, for example)

  • Region.is_on_map_edge this will indicate if the region is on the edge of the map, meaning there is a fly zone between it and the map-edge , without any other regions touching that border, this could be useful for drops, nydus, etc

  • Region.drop_areas will return areas that are recommended for drops / turret placements

  • Region.siege_walls will return a list of points and direction from where to get to that spot, for sieging, example of such spot could be seen here https://www.youtube.com/watch?v=NUQsAWIBTSk&start=458 ( a few seconds in TY is tucking the tank in a
    very strategic spot)

tests

test for compatability with aiarena , sc2ai

Issue: Air vs ground grid cost values in non ground pathable areas

self.get_air_vs_ground_grid() creates a grid where by default, the ground pathable tiles have a cost of 100 and non pathable of 1. Pretend we add cost to the grid because we see a marine:

air_vs_ground_grid = self.get_air_vs_ground_grid()
pos = marine.position
air_vs_ground_grid = self.add_cost(
            position=(int(pos.x), int(pos.y)),
            radius=marine.range,
            grid=air_vs_ground_grid,
            weight=10,
        )

Then the cost values over ground pathable tiles will correctly update to 110 and non pathable will now be 11

Everything works as it should, but the problem with this, is that units will favour the non pathable tile with a value of 11 (which is now dangerous) over a perfectly safe ground tile that has a default value of 100

My suggestion is that when cost is added over a non pathable area because the radius spans over a non pathable area, the default value for the ground pathable tiles is also added.

Highlighted in red on the picture is an example of what the air vs ground grid thinks is safe, but really it's a dangerous area (in this picture the default weight for pathable areas was set to 50).

grid

choke points

Class ChokePoint

with available attributes :

  • get_regions ( usually a chokepoint will divide two regions, meaning it is directly connected to two or more )

  • get_sides

  • get_center

  • get_area (or width )

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.