Exemple #1
0
def main():
    self = Container()
    UnitInfo.setup()
    print(os.getcwd())

    print("pystarting")

    # A GameController is the main type that you talk to the game with.
    # Its constructor will connect to a running game.
    self.gc = bc.GameController()

    print("pystarted")

    # It's a good idea to try to keep your bots deterministic, to make debugging easier.
    # determinism isn't required, but it means that the same things will happen in every thing you run,
    # aside from turns taking slightly different amounts of time due to noise.
    random.seed(6137)

    # For the purposes of this program, (0, 0) is the UPPERLEFT corner and Point(y, x) <=> [y][x] <=> bc.MapLocation(self.planet, x, y)

    self.directions = [
        Point(1, 0),
        Point(1, 1),
        Point(0, 1),
        Point(-1, 1),
        Point(-1, 0),
        Point(-1, -1),
        Point(0, -1),
        Point(1, -1)
    ]

    self.planet = self.gc.planet()
    self.planet_map = self.gc.starting_map(self.planet)
    self.team = self.gc.team()
    self.asteroids = self.gc.asteroid_pattern()
    self.orbit = self.gc.orbit_pattern()

    # self.kmap[row][col] is an amount of karbonite >= 0 or -1 if impassable
    self.kmap = phase0.generate_kmap(self)

    if self.planet == bc.Planet.Earth:
        main_earth(self)
    else:
        main_mars(self)
class Manager():
    '''Manager class to distribute the GameController'''

    game_controller = bc.GameController()

    # Lists for pathing

    directions = [
        bc.Direction.North, bc.Direction.Northeast, bc.Direction.East,
        bc.Direction.Southeast, bc.Direction.South, bc.Direction.Southwest,
        bc.Direction.West, bc.Direction.Northwest
    ]
    tryRotate = [0, -1, 1, -2, 2]

    num_worker = 0
    num_factory = 0
    num_mage = 0
    num_ranger = 0

    yourStart = []
    enemyStart = []
    earthMap = None

    def __init__(self):
        print("Hello")

    def countWorker(self):
        self.num_worker += 1
        print('Worker Count: ' + str(self.num_worker))

    def locateEnemy(self):
        pathing.findEnemy(self.game_controller, self.earthMap, self.yourStart,
                          self.enemyStart)

    def fuzzygoto(self, unit, dest):
        pathing.fuzzygoto(self.game_controller, unit, dest)
Exemple #3
0
import battlecode as bc
import random
import sys
import traceback
import time

import os
print(os.getcwd())

print("pystarting")

#Test
# A GameController is the main type that you talk to the game with.
# Its constructor will connect to a running game.
gc = bc.GameController()
directions = list(bc.Direction)

print("pystarted")

# It's a good idea to try to keep your bots deterministic, to make debugging easier.
# determinism isn't required, but it means that the same things will happen in every thing you run,
# aside from turns taking slightly different amounts of time due to noise.
random.seed(6137)

# let's start off with some research!
# we can queue as much as we want.
gc.queue_research(bc.UnitType.Rocket)
gc.queue_research(bc.UnitType.Worker)
gc.queue_research(bc.UnitType.Knight)

my_team = gc.team()
Exemple #4
0
import battlecode as bc
import random
import sys
import traceback

from RunEarth import RunEarth
from RunMars import RunMars

print("Starting bananabot Player")

# A GameController is the main type that you talk to the game with.
# Its constructor will connect to a running game.
GAMECONTROLLER = bc.GameController()
PLANETS = bc.Planet
MY_TEAM = GAMECONTROLLER.team()

RUNEARTH = RunEarth(GAMECONTROLLER)
RUNMARS = RunMars(GAMECONTROLLER)

# Main game loop
# Avoid placing additional code here if possible
while True:
    try:
        if GAMECONTROLLER.planet() == PLANETS.Earth:
            #print('Running Earth Turn')
            RUNEARTH.Run()
        else:
            #print('Running Mars Turn')
            RUNMARS.Run()

    except Exception as e:
Exemple #5
0
def goto(unit, dest): #implementing a* over here instead of their pathfinding cheese



print("pystarting")

# A GameController is the main type that you talk to the game with.
# Its constructor will connect to a running game.
gc = bc.GameController()
directions = [bc.Direction.NORTH, bc.Direction.NORTHEAST, bc.Direction.EAST,
              bc.Direction.SOUTHEAST, bc.Direction.SOUTH, bc.Direction.SOUTHWEST,
              bc.Direction.WEST, bc.Direction.NORTHWEST]

print("pystarted")


# It's a good idea to try to keep your bots deterministic, to make debugging easier.
# determinism isn't required, but it means that the same things will happen in every thing you run,
# aside from turns taking slightly different amounts of time due to noise.
random.seed(6137)

# let's start off with some research!
# we can queue as much as we want.

if gc.planet() == bc.Planet.Earth #initializing the map, and starting locations
    myStart = gc.my_units()[0].location.map_location()
    earthMap = gc.starting_map(bc.Planet.Earth)
    enemyStart = invert(myStart)

print(os.getcwd())
gc.queue_research(bc.UnitType.Rocket)
gc.queue_research(bc.UnitType.Worker)
gc.queue_research(bc.UnitType.Knight)

my_team = gc.team()

