def __init__(self, owner, owner_name): self.owner = owner self.owner_name = owner_name self.workforce = 1 self.storage_capacity = 100 self.buildings = [ Building.Pipeline(), Building.Mine(), Building.Manor(), Building.Storage(), ] self.resources = { "gingerbread": 20, "cottoncandy": 20, "candy": 20, "chocolate": 20, } self.units = {} self.rallied_units = {} self.build_threads = [] # all attack actions going on from this player self.attack_threads = [] # all returning troop actions going on from this player self.return_threads = [] # a list of messages that will be send to you every fast update self.messages = [] self.protection = True
def setUp(self): starting_deck = [ Building.GreenBuilding('Tavern', 1), Building.GreenBuilding('Tavern', 1), Building.BlueBuilding('Temple', 1), Building.BlueBuilding('Chapel', 2) ] self.player = Player.Player("Napoleon", starting_deck)
def main(): pygame.init() Main.actors = Unit.Actor(Config.actors, Config.actorsx, Config.actorsy) Main.buildings = Building.Buildings(Config.actors, Config.actorsx, Config.actorsy) if Config.loadMap == 1: with open("Saves/Save.txt", "rb") as fp: Config.gameMap = pickle.load(fp) while Config.stop == 0: # Main loop, ends if Config.stop is changed # take keyboard input if Config.gameMode == 0: inputEditor() else: inputGame() if Config.pause == 0: Main.actors.allAct() drawAll() # call the draw map function pygame.display.update() # update map once updated # game time tempTime = time.time() * 1000 while tempTime < Config.frameTime + 90: tempTime = time.time() * 1000 pygame.time.wait(1) # pause for a short while Config.frameTime = tempTime # If loops exits pygame.quit() sys.exit()
def get_buildings(village): driver = village.driver #First get resource production buildings driver.get(server + "/dorf1.php") areas = driver.find_elements_by_css_selector("#rx > area") areas_href = [] for i in areas: areas_href.append(i.get_attribute("href")) #areas_href = (i.get_attribute("href") for i in areas) resource_buildings = [] for x in areas_href: print(x) driver.get(x) cost_spans = driver.find_elements_by_css_selector( "#contract > .resourceWrapper > .resource > .value") cost = [] for span in cost_spans: cost.append(int(span.text)) building = Building.Building() building.cost = cost building.href = x building.village = village building.is_resource = True resource_buildings.append(building) print(resource_buildings)
def gameInit(self): # make game board 0~16 self.boards.append(Board(0, 1, "정문", self.texArr)) self.boards.append(Board(1, 0, "넉터", self.texArr)) self.boards.append(Board(2, 0, "제6 공학관", self.texArr)) self.boards.append(Board(3, 0, "인문관", self.texArr)) self.boards.append(Board(4, 0, "대학본부", self.texArr)) self.boards.append(Board(5, 0, "제2 공학관", self.texArr)) self.boards.append(Board(6, 0, "문창회관", self.texArr)) self.boards.append(Board(7, 0, "자연대 연구실험동", self.texArr)) self.boards.append(Board(8, 0, "새벽벌도서관", self.texArr)) self.boards.append(Board(9, 0, "사회관", self.texArr)) self.boards.append(Board(10, 0, "금정회관", self.texArr)) self.boards.append(Board(11, 0, "법학관", self.texArr)) self.boards.append(Board(12, 0, "테니스장", self.texArr)) self.boards.append(Board(13, 0, "제 1도서관", self.texArr)) self.boards.append(Board(14, 0, "무지개문", self.texArr)) self.boards.append(Board(15, 0, "건설관", self.texArr)) self.dice = Dice(self.texArr) # player setting for player_no in range(4): self.player.append(Player(player_no)) # character setting for player_no in range(4): self.characters.append(Character(self, player_no, player_no)) for build_no in range(16): self.buildings.append((Building(build_no, self.texArr)))
def __init__(self): World.__init__(self) #load background self.background = pygame.image.load("Background.png").convert() #build building without elevators b = (0,0,150*ELEVS,50*FLOORS) block = Building.building(b) block.rect.x = 50 block.rect.y = 450 - (FLOORS*50) self.Building_list.add(block) #build proper amount of elevators for i in range(0,ELEVS): eblock = Building.elevator(Building.E) eblock.rect.x = 100 + (i * 150) eblock.rect.y = 400 self.elevator_list.add(eblock)
def main(): win = GraphWin("TestWindow", 1900, 1000) b1 = Building(100, 400, "gray", win, "black", "white") b2 = House(600, 400, color_rgb(219, 215, 177), win, "white", color_rgb(81, 45, 45)) b3 = Townhouse(1100, 400, color_rgb(102, 51, 0), win, "white", color_rgb(79, 36, 18)) win.getMouse() win.close()
def generateBuilding(matrix, p, height_map, simple_height_map): logging.info("Generating a building in lot {}".format(p)) h = prepareLot(matrix, p, height_map, (43, 8)) building = Building.generateBuilding(matrix, h, p[1], p[2], p[3], p[4], p[5]) toolbox.updateHeightMap(height_map, p[2] + 1, p[3] - 1, p[4] + 1, p[5] - 1, -1) toolbox.updateHeightMap(simple_height_map, p[2] + 1, p[3] - 1, p[4] + 1, p[5] - 1, -1) return building
def location_options(self, player_id, loc_name, loc_type, building_types): loc_inst = Location() build_inst = Building.Building() desc_str = "You find yourself in the {} of {}.\nYou see".format(loc_type, loc_name) opts_str = "[(M)ap] [(Q)uest] [(I)nventory] [(H)elp] [(E)xit]\n" for index, building_type in enumerate(building_types): if index < (len(building_types) - 1): desc_str += " a {},".format(building_type) elif index == (len(building_types) - 1): desc_str += " and a {}.\nWhat do you do?\n".format(building_type) opts_str += "{}) Go to {}\n".format((index + 1), building_type) opts_str += "{}) Leave {}\n".format((len(building_types)+1), loc_name) print(desc_str) print(opts_str) selection = input("Selection: ") try: select_num = int(selection) if select_num <= len(building_types): bldg_type = building_types[select_num-1] curr_name = characterInst.get_char_name(player_id) loc_id = loc_inst.get_current_location(curr_name) build_inst.enter_building(bldg_type, player_id, loc_id) else: print("Leaving {}".format(loc_name)) nearby_towns = loc_inst.leave(player_id, False) nearby_str = "[(M)ap] [(Q)uest] [(I)nventory] [(H)elp] [(E)xit]\n" for index, town in enumerate(nearby_towns): town_name = town["city_name"] nearby_str += "{}) Go to {}\n".format((index + 1), town_name) nearby_str += "{}) Head back into {}\n".format((len(nearby_towns) + 1), loc_name) print(nearby_str) travel_str = input("Selection: ") selection = travel_str travel_id = int(travel_str) if travel_id <= len(nearby_towns): dest_name = nearby_towns[travel_id-1]["city_name"] dest_obj = locationInst.go_to(dest_name, player_id) destType = dest_obj["town_description"] destBldgs = dest_obj["buildings"] self.location_options(player_id, dest_name, destType, destBldgs) else: dest_name = loc_name self.location_options(player_id, dest_name, loc_type, building_types) except ValueError: self.menu_option(selection, player_id, loc_name, loc_type, building_types)
def setUp(self): self.starting_deck = [ Building.GreenBuilding("Tavern", 1), Building.YellowBuilding("Estate", 3), Building.BlueBuilding("Temple", 1), Building.RedBuilding("Jail", 2) ] self.player = Player.Player("Napoleon", self.starting_deck) self.assassin = Role.Assassin() self.thief = Role.Thief() self.mage = Role.Mage() self.king = Role.King() self.bishop = Role.Bishop() self.merchant = Role.Merchant() self.architect = Role.Architect() self.warlord = Role.Warlord() self.roles = [ self.assassin, self.thief, self.mage, self.king, self.bishop, self.merchant, self.architect, self.warlord ]
def create_npc(self, player_id, typeStr, location_id): buildInst = Building.Building() with open('npc_names.json') as data: npc_names = json.load(data) random_npc = randint(0, len(npc_names) - 1) name = npc_names[random_npc]['name'] if (typeStr == 'BlackSmith'): function = 'Blacksmith' elif (typeStr == 'Tavern'): function = 'Bartender' elif (typeStr == 'Church'): function = 'Priest' elif (typeStr == 'Potion Shop'): function = 'Potion Dealer' elif (typeStr == 'Armor Shop'): function = 'Armor Dealer' elif (typeStr == 'Defense Shop'): function = 'Defense Dealer' elif (typeStr == 'Inn'): function = 'Innkeeper' elif (typeStr == 'Clinic'): function = 'Healer' fullName = name + " the " + function self.connection.cursor.execute( """INSERT INTO `NPC`(npc_name, npc_function, location_id) VALUES('{}', '{}', '{}');""".format(fullName, typeStr, location_id)) self.connection.conn.commit() print("Upon entering the {} you see someone working hard.\n".format( typeStr)) print("Options: \n") selection = input("1) Approach them\n" "2) Leave\n" "Selection: ") if selection == "1": print("\"Hello, I'm {}. I've got a problem can you handle it?\"\n". format(fullName)) choice = input("(Y/N) ") if choice == 'Y' or choice == 'y': #create quest description = self.create_quest(location_id, player_id) print("\"I need you to {}\"\n".format(description)) print("Quest added to your quest log!") else: print("OK then out ya go!\n") buildInst.leave_building(player_id, location_id)
def __init__(self, deck, left=True): """Build everything and get 6 cards from 'deck'""" res_x = Const.RESX res_y = Const.RESY pos_x = res_x - 11 * res_x / 80 if left: pos_x = res_x / 80 self.tower = Building.Building(left, True, Const.INIT_TOWER) self.wall = Building.Building(left, False, Const.INIT_TOWER / 2) self.brick = Ressource.Ressource((pos_x, res_y / 20), Const.DARK_RED, _("Bricks")) self.gem = Ressource.Ressource((pos_x, res_y / 10 + res_y / 7), Const.DARK_BLUE, _("Gems")) self.crea = Ressource.Ressource( (pos_x, 3 * res_y / 20 + 2 * res_y / 7), Const.DARK_GREEN, _("Creatures")) self.cards = [] for i in xrange(1, 7): self.cards.append( deck.get_card((i * res_x / 49 + (i - 1) * res_x / 7, res_y - Const.CARD_HEIGHT))) self.win = False self.deck = deck
def expandNode(self, currentState, move): gameState = currentState.fastclone() # ourInventory = gameState.inventories[self.playerId] ourId = gameState.whoseTurn ourInventory = gameState.inventories[gameState.whoseTurn] if (move.moveType == MOVE_ANT): antToMove = None for ant in ourInventory.ants: if ant.coords == move.coordList[0]: antToMove = ant if antToMove is not None: antToMove.coords = move.coordList[-1] antToMove.hasMoved = True # check if other ants near by for attack opponentId = self.getOpponentId(gameState.whoseTurn) enemyInv = gameState.inventories[opponentId] ## Checks if can attack. self.attackSequence(enemyInv, antToMove) elif (move.moveType == BUILD): # just worried about building Ants and Tunnel if (move.buildType == WORKER): # add ant ourInventory.ants.append(Ant(move.coordList[-1], WORKER, ourId)) # subtract food ourInventory.foodCount -= 1 elif (move.buildType == DRONE): ourInventory.ants.append(Ant(move.coordList[-1], DRONE, ourId)) ourInventory.foodCount -= 1 elif (move.buildType == SOLDIER): ourInventory.ants.append( Ant(move.coordList[-1], SOLDIER, ourId)) ourInventory.foodCount -= 2 elif (move.buildType == R_SOLDIER): ourInventory.ants.append( Ant(move.coordList[-1], R_SOLDIER, ourId)) ourInventory.foodCount -= 2 elif (move.buildType == TUNNEL): ourInventory.constrs.append( Building(move.coordList[-1], TUNNEL, ourId)) ourInventory.foodCount -= 3 else: self.pickUpFood(gameState, ourInventory) self.dropOffFood(gameState, ourInventory) return gameState return gameState
def rightClic(self, pos, playerId): if self.isAlive: if self.isAlly(playerId) == False or playerId == self.id: for i in self.units: unit = i.select(pos) if unit != None: return unit unit = self.motherShip.select(pos) if unit != None: return unit for b in self.buildings: building = b.select(pos) if building != None: return building return None
def __init__(self, settings, gui): if isinstance(settings, Config.Config_World): self.settings = settings self.gui = gui if isinstance(settings.screen, Config.Config_Screen): render.start(self.settings.screen.x_pos, self.settings.screen.y_pos, self.settings.screen.x_size, self.settings.screen.y_size, 1000) # creating city grid for b in range(2): self.x_location += 100 self.y_location = 90 for z in range(3): self.y_location -= 20 # self.x_location += 20 for i in range(2): self.y_location -= 10 self.x_location -= 20 self.c = random.randint(0, 1) for t in range(2): self.c2 = random.randint(0, 1) b_location = P3.P3(self.x_location, self.y_location, 0) # print(b_location) buildings.extend([ Building.Building(b_location, 10, random.randrange(20, 65), 10, (self.c, 0, self.c2)) ]) self.x_location += 10 if isinstance(settings, Config.Config_World): flock = settings.flocks[0] if isinstance(flock, Config.Config_Flock): self.F1 = Flock.Flock(flock.count, World.make_force_field(buildings), flock.center, flock.radius) self.render = render.Render(self.F1) gui.set_tick_method(self.tick)
def castData(self, file): print "load data" way = None lines = open(file).readlines() with open(file, "r") as fp: for lineNumber, line in enumerate(fp): if "<node id=" in line: pointInfo = self.castPoint(line) self.points[pointInfo[0]] = Point.PointNode( pointInfo[0], pointInfo[1], pointInfo[2]) #point object #reading info between two </ways> if "</way>" in line: if way: buildInfo = self.castBuild(way, lineNumber + 1, lines) self.buildings[buildInfo[0]] = Building.BuildingNode( buildInfo[0], buildInfo[1], buildInfo[2], buildInfo[3], buildInfo[4]) #building object way = lineNumber + 1
def generateRandomBuildings(numberOfBuildings, city, areaRange=[10, 1000]): direct = city.streetNWAdm.getDirectEdges() buildings = [] for _ in range(numberOfBuildings): randomNumber = random.randint(0, len(direct) - 1) randomEdge = direct[randomNumber] # Filter not highway ways and some unwanted highway ways if not city.isStreetWay(randomEdge[City.WAY]): continue nodeId = ToolsExt.generateRandomNodeInEdge(randomEdge, city) randomArea = random.randint(areaRange[0], areaRange[1]) building = Building.Building(nodeId, randomArea, city.getNodeLat(nodeId), city.getNodeLon(nodeId)) buildings.append(building) return buildings
def populate(self): """adds all the people and make sure they don't go all ape shit """ FARMER_COUNT = 4 VILLAGER_COUNT = 5 BUILDER_COUNT = 1 lumber1 = Building.LumberYard(self, self.lumberyard_img) lumber1.location = vector2.Vector2(self.w / 2, self.h / 2) lumber1.tile_x, lumber1.tile_y = 4, 4 self.add_entity(lumber1) for Villager_no in xrange(VILLAGER_COUNT): """Adds all Wood Cutters """ villager = Lumberjack.Lumberjack(self, self.lumberjack_img) villager.location = lumber1.location.copy() villager.LastLumberYard = lumber1 villager.brain.set_state("Searching") self.add_entity(villager) self.population += 1 for Building_no in xrange(BUILDER_COUNT): builder = Builder.Builder(self, self.builder_img, lumber1) builder.location = lumber1.location.copy() builder.brain.set_state("Idle") self.add_entity(builder) self.population += 1 for FARMER in xrange(FARMER_COUNT): """Adds all the farmers """ farmer = Farmer.Farmer(self, self.farmer_img) farmer.location = vector2.Vector2(20, 20) farmer.brain.set_state("Planting") self.add_entity(farmer) self.population += 1
def test_add_card(self): new_deck = BuildingDeck.BuildingDeck() new_deck.add(Building.GreenBuilding("Tavern", 1))
def test_buildable(self, building, built, pos): if building == "LumberYard": if built: Build = Building.LumberYard(self, self.lumberyard_img) else: Build = Building.UnderConstruction(self, self.uc_img, "LumberYard") elif building == "House": if built: Build = Building.House(self, self.house_img) else: Build = Building.UnderConstruction(self, self.uc_house_img, "House") elif building == "Dock": if built: Build = Building.Dock(self, self.dock_img) else: Build = Building.UnderConstruction(self, self.ucw_img, "Dock") elif building == "Manor": if built: Build = Building.Manor(self, self.manor_img) else: Build = Building.UnderConstruction(self, self.uc_img, "Manor") buildable = 1 land = 0 water = 0 Twidth, Theight = Build.image.get_size() for i in range(Twidth >> 5): for j in range(Theight >> 5): try: if built: test_tile = self.get_tile( vector2.Vector2((pos.x - 32) + (i << 5), (pos.y - 32) + (j << 5))) #print "A", test_tile, test_tile.location else: test_tile = self.get_tile( vector2.Vector2( ((pos.x - 32) - self.background_pos.x) + (i << 5), ((pos.y - 32) - self.background_pos.y) + (j >> 5))) #print "B", test_tile, test_tile.location if test_tile.buildable != 1 and building != "Dock": buildable = 0 return 0 elif building == "Dock": if test_tile.buildable_w: water += 1 elif test_tile.buildable: land += 1 except IndexError: print 'IndexError' return 0 if building == "Dock" and not built: if water >= 1 and land <= 2 and land > 0: #print ('buildable', water, land) buildable = 1 return 1, Build else: #print ('not buildable', water, land) buildable = 0 return 0 return 1, Build
import Building import Sprite import pygame building1 = Building.Building( Sprite.Sprite(pygame.image.load('images/ArcherTowerBuilding.png')), Building.archerTowerEffect, 1) buildings = [building1]
def setUp(self): self.tavern = Building.GreenBuilding('Tavern', 1) self.university = Building.PurpleBuilding('University', 6)
RSI_steel_door = 35 # Building Materials (Mark's addition) RSI_interior_wall = .1 * RSI_drywall + .2 * RSI_fiberglass RSI_exterior_wall = .05 * RSI_drywall + .3 * RSI_fiberglass + .15 * RSI_concrete RSI_roofing = 0.05 * RSI_drywall + 0.3 * RSI_fiberglass + RSI_wood_roof # inline function for parallel Reff r_par = lambda A, R: 1 / (sum(np.divide(np.array(A), np.array(R))) / sum( np.array(A))) #note: A and R must be np arrays ## Creating the building L = 17 #length of building, replace w/ your own value W = 13 #width of building Tmin = [294, 294, 294, 294, 294, 291, 290] Tmax = [300, 300, 300, 300, 300, 305, 295] building = Building(L, W) TH_range = [300, 320] fH_max = 4 building.addHeater(TH_range, fH_max, building) TC_range = [285, 295] fC_max = 2 building.addCooler(TC_range, fC_max, building) ## Add rooms # use building.addRoom(roomID,TRange,roomL,roomW) building.addRoom(0, [294, 300], 6, 5) building.addRoom(1, [294, 300], 5, 7) building.addRoom(2, [294, 300], 8, 8) building.addRoom(3, [294, 300], 5, 6) building.addRoom(4, [294, 300], 6, 5) building.addRoom(5, [291, 305], 4, 4)
from Graphics import * import time from Building import * from Base import * win = GraphWin("City",1900,1000) land = City(win) land.backdrop() b1 = Building(100, 350, "gray", win, "black", "white") b2 = House(600, 350, color_rgb(219, 215, 177), win, "white", color_rgb(81, 45, 45)) b3 = Townhouse(1200, 350, color_rgb(102, 51, 0), win, "white", color_rgb(79, 36, 18)) land.drawBox() win.getMouse() y = 0 vlc.MediaPlayer("siren.wav").play() while y <= 600: nuke = Nuke(win, 950, y) y += 100 time.sleep(1) nuke.explode() win.getMouse()
import time as t c=input(('PRESS SPACE TO ENTER THE CITY')) if(c==' '): ch=int(input('WHAT WOULD YOU LIKE TO DO\n1.WANT TO ENTER THE BUILDING\n2.WANT TO ENTER THE FACTORY\n3.MAKE ANNOUNCEMENT IN PLAYGROUND\n4.HOSPITAL STATUS\n5.ROAD STATUS')) if(ch==1): import Building a=int(input('1.PARKING\n2.TEMPERATURE\n')) if(a==1): Building.parking() else: for i in range(0,10): Building.Temp() time.sleep(1) elif(ch==2): import factory factory.Factory() elif(ch==3): import playground elif(ch==4): import smartcity_ir
def test_green_taxing(self): tavern = Building.GreenBuilding('Tavern', 1) self.player.build_building(tavern) self.player.tax() self.assertEqual(self.player.get_gold(), 2)
def kill(self): self.isAlive = False for i in self.units: i.kill() for b in self.buildings: b.kill()
def test_build_too_expensive(self): too_expensive_building = Building.RedBuilding('Warfield', 3) self.player.take_card(too_expensive_building) self.assertEqual(self.player.build_building(too_expensive_building), False)
def gameInit(self): self.sounds = Sound.Sound() self.building = Building.Building(self.screen, self.screenSize) if self.rainEffect: self.weather = [] for columnNumber in range(1, self.building.leftWallX // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.floorY)) for columnNumber in range(self.building.leftWallX // Weather.SIZE, self.building.rightWallX // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.leftWallX)) for columnNumber in range(self.building.rightWallX // Weather.SIZE, self.screenWidth // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.floorY)) self.sky = Weather.Sky(self.screen, self.screenWidth, self.screenHeight, self.building.leftWallX, self.building.rightWallX, self.building.ceilingY, self.sounds) # RANDOMLY SPAWNED self.hero = Character.Player(self.screen, self.building, self.screenWidth, self.screenHeight) self.cultist = Trash.Cultist(self.screen, self.building) self.enemiesToSpawn.append(self.cultist) self.cultist2 = Trash.Cultist(self.screen, self.building) self.enemiesToSpawn.append(self.cultist2) self.angel = Trash.Angel(self.screen, self.building) #self.enemies.append(self.angel) #self.angel.spawn() self.enemiesToSpawn.append(self.angel) self.skeleton = Trash.Skeleton(self.screen, self.building) self.enemiesToSpawn.append(self.skeleton) self.skeleton2 = Trash.Skeleton(self.screen, self.building) self.enemiesToSpawn.append(self.skeleton2) self.bomb = Equipment.Bomb(self.screen, self.building) self.equipmentToSpawn.append(self.bomb) self.bomb2 = Equipment.Bomb(self.screen, self.building) self.equipmentToSpawn.append(self.bomb2) self.garlic = Equipment.Garlic(self.screen, self.building) self.equipmentToSpawn.append(self.garlic) self.garlic2 = Equipment.Garlic(self.screen, self.building) self.equipmentToSpawn.append(self.garlic2) self.flute = Equipment.Flute(self.screen, self.building) self.equipmentToSpawn.append(self.flute) self.flute2 = Equipment.Flute(self.screen, self.building) self.equipmentToSpawn.append(self.flute2) self.rune = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune) self.rune2 = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune2) self.rune3 = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune3) self.sword = Equipment.Sword(self.screen, self.building) self.equipmentToSpawn.append(self.sword) self.whip = Equipment.Whip(self.screen, self.building) self.equipmentToSpawn.append(self.whip) self.shield = Equipment.Shield(self.screen, self.building) self.equipmentToSpawn.append(self.shield)
def generate_buildings(): return [Building.Market({Item.Apple(10,"Mich."):10,Item.Bread(15,"France"):7})]
def initialize_starting_deck(self): for i in range(5): self.add(Building.GreenBuilding("Tavern", 1)) for i in range(4): self.add(Building.GreenBuilding("Market", 2)) for i in range(3): self.add(Building.GreenBuilding("Merchant's House", 2)) self.add(Building.GreenBuilding("Dock", 3)) self.add(Building.GreenBuilding("Port", 4)) for i in range(2): self.add(Building.GreenBuilding("Town Hall", 5)) for i in range(3): self.add(Building.BlueBuilding("Temple", 1)) self.add(Building.BlueBuilding("Chapel", 2)) self.add(Building.BlueBuilding("Monastery", 3)) for i in range(2): self.add(Building.BlueBuilding("Cathedral", 5)) for i in range(3): self.add(Building.RedBuilding("Sentry Tower", 1)) self.add(Building.RedBuilding("Jail", 2)) self.add(Building.RedBuilding("Warfield", 3)) for i in range(2): self.add(Building.RedBuilding("Stronghold", 5)) for i in range(5): self.add(Building.YellowBuilding("Estate", 3)) for i in range(4): self.add(Building.YellowBuilding("Castle", 4)) for i in range(3): self.add(Building.YellowBuilding("Palace", 5)) self.add(Building.PurpleBuilding("University", 6)) self.add(Building.PurpleBuilding("Dragon's Gate", 6))
def test_start_player_turn_take_card(self): self.player.take_card(Building.RedBuilding('Warfield', 3)) self.assertEqual(len(self.player.get_hand_deck()), 5)
def main(num_people): #initial the elevator system system = System(3) #initial the building with total number of customers, total floor by default is 5 building = Building(num_people) #pools = building.adict max_iter = 2500 count = {0: 3, 1: 3, 2: 3} peoplecount = 0 a = 0 # start the simulation for step in range(max_iter): # print step # print peoplecount ## if peoplecount < building.total_cus if peoplecount < 0.6 * building.total_cus or ( len(system.elevators[0].remain_list) + len(system.elevators[1].remain_list) + len(system.elevators[2].remain_list)) > 0: #Update pool in each level pools = building.dictionUpdate() system.requireOut(pools) #print pools[1].alreadyIn for key in system.elevators: #print 1,system.elevators[0].direction,system.elevators[0].cur_floor #print system.requireout_up,system.requireout_down,len(system.elevators[0].remain_list),len(system.elevators[1].remain_list) #update RequireOut information system.outdemand(key) #print system.elevators[key].cur_floor #direction change system.DecisionDecide(system.elevators[key]) #print system.elevators[2].Aimminglist #move or load & release customers #if elevator stops, it will stop 4 time step # print count[0] # print 0,system.elevators[0].Aimminglist #print key,system.elevators[0].cur_floor,len(system.elevators[0].remain_list),system.elevators[0].Aimminglist,system.elevators[0].direction,count[0] # print system.elevators[key].Aimminglist,key if count[key] == 3: if (system.elevators[key].cur_floor == 1 and system.elevators[key].direction == 'down'): system.elevators[key].direction = 'stay' elif (system.elevators[key].cur_floor == len( system.requireout_up) and system.elevators[key].direction == 'up'): system.elevators[key].direction = 'stay' system.elevators[key].move() # print system.requireout_up,system.requireout_down # if there's requires,open the door, upload & release customers if len(system.elevators[key].Aimminglist) == 1: if system.elevators[key].Aimminglist[ 0] == system.elevators[key].cur_floor: count[key] = 0 else: if system.elevators[key].Aimminglist[ 0] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[1] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[ -1] == system.elevators[ key].cur_floor: count[key] = 0 else: #print system.elevators[0].cur_floor,system.elevators[0].direction,count[0] if len(system.elevators[key].Aimminglist) == 1: count[key] = count[key] + 1 if system.elevators[key].Aimminglist[ 0] == system.elevators[key].cur_floor: j = 0 while j < len(system.elevators[key].remain_list): cus = system.elevators[key].remain_list[j] if cus.dest_floor == system.elevators[ key].cur_floor: system.elevators[key].cancel_customer(cus) A4 = system.elevators[key].Aimminglist[1:] if system.elevators[key].cur_floor in A4: A4.remove( system.elevators[key].cur_floor) system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + A4 peoplecount = peoplecount + 1 else: j = j + 1 if len(system.elevators[key].remain_list ) == system.elevators[key].capacity: pass else: if (system.elevators[key].direction == "up") or ( (system.elevators[key].direction == 'stay') and (len(pools[system.elevators[key]. cur_floor].pool_up) >= len(pools[system.elevators[key]. cur_floor].pool_down))): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_up): cus = pools[system.elevators[key]. cur_floor].pool_up[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Uppoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break elif (system.elevators[key].direction == "down") or ( system.elevators[key].direction == 'stay' and len(pools[system.elevators[key]. cur_floor].pool_up) < len(pools[system.elevators[key]. cur_floor].pool_down)): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_down): cus = pools[system.elevators[key]. cur_floor].pool_down[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Downpoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break else: pass system.elevators[key].requireIn.sort() for i in system.elevators[key].requireIn: if i not in system.elevators[key].Aimminglist[ 1:]: system.elevators[key].Aimminglist.append(i) Aimin = system.elevators[key].Aimminglist[1:] Aimin.sort() system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + Aimin else: count[key] = count[key] + 1 if system.elevators[key].Aimminglist[ 1] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[( len(system.elevators[key]. Aimminglist) - 1 )] == system.elevators[key].cur_floor: #print 100,system.elevators[key].Aimminglist i = 0 while i < len(system.elevators[key].remain_list): cus = system.elevators[key].remain_list[i] if cus.dest_floor == system.elevators[ key].cur_floor: system.elevators[key].cancel_customer(cus) A4 = system.elevators[key].Aimminglist[1:] if system.elevators[key].cur_floor in A4: A4.remove( system.elevators[key].cur_floor) system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + A4 peoplecount = peoplecount + 1 else: i = i + 1 if len(system.elevators[key].remain_list ) == system.elevators[key].capacity: pass else: if (system.elevators[key].direction == "up") or ( (system.elevators[key].direction == 'stay') and (len(pools[system.elevators[key]. cur_floor].pool_up) >= len(pools[system.elevators[key]. cur_floor].pool_down))): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_up): cus = pools[system.elevators[key]. cur_floor].pool_up[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Uppoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break elif (system.elevators[key].direction == "down") or ( system.elevators[key].direction == 'stay' and len(pools[system.elevators[key]. cur_floor].pool_up) < len(pools[system.elevators[key]. cur_floor].pool_down)): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_down): cus = pools[system.elevators[key]. cur_floor].pool_down[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Downpoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break else: pass system.elevators[key].requireIn.sort() for i in system.elevators[key].requireIn: if i not in system.elevators[key].Aimminglist[ 1:]: system.elevators[key].Aimminglist.append(i) Aimin = system.elevators[key].Aimminglist[1:] Aimin.sort() system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + Aimin else: return step