Skip to content

Commit

Permalink
pull map data method for pulling data from the game and from any map
Browse files Browse the repository at this point in the history
  • Loading branch information
DrInfy committed Jul 10, 2020
1 parent 5e4d291 commit 47e07b8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
48 changes: 48 additions & 0 deletions pull_map_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import sys
import argparse
import numpy as np


if "python-sc2" not in sys.path:
sys.path.insert(1, "python-sc2")

from sc2.game_info import GameInfo
from sc2.player import Bot, Computer
from sc2 import BotAI, maps, run_game, Race


class PullerBot(BotAI):
async def on_step(self, iteration):
if iteration == 1:
game_info: GameInfo = self.game_info
path_grid = game_info.pathing_grid
placement_grid = game_info.placement_grid
map_name = game_info.map_name

with open(f"tests\\{map_name}_height.npy", 'wb') as f:
np.save(f, game_info.terrain_height.data_numpy, False, False)
with open(f"tests\\{map_name}_pathing.npy", 'wb') as f:
np.save(f, path_grid.data_numpy, False, False)
with open(f"tests\\{map_name}_placement.npy", 'wb') as f:
np.save(f, placement_grid.data_numpy, False, False)
print("MAPS SAVED")
elif iteration > 1:
await self.client.leave()



def main():
parser = argparse.ArgumentParser(description="Save numpy map data")
parser.add_argument("-m", "--map", help="map name to use.")
args = parser.parse_args()

run_game(
maps.get(args.map),
[Bot(Race.Random, PullerBot()),
Computer(Race.Random)],
realtime=False
)

if __name__ == '__main__':
main()
25 changes: 13 additions & 12 deletions test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ def __init__(self, x: int, y: int, width: int, height: int):
self.width = width
self.height = height

playable_area = Rect(2, 2, 38, 38)
maze = read_maze("tests/choke.txt")
map = sc2pathlibp.Sc2Map(maze, maze, maze, playable_area)
print(f"Choke lines found: {len(map.chokes)}")

map.plot("cliffs")
map.plot_chokes("chokes")
input("Press Enter to continue...")

pathing = np.load("tests/AutomatonLE_pathing.npy")
placement = np.load("tests/AutomatonLE_placement.npy")
height = np.load("tests/AutomatonLE_height.npy")
# playable_area = Rect(2, 2, 38, 38)
# maze = read_maze("tests/choke.txt")
# map = sc2pathlibp.Sc2Map(maze, maze, maze, playable_area)
# print(f"Choke lines found: {len(map.chokes)}")

# map.plot("cliffs")
# map.plot_chokes("chokes")
# input("Press Enter to continue...")

map_name = "Submarine LE"
pathing = np.load(f"tests/{map_name}_pathing.npy")
placement = np.load(f"tests/{map_name}_placement.npy")
height = np.load(f"tests/{map_name}_height.npy")

playable_area = Rect(18, 16, 148, 148) # AutomatonLE
ns_pf = time.perf_counter_ns()
Expand Down
Binary file added tests/Submarine LE_height.npy
Binary file not shown.
Binary file added tests/Submarine LE_pathing.npy
Binary file not shown.
Binary file added tests/Submarine LE_placement.npy
Binary file not shown.

0 comments on commit 47e07b8

Please sign in to comment.