Exemplo n.º 1
0
import numpy as np
import matplotlib.pyplot as plt
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.starcraft.adv_heuristics import heuristic

unit_repo = UnitRepository()

zealot = []
dragoon = []
dark_templar = []
marine = []
firebat = []
medic = []

frame = []
seconds = []
minutes = []

file = open("stats/unit_history_3.dat", 'r')
lines = []
for line in file:
    lines = line.split(" ")

for line in lines:
    records = line.split(";")
    i = -1
    for record in records:
        if i == -1:
            t = int(record.split(';')[0])
Exemplo n.º 2
0
import numpy as np
import tqdm
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.evolution.evolution import Evolution
from broodwar_strategy_evolver.evolution.evolution import CrossoverMethod

unit_repo = UnitRepository()


def run(enemies, runs, generations):
    units = {}
    techs = {}
    upgrades = {}

    for s in tqdm.trange(runs):
        gamestate = GameState(own_race=Race.PROTOSS,
                              opp_race=Race.TERRAN,
                              own_units=own_units,
                              opp_units=enemies,
                              own_techs=own_techs,
                              own_upgrades=own_upgrades,
                              own_units_under_construction=[],
                              own_techs_under_construction=[],
                              own_upgrades_under_construction=[])

        gamestate.frame = 24 * 60 * 2

        minutes = 12
        horizon = int(24 * 60 * minutes)
Exemplo n.º 3
0
from django.http import HttpResponse
from django.shortcuts import render
import threading
import time
from broodwar_strategy_evolver.evolution.evolution import Evolution, CrossoverMethod, Genome
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
from broodwar_strategy_evolver.starcraft.forward_model import GameState, ForwardModel
from broodwar_strategy_evolver.evolution.stub import Stub
import numpy as np

unit_repo = UnitRepository()
lock = threading.Lock()
#evolution = Evolution(pop_size=32, own_race=Race.PROTOSS, opp_race=Race.TERRAN, horizon=24*60*8, coevolve=False)
forward_model = ForwardModel()


class Shared:
    def __init__(self):
        self.running = False
        self.build_order = []
        self.gamestate = None
        self.champion = None
        self.evolution = None
        self.generations = 100
        self.frames_per_build = 300
        self.start_time = 0
        self.pop_history = []
        self.update_history = []
        self.unit_history = []
        self.fitness_history = []
Exemplo n.º 4
0
import numpy as np
import tqdm
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.evolution.evolution import Evolution
from broodwar_strategy_evolver.evolution.evolution import CrossoverMethod

unit_repo = UnitRepository()

own_units = np.zeros(len(unit_repo.units))
own_units[unit_repo.get_by_name("Probe").id] = 9
own_units[unit_repo.get_by_name("Nexus").id] = 1
'''
opp_units = np.zeros(len(unit_repo.units))
opp_units[unit_repo.get_by_name("Nexus").id] = 1
opp_units[unit_repo.get_by_name("Probe").id] = 4
opp_units[unit_repo.get_by_name("Zealot").id] = 0
opp_units[unit_repo.get_by_name("Dragoon").id] = 12
'''

opp_units = np.zeros(len(unit_repo.units))
opp_units[unit_repo.get_by_name("Drone").id] = 9
opp_units[unit_repo.get_by_name("Zergling").id] = 0
opp_units[unit_repo.get_by_name("Hydralisk").id] = 0
opp_units[unit_repo.get_by_name("Hatchery").id] = 1

own_techs = np.zeros(len(unit_repo.techs))
own_upgrades = np.zeros(len(unit_repo.upgrades))

