Пример #1
0
def makeMap(rows, cols, numBats, numBombs):

    world_map = []

    # Neighboring Coordinates
    # (-1,-1) (0,-1) (1,-1)
    # (-1, 0) robot  (1, 0)
    # (-1, 1) (0, 1) (1, 1)
    adj_x = [-1,0,1,-1,1,-1,0,1]
    adj_y = [-1,-1,-1,0,0,1,1,1]
    numNeighbors = len(adj_x)

    # Randomly pick a starting location for the robot
    startingLoc = [randint(0, cols-1), randint(0, rows-1)]

    # List to hold all of the world map pieces
    world_map = [[WorldSquare([x, y],0,0,False,0) for y in range(rows)] for x in range(cols)]


    # Place numBombs number of bombs randomly
    for i in range(numBombs):
        bomb_x = randint(0, cols - 1)
        bomb_y = randint(0, rows - 1)       

        # Bombs cannot be placed in squares bordering the starting location
        while (abs(startingLoc[0] - bomb_x) <= 1 and abs(startingLoc[1] - bomb_y) <= 1) or world_map[bomb_x][bomb_y].bomb:
            bomb_x = randint(0, cols - 1)
            bomb_y = randint(0, rows - 1)

        world_map[bomb_x][bomb_y].placeBomb() # Add bomb
        #print "Bomb location: (%d, %d)" % (bomb_x, bomb_y)

    # Place numBatteries number of batteries randomly
    batsPlaced = 0
    while batsPlaced < numBats:
        bat_x = randint(0, cols - 1)
        bat_y = randint(0, rows - 1)       

        if not (bat_x == startingLoc[0] and bat_y == startingLoc[1]):
            world_map[bat_x][bat_y].placeBat(randint(5, 10)) # Add battery
            print "Bat location: (%d, %d)" % (bat_x, bat_y)
            batsPlaced += 1
        
#    for i in range(numBats):
#        bat_x = randint(0, cols - 1)
#        bat_y = randint(0, rows - 1)       
#
#        world_map[bat_x][bat_y].placeBat(randint(2, 5)) # Add battery
#        print "Bat location: (%d, %d)" % (bat_x, bat_y)

    startingMap = WorldMap(world_map, startingLoc, numBombs, numBats, rows, cols)
     # update adjacent bomb and battery counts
    for r in range(rows):
        for c in range(cols):
            if world_map[c][r].bomb:
                neighbors = startingMap.getNeighbors([c, r])
                for neighbor in neighbors:
                    if not neighbor.bomb:
                        neighbor.addAdjBomb()
            if world_map[c][r].battery:
                neighbors = startingMap.getNeighbors([c, r])
                for neighbor in neighbors:
                    neighbor.addAdjBat()

                        
    startingMap.printMap()
    analysis("Numb bombs = " + str(numBombs))
    return startingMap
Пример #2
0
                                                           (etf, 'etf'),
                                                           (fon, 'fon')],
                                                          papers)
dept_qual_G = departments_qualitative.create_graph([(matf, 'matf'),
                                                    (etf, 'etf'),
                                                    (fon, 'fon')], papers)

mag_G = magazines.create_graph(papers, name_dict)
conf_G = conferences.create_graph(papers, name_dict)

etf_G = school.create_graph('etf', etf, papers, 'crimson')
matf_G = school.create_graph('matf', matf, papers, 'skyblue')
fon_G = school.create_graph('fon', fon, papers, 'teal', flag=True)
fon_is_G = school.create_graph('fon is', fon, papers, 'teal',
                               'Katedra za informacione sisteme')
fon_si_G = school.create_graph('fon si', fon, papers, 'lightseagreen',
                               'Katedra za softversko inzenjerstvo')
fon_it_G = school.create_graph('fon it', fon, papers, 'cadetblue',
                               'Katedra za informacione tehnologije')

util.analysis(dept_G, 'dept', True)
util.analysis(dept_qual_G, 'dept_qual', True)
util.analysis(mag_G, 'mag', False)
util.analysis(conf_G, 'conf', False)
util.analysis(etf_G, 'etf', False)
util.analysis(matf_G, 'matf', False)
util.analysis(fon_G, 'fon', True)
util.analysis(fon_is_G, 'fon_is', False)
util.analysis(fon_si_G, 'fon_si', False)
util.analysis(fon_it_G, ' fon_it', False)
Пример #3
0
 def mapSize(self):
     size = self.rows*self.cols
     analysis(size)