Пример #1
0
    def __init__(self, MAP_W=12, MAP_H=12):
        os.chdir(MICROPOLISCORE_DIR)
        self.SHOW_GUI = False
        engine, win1 = main.train()
        os.chdir(CURR_DIR)
        self.engine = engine
        # print(dir(self.engine))
        self.MAP_X = MAP_W
        self.MAP_Y = MAP_H
        self.MAP_XS = 5
        self.MAP_YS = 5
        self.engineTools = [
            'Residential',
            'Commercial',
            'Industrial',
            'FireDept',
            'PoliceDept',
            # TODO: implement query (skipped for now by indexing)
            'Query',
            'Wire',
            'Clear',
            'Rail',
            'Road',
            'Stadium',
            'Park',
            'Seaport',
            'CoalPowerPlant',
            'NuclearPowerPlant',
            'Airport',
            'Net',
            'Water',
            'Land',
            'Forest',
        ]
        self.tools = [
            'Residential', 'Commercial', 'Industrial', 'Road', 'Wire',
            'NuclearPowerPlant', 'Park', 'Clear', None
        ]
        # since query is exluded for now:
        self.num_tools = len(self.tools)

        # map with extra channel charting position of walker
        self.map = TileMap(self, self.MAP_X, self.MAP_Y, walker=True)

        self.zones = self.map.zones
        self.num_zones = self.map.num_zones
        # allows building on rubble and forest
        self.engine.autoBulldoze = True
        # for bots
        win1.playCity()
        self.engine.setFunds(1000000)
        engine.setSpeed(3)
        engine.setPasses(500)
        #engine.simSpeed =99
        engine.clearMap()
        self.win1 = win1
Пример #2
0
    def __init__(self, MAP_W=6, MAP_H=6):
        self.SHOW_GUI = False
        engine, win1 = main.train()
        os.chdir(CURR_DIR)
        self.engine = engine
        # print(dir(self.engine))
        self.MAP_X = MAP_W
        self.MAP_Y = MAP_H
        # shifts build area to centre of 120 by 100 tile map
        # self.MAP_XS = 59 - self.MAP_X // 2
        # self.MAP_YS = 49 - self.MAP_Y //2
        self.MAP_XS = 1
        self.MAP_YS = 1
        self.engineTools = [
            'Residential',
            'Commercial',
            'Industrial',
            'FireDept',
            'PoliceDept',
            # TODO: implement query (skipped for now by indexing)
            'Query',
            'Wire',
            'Clear',
            'Rail',
            'Road',
            'Stadium',
            'Park',
            'Seaport',
            'CoalPowerPlant',
            'NuclearPowerPlant',
            'Airport',
            'Net',
            'Water',
            'Land',
            'Forest',
        ]
        self.tools = [
            'Residential', 'Commercial', 'Industrial', 'Road', 'Wire',
            'NuclearPowerPlant', 'Park', 'Clear'
        ]
        # since query is exluded for now:
        self.num_tools = len(self.tools)

        self.map = TileMap(self)
        self.zones = self.map.zones
        self.num_zones = self.map.num_zones
        # allows building on rubble and forest
        self.engine.autoBulldoze = True
        # for bots
        win1.playCity()
        self.engine.setFunds(1000000)
        engine.setSpeed(3)
        engine.setPasses(500)
        #engine.simSpeed =99
        engine.clearMap()
        self.win1 = win1
Пример #3
0
 def __init__(self, MAP_W=20, MAP_H=20):
     print('initiated gui')
     engine, win1 = main.train()
     self.engine = engine
     self.engine.setGameLevel(2)
     self.engine.autoBulldoze = True
     win1.playCity()
     self.engine.setFunds(1000000)
     engine.setSpeed(3)
     engine.setPasses(500)