while True:
    # We only support Python 3, which means brackets around print()
    print('pyround:', gc.round(), 'time left:', gc.get_time_left_ms(), 'ms')

    # frequent try/catches are a good idea
    try:
        # walk through our units:
        for unit in gc.my_units():

            # first, factory logic
            if unit.unit_type == bc.UnitType.Factory:
                garrison = unit.structure_garrison()
                if len(garrison) > 0:
                    d = random.choice(directions)
                    if gc.can_unload(unit.id, d):
                        print('unloaded a knight!')
                        gc.unload(unit.id, d)
                        continue
                elif gc.can_produce_robot(unit.id, bc.UnitType.Knight):
                    gc.produce_robot(unit.id, bc.UnitType.Knight)
                    print('produced a knight!')
                    continue

            # first, let's look for nearby blueprints to work on
            location = unit.location
            if location.is_on_map():
                nearby = gc.sense_nearby_units(location.map_location(), 2)
                for other in nearby:
                    if unit.unit_type == bc.UnitType.Worker and gc.can_build(unit.id, other.id):
                        gc.build(unit.id, other.id)
                        print('built a factory!')
                        # move onto the next unit
                        continue
                    if other.team != my_team and gc.is_attack_ready(unit.id) and gc.can_attack(unit.id, other.id):
                        print('attacked a thing!')
                        gc.attack(unit.id, other.id)
                        continue

            # okay, there weren't any dudes around
            # pick a random direction:
            d = random.choice(directions)

            # or, try to build a factory:
            if gc.karbonite() > bc.UnitType.Factory.blueprint_cost() and gc.can_blueprint(unit.id, bc.UnitType.Factory, d):
                gc.blueprint(unit.id, bc.UnitType.Factory, d)
            # and if that fails, try to move
            elif gc.is_move_ready(unit.id) and gc.can_move(unit.id, d):
                gc.move_robot(unit.id, d)

    except Exception as e:
        print('Error:', e)
        # use this to show where the error was
        traceback.print_exc()

    # send the actions we've performed, and wait for our next turn.
    gc.next_turn()

    # these lines are not strictly necessary, but it helps make the logs make more sense.
    # it forces everything we've written this turn to be written to the manager.
    sys.stdout.flush()
    sys.stderr.flush()
Exemple #6
0
def main():
    print("pystarting")

    # A GameController is the main type that you talk to the game with.
    # Its constructor will connect to a running game.
    gc = bc.GameController()
    directions = list(bc.Direction)

    print("pystarted")

    # It's a good idea to try to keep your bots deterministic, to make debugging easier.
    # determinism isn't required, but it means that the same things will happen in every thing you run,
    # aside from turns taking slightly different amounts of time due to noise.
    random.seed(6137)

    # let's start off with some research!
    # we can queue as much as we want.
    gc.queue_research(bc.UnitType.Rocket)
    gc.queue_research(bc.UnitType.Worker)
    gc.queue_research(bc.UnitType.Knight)
    my_team = gc.team()
    #inKarbs1=(genInKarbLocs())
    #p=Pool(processes=10)
    #inKarbs2=p.map(genInKarbLocs,[])
    #p.close()
    #print(inKarbs1)
    #print(inKarbs2)
    while True:
        # We only support Python 3, which means brackets around print()
        print('pyround:', gc.round())
        # print(PlanetMap.initial_karbonite_at(location()))
    
        # frequent try/catches are a good idea
        try:
            # walk through our units:
            for unit in gc.my_units():
                if(unit.unit_type==bc.UnitType.Worker):
                    location = (unit.location).map_location()
                    surr=gc.all_locations_within(location,9)
                    moves=[]
                    for loc in surr:
                        if(gc.karbonite_at(loc)>0):
                            moves.append(location.direction_to(loc))
                    move=random.choice(moves)
                    movePoss=gc.is_move_ready(unit.id)
                    moveOcc=gc.is_occupiable(location.add(move))
                    if(movePoss and moveOcc):
                        gc.move_robot(unit.id,move)
                    print(gc.karbonite())
                
                        
                 
                '''if location.is_on_map():
                    if unit.unit_type == bc.UnitType.Worker:
    
                        # d = random.choice(directions)
                        d = directions[0]
                        # gc.move_robot(unit.id, d)
    
                        if gc.karbonite_at(location.map_location()) > 0:
                            if gc.can_harvest(unit.id,d) == True:
                                 gc.harvest(unit.id,d)
                                 print("Amount of Kryptonite left here" + str(gc.karbonite_at(location.map_location())))
                            print("Total karbonite is" + str(gc.karbonite()))
        '''
        except Exception as e:
            print('Error:', e)
            # use this to show where the error was
            traceback.print_exc()
    
        # send the actions we've performed, and wait for our next turn.
        # this is the final yield function.
        gc.next_turn()
    
        # these lines are not strictly necessary, but it helps make the logs make more sense.
        # it forces everything we've written this turn to be written to the manager.
        sys.stdout.flush()
        sys.stderr.flush()
class game_controller():
    gc = bc.GameController()
    my_team = gc.team()
Exemple #8
0
import traceback
import sys

import battlecode as bc
import random

from ai import AI
from game.game_controller import GC
from pathfinding.pathfinder import PathFinder

random.seed(6137)
GC(bc.GameController())
PathFinder()
ai = AI()

while True:
    try:
        ai.play_round()
    except Exception as e:
        print(traceback.format_exc())
    GC.get().next_turn()

    # these lines are not strictly necessary, but it helps make the logs make more sense
    # it forces everything we've written this turn to be written to the manager
    sys.stdout.flush()
    sys.stderr.flush()