def search(self): if self.searchText.text().isdigit(): self.show_shopWindow(self.searchText.text()) return foodIds = self.user.search_foods(self.searchText.text()) fText = '\n'.join(str(entities.Food(x)) for x in foodIds) shopIds = self.user.search_shops(self.searchText.text(), self.selected_address) sText = '\n'.join(str(entities.Shop(x)) for x in shopIds) self.scrollArea1.setText(fText) self.scrollArea2.setText(sText)
def retranslateUi(self, ShopWindow): _translate = QtCore.QCoreApplication.translate ShopWindow.setWindowTitle(_translate("ShopWindow", "صفحهی فروشگاه")) i = 0 if not self.prv: for x in entities.Shop(self.shopId).foods: self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(400, 150 + i * 30, 321, 21)) self.label.setLayoutDirection(QtCore.Qt.RightToLeft) self.label.setText(_translate("ShopWindow", str(x))) self.label.setObjectName(f"label{i}") self.spinBox = QtWidgets.QSpinBox(self.centralwidget) self.spinBox.setGeometry(QtCore.QRect(730, 150 + i * 30, 48, 26)) self.spinBox.setLayoutDirection(QtCore.Qt.LeftToRight) self.spinBox.setObjectName(f"spinBox{i}") i += 1 else: for f in self.user.previous_foods(self.shopId): x = entities.Food(f) self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(400, 150 + i * 30, 321, 21)) self.label.setLayoutDirection(QtCore.Qt.RightToLeft) self.label.setText(_translate("ShopWindow", str(x))) self.label.setObjectName(f"label{i}") self.spinBox = QtWidgets.QSpinBox(self.centralwidget) self.spinBox.setGeometry(QtCore.QRect(730, 150 + i * 30, 48, 26)) self.spinBox.setLayoutDirection(QtCore.Qt.LeftToRight) self.spinBox.setObjectName(f"spinBox{i}") i += 1 self.backLB.setText(_translate("ShopWindow", "بازگشت")) self.dnBT.setText(_translate("ShopWindow", "ثبت سفارش")) self.backLB.clicked.connect(self.back) self.dnBT.clicked.connect(self.dn) if not self.prv: self.preBT.setText(_translate("ShopWindow", "سفارشهای قبل")) self.preBT.clicked.connect(self.prev) else: self.preBT.setText(_translate("ShopWindow", "همهی غذاها")) self.preBT.clicked.connect(self.all)
def __init__(self, gridWidth, gridHeight, numObstacles): # create snake and food objects self.agent = ent.Snake(SNAKE_INITIAL_LENGTH) self.food = ent.Food() self.obstacles = [-1] * numObstacles # set the environment self.environment = env.Environment(gridWidth, gridHeight, SNAKE_INITIAL_LENGTH, self.agent, self.food, STRENGTH_LINE_OF_SIGHT, RANGE_LINE_OF_SIGHT) # set parameters self.actualEpsilon = EPSILON self.actualGamma = GAMMA self.actualAlpha = ALPHA self.episodesLeft = EPISODES self.numberOfstepsTaken = 0 # init QTable self.QTable = qt.QTable(gridWidth, gridHeight) self.QTable.initTable(RANGE_LINE_OF_SIGHT, STRENGTH_LINE_OF_SIGHT, self.environment.getEntities()) # statistics #steps self.arrayAverageSteps = [MAX_STEPS_PER_EPISODE] * 10 self.arrayAverageReward = [0] * 30 #reward self.averageReward = 0 self.averageSteps = 0 self.lastReward = 0 #collisions self.counterCollisionsWithItself = 0 self.counterCollisionsWithWall = 0
def main(): """ This is the entry point in to the Nurltown ecosystem simulator. The function does the following: 1. Instantiates a Pygame session 2. Set the game configuration and utilities 3. Populates the ecosystem with an initial collection of nurlets and food 4. Continuously runs a loop of updating the states of the game entities and redrawing the game state """ width, height = cfg.GAME_WIDTH, cfg.GAME_HEIGHT # import the game dimensions from the configuration file pg.init() # initialize the pygame module pg.font.init() # initialize the font library # Create a text object to test the game loop test_font = pg.font.SysFont('Helvetica', 30) test_text = test_font.render('GAME DEVELOPMENT IN PROGRESS...', False, (255, 0, 0)) screen = pg.display.set_mode( (width, height)) # create a display object representing the game screen constrain_within_screen = screen_constraint_generator(screen) get_random_pos = random_pos_generator(screen) nurlets = pg.sprite.Group() hostiles = pg.sprite.Group() food = pg.sprite.Group() nurlet = ntts.Nurlet(width / 2, height / 2) hostile_nurlets = [ntts.HostileNurlet(*get_random_pos()) for x in range(2)] jellies = [ntts.Food(*get_random_pos()) for x in range(cfg.MAX_NUM_FOOD)] entity_groups = [food, nurlets, hostiles] nurlets.add(nurlet) hostiles.add(hostile_nurlets) food.add(jellies) while True: # Handle the events that the game instance encounters # Events can be mouse movements/clicks, key presses, window resizing, joystick use, etc. # You can read more about the supported event types here: # https://www.pg.org/docs/ref/event.html events = pg.event.get() keys_pressed = pg.key.get_pressed() for event in events: # Quit the game and program when the 'x' button on the window is pressed if event.type == pg.QUIT: sys.exit() # Adds a quick way to exit the game by press the ';' button if event.type == pg.KEYDOWN and event.key == pg.K_SEMICOLON: sys.exit() # Clear the screen screen.fill(colors.black) # Update the nurlets nurlets.update(food, keys_pressed) # Update the hostiles hostiles.update(food) # Replenish food num_to_respawn = max(0, cfg.MAX_NUM_FOOD - len(food)) if num_to_respawn: food.add(ntts.Food(*get_random_pos())) # Redraw the entities for group in entity_groups: for sprite in group.sprites(): constrain_within_screen(sprite) group.draw(screen) # Display test text screen.blit(test_text, (180, 500)) # Display the health bar draw_health_bar(screen, nurlet.hp) pg.display.update()