Пример #4
0
    def __init__(self, MAP_W=12, MAP_H=12, PADDING=13, parallel_gui=False, rank=None):
        self.SHOW_GUI=False
        engine, win1 = main.train(bot=self, rank=rank)
        os.chdir(CURR_DIR)
        self.engine = engine
        self.engine.setGameLevel(2)
        self.MAP_X = MAP_W
        self.MAP_Y = MAP_H
        self.PADDING = PADDING
        # shifts build area to centre of 120 by 100 tile map
       # self.MAP_XS = 59 - self.MAP_X // 2
       # self.MAP_YS = 49 - self.MAP_Y //2
        self.MAP_XS = 5
        self.MAP_YS = 5
        self.num_roads = 0
        self.engineTools = ['Residential', 'Commercial', 'Industrial', 
                'FireDept', 
                'PoliceDept', 
                # TODO: implement query (skipped for now by indexing)
               'Query',
               'Wire',
               'Clear',
               'Rail',
               'Road',
                'Stadium',
                'Park', 
                 'Seaport',
                'CoalPowerPlant', 
                'NuclearPowerPlant',
                'Airport',
                'Net',
                'Water',
                'Land',
                'Forest',
                ]
        # Names correspond to those of resultant zones
        self.tools = ['Residential', 'Commercial', 'Industrial', 
                'FireDept', 
                'PoliceDept', 
             # 'Query',
                'Clear',
               'Wire',
              #'Land',
               'Rail',
               'Road',
                'Stadium',
                'Park', 
                 'Seaport',
                'CoalPowerPlant', 
                'NuclearPowerPlant',
                'Airport',
                'Net',
                'Water',
                'Land',
                'Forest',
                ]
        #['Residential','Commercial','Industrial','Road','Wire','NuclearPowerPlant', 'Park', 'Clear']
        # since query is exluded for now:
        self.num_tools = len(self.tools)
        self.map = TileMap(self, self.MAP_X + 2 * PADDING, self.MAP_Y + 2 * PADDING)
        self.zones = self.map.zones
        self.num_zones = self.map.num_zones
        # allows building on rubble and forest
        self.engine.autoBulldoze = True
        # for bots 
        self.land_value = 0
        win1.playCity()
        self.engine.setFunds(1000000)
        engine.setSpeed(3)
        engine.setPasses(500)
        #engine.simSpeed =99
        self.total_traffic = 0
        self.last_total_traffic = 0
#       engine.clearMap()
        self.win1=win1
        self.player_builds = []
Пример #5
0
    def __init__(self, MAP_W=12, MAP_H=12, PADDING=13, parallel_gui=False):
        self.parallel_gui = parallel_gui
        self.pgui = None
        if parallel_gui:
            import pexpect
            self.pgui = pexpect.spawn('/bin/bash')
            self.pgui.expect('sme')
            self.pgui.sendline('cd gym-micropolis')
            self.pgui.expect('sme')
            self.pgui.sendline('pwd')
            self.pgui.expect('sme')
            self.pgui.sendline('python2')
            self.pgui.expect('>>>')
            self.pgui.sendline(
                'from gym_micropolis.envs.gui import MicropolisGUI')
            self.pgui.expect('>>>')
            self.pgui.sendline('m = MicropolisGUI({}, {})'.format(
                MAP_W, MAP_H))
            self.pgui.expect('>>>')
            self.pgui.sendline('m.render()')
            self.pgui.expect('>>>')

        self.SHOW_GUI = False
        engine, win1 = main.train(bot=self)
        os.chdir(CURR_DIR)
        self.engine = engine
        self.engine.setGameLevel(2)
        self.MAP_X = MAP_W
        self.MAP_Y = MAP_H
        self.PADDING = PADDING
        # shifts build area to centre of 120 by 100 tile map
        # self.MAP_XS = 59 - self.MAP_X // 2
        # self.MAP_YS = 49 - self.MAP_Y //2
        self.MAP_XS = 1
        self.MAP_YS = 1
        self.num_roads = 0
        self.engineTools = [
            'Residential',
            'Commercial',
            'Industrial',
            'FireDept',
            'PoliceDept',
            # TODO: implement query (skipped for now by indexing)
            'Query',
            'Wire',
            'Clear',
            'Rail',
            'Road',
            'Stadium',
            'Park',
            'Seaport',
            'CoalPowerPlant',
            'NuclearPowerPlant',
            'Airport',
            'Net',
            'Water',
            'Land',
            'Forest',
        ]
        # Names correspond to those of resultant zones
        self.tools = [
            'Residential',
            'Commercial',
            'Industrial',
            'FireDept',
            'PoliceDept',
            # 'Query',
            'Wire',
            'Clear',
            'Rail',
            'Road',
            'Stadium',
            'Park',
            'Seaport',
            'CoalPowerPlant',
            'NuclearPowerPlant',
            'Airport',
            'Net',
            'Water',
            'Land',
            'Forest',
        ]
        #['Residential','Commercial','Industrial','Road','Wire','NuclearPowerPlant', 'Park', 'Clear']
        # since query is exluded for now:
        self.num_tools = len(self.tools)
        self.map = TileMap(self, self.MAP_X + 2 * PADDING,
                           self.MAP_Y + 2 * PADDING)
        self.zones = self.map.zones
        self.num_zones = self.map.num_zones
        # allows building on rubble and forest
        self.engine.autoBulldoze = True
        # for bots
        win1.playCity()
        self.engine.setFunds(1000000)
        engine.setSpeed(3)
        engine.setPasses(500)
        #engine.simSpeed =99
        self.total_traffic = 0
        self.last_total_traffic = 0
        #       engine.clearMap()
        self.win1 = win1