gamestate = GameState(own_race=Race.PROTOSS,
Exemplo n.º 5
0
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
import random
import os
import numpy as np

unit_repo = UnitRepository()
path = os.path.dirname(os.path.realpath(__file__))


def load_unit_heuristics(filename):
    h = {}

    file = open(filename, 'r')
    idx = 0
    b = []
    for line in file:
        # Race_b units
        if idx == 0:
            units = line.split('\n')[0].split(';')
            for u in units:
                if u != "":
                    unit = unit_repo.get_by_name(u)
                    b.append(unit.id)
                    h[unit.id] = {}
        else:
            # Race_a units
            cells = line.split('\n')[0].split(';')
            cell_idx = 0
            unit = None
            for cell in cells:
Exemplo n.º 6
0
import numpy as np
import tqdm
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.evolution.evolution import Evolution
from broodwar_strategy_evolver.evolution.evolution import CrossoverMethod
import matplotlib.pyplot as plt
import time

unit_repo = UnitRepository()

own_units = np.zeros(len(unit_repo.units))
own_units[unit_repo.get_by_name("Probe").id] = 18
own_units[unit_repo.get_by_name("Assimilator").id] = 1
own_units[unit_repo.get_by_name("Gateway").id] = 1
own_units[unit_repo.get_by_name("Cybernetics Core").id] = 1
own_units[unit_repo.get_by_name("Nexus").id] = 1
own_units[unit_repo.get_by_name("Pylon").id] = 3
'''
opp_units = np.zeros(len(unit_repo.units))
opp_units[unit_repo.get_by_name("Nexus").id] = 1
opp_units[unit_repo.get_by_name("Probe").id] = 4
opp_units[unit_repo.get_by_name("Zealot").id] = 0
opp_units[unit_repo.get_by_name("Dragoon").id] = 12
'''

opp_units = np.zeros(len(unit_repo.units))
opp_units[unit_repo.get_by_name("Drone").id] = 18
opp_units[unit_repo.get_by_name("Zergling").id] = 0
opp_units[unit_repo.get_by_name("Overlord").id] = 3
Exemplo n.º 7
0
import threading
import multiprocessing
import time
from broodwar_strategy_evolver.nn.ACNetwork import ACNetwork
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type, StarCraftException
from broodwar_strategy_evolver.starcraft.forward_model import GameState, ForwardModel
import operator
import collections
import numpy as np
import tensorflow as tf
import os
import math

# StarCraft config
unit_repo = UnitRepository()
fm = ForwardModel()
own_race = Race.PROTOSS
opp_race = Race.TERRAN
a_size = len(unit_repo.units_by_race(own_race)) + \
            len(unit_repo.techs_by_race(own_race)) + \
            len(unit_repo.upgrades_by_race(own_race))
s_size = a_size * 3 + len(unit_repo.units_by_race(opp_race)) + 3

banned_builds = [
    "Shuttle", "Archon", "High Templar", "Dark Archon", "Carrier", "Reaver"
]

print('Loading Model...')
sess = tf.Session()
from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Race, Type
import numpy as np

# Unit table
unit_repo = UnitRepository()


def create_build_order(units):
    bo = []
    for unit in units:
        bo.append(unit_repo.get_by_name(unit))
    return bo


def test_build_order(build_order, gamestate):
    print("-------------------")
    opp_units=np.zeros(len(unit_repo.units))
    gamestate, _ = forward_model.run(gamestate, build_order, to_frame=50000)
    gamestate.print()

# Create Forward Model
forward_model = ForwardModel(verbose=True)

# Create initial unit vector
start_units = np.zeros(len(unit_repo.units)).astype(int)
start_units[unit_repo.get_worker(Race.PROTOSS).id] = 4
start_units[unit_repo.get_base(Race.PROTOSS).id] = 1

start_techs = np.zeros(len(unit_repo.techs)).astype(int)
Exemplo n.º 9
0
import numpy as np
import time

from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Type, Race
from http_server.sup import views

unit_repo = UnitRepository()
own_units = np.zeros(len(unit_repo.units)).astype(int)
own_units[unit_repo.get_by_name("Nexus").id] = 1
own_units[unit_repo.get_by_name("Probe").id] = 7

opp_units = np.zeros(len(unit_repo.units)).astype(int)
own_techs = np.zeros(len(unit_repo.techs)).astype(int)
own_upgrades = np.zeros(len(unit_repo.upgrades)).astype(int)


gamestate = GameState(own_race=Race.PROTOSS,
                      opp_race=Race.TERRAN,
                      own_units=own_units,
                      opp_units=opp_units,
                      minerals=50,
                      gas=0,
                      frame=0,
                      new_game=False)

# Get build from service
build = views.__update__(gamestate)
print("Building " + build)
Exemplo n.º 10
0
import numpy as np
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.evolution.stub import Stub

unit_repo = UnitRepository()

stub_build_order = [
    unit_repo.get_by_name("Probe").id,
    unit_repo.get_by_name("Pylon").id,
    unit_repo.get_by_name("Gateway").id,
    unit_repo.get_by_name("Assimilator").id,
    unit_repo.get_by_name("Cybernetics Core").id,
    unit_repo.get_by_name("Dragoon").id,
    unit_repo.get_by_name("Zealot").id
]
stub_units = np.zeros(len(unit_repo.units))
stub_units[unit_repo.get_by_name("Probe").id] = 4
stub_units[unit_repo.get_by_name("Nexus").id] = 1

stub = Stub(stub_build_order, list(stub_units))


def print_current_build_order():
    print("-- Build order:")
    for build in stub.get_build_order():
        print(unit_repo.get_by_id(build).name)
    print("---------------")


def build(name):
    print("-- Building " + name)
Exemplo n.º 11
0
import numpy as np
import time

from broodwar_strategy_evolver.starcraft.forward_model import ForwardModel, GameState
from broodwar_strategy_evolver.starcraft.unit_repository import UnitRepository
from broodwar_strategy_evolver.starcraft.starcraft import Type, Race
from http_server.app import views

unit_repo = UnitRepository()
own_units = np.zeros(len(unit_repo.units)).astype(int)
own_units[unit_repo.get_by_name("Nexus").id] = 1
own_units[unit_repo.get_by_name("Probe").id] = 4

opp_units = np.zeros(len(unit_repo.units)).astype(int)
opp_units[unit_repo.get_by_name("Drone").id] = 4
opp_units[unit_repo.get_by_name("Hatchery").id] = 1
'''
opp_units[unit_repo.get_by_name("Barracks").id] = 1
opp_units[unit_repo.get_by_name("Academy").id] = 1
opp_units[unit_repo.get_by_name("Siege Tank Tank Mode").id] = 10
opp_units[unit_repo.get_by_name("Goliath").id] = 10
'''

own_techs = np.zeros(len(unit_repo.techs)).astype(int)
own_upgrades = np.zeros(len(unit_repo.upgrades)).astype(int)


gamestate = GameState(own_race=Race.PROTOSS,
                      opp_race=Race.ZERG,
                      own_units=own_units,
                      opp_units=opp_units,