Пример #6
0
    def __init__(self,
                 env,
                 MAP_W=12,
                 MAP_H=12,
                 PADDING=13,
                 gui=False,
                 rank=None,
                 power_puzzle=False,
                 paint=False):
        env.micro = self  # attach ourselves to our parent before we start
        # Reuse game engine if we are reinitializing controller (i.e. to change map size)
        if hasattr(self, 'engine'):
            print('REINIT: reuse engine and window')
            engine, win1 = self.engine, self.win1
        else:
            engine, win1 = main.train(env=env,
                                      rank=rank,
                                      map_x=MAP_W,
                                      map_y=MAP_H,
                                      gui=gui)

    #os.chdir(CURR_DIR)
        self.env = env
        self.engine = engine
        self.engine.setGameLevel(2)
        self.MAP_X = MAP_W
        self.MAP_Y = MAP_H
        self.PADDING = PADDING
        # shifts build area to centre of 120 by 100 tile map
        # self.MAP_XS = 59 - self.MAP_X // 2
        # self.MAP_YS = 49 - self.MAP_Y //2
        self.MAP_XS = 16
        self.MAP_YS = 8
        self.num_roads = 0
        self.engineTools = [
            'Residential',
            'Commercial',
            'Industrial',
            'FireDept',
            'PoliceDept',
            # TODO: implement query (skipped for now by indexing)
            'Query',
            'Wire',
            'Clear',
            'Rail',
            'Road',
            'Stadium',
            'Park',
            'Seaport',
            'CoalPowerPlant',
            'NuclearPowerPlant',
            'Airport',
            'Net',
            'Water',
            'Land',
            'Forest',
        ]
        # Names correspond to those of resultant zones
        if power_puzzle:
            self.tools = ['Wire']
        else:
            self.tools = [
                'Residential',
                'Commercial',
                'Industrial',
                'FireDept',
                'PoliceDept',
                # 'Query',
                'Clear',
                'Wire',
                # 'Land',
                'Rail',
                'Road',
                'Stadium',
                'Park',
                'Seaport',
                'CoalPowerPlant',
                'NuclearPowerPlant',
                'Airport',
                'Net',
                'Water',
                'Land',
                'Forest',
                'Nil'  # the agent takes no action
            ]
        #['Residential','Commercial','Industrial','Road','Wire','NuclearPowerPlant', 'Park', 'Clear']
        # since query is exluded for now:
        self.num_tools = len(self.tools)
        # TODO: move age-tracking into wrapper?
        self.map = TileMap(self,
                           self.MAP_X + 2 * PADDING,
                           self.MAP_Y + 2 * PADDING,
                           paint=paint)
        self.zones = self.map.zones
        self.num_zones = self.map.num_zones
        # allows building on rubble and forest
        self.engine.autoBulldoze = True
        # for bots
        self.land_value = 0

        #win1.playCity()
        if win1:
            win1.playCity()
        self.engine.resume()
        self.engine.setGameMode('play')

        self.init_funds = 2000000
        self.engine.setFunds(self.init_funds)
        self.engine.setSpeed(3)
        self.engine.setPasses(100)
        #engine.simSpeed =99
        self.total_traffic = 0
        self.last_total_traffic = 0
        #       engine.clearMap()
        self.win1 = win1
        self.player_builds = []