Esempio n. 1
0
def get_food():
    """
    -------------------------------------------------------
    Creates a food object by requesting data from a user.
    Use: f = get_food()
    -------------------------------------------------------
    Returns:
        food - a completed food object (Food).
    -------------------------------------------------------
    """

    n = input("Enter Name:")
    
    print("Origin")
    
    # Create food object to use the origins function
    p = Food("Butter Chicken", 2 , True, 120)
    print(p.origins())
    
    o = int(input(":"))
    v = input("Vegetarian (Y/N):")
    if v == "Y":
        v = True
    
    if v == "N":
        v = False
        
    c = int(input("Calories:"))
    
    food = Food(n, o, v == True, c)

    return food
Esempio n. 2
0
    def instruction(self):
        self.elements = []
        self.text_menu = arcade.draw_text("Instruction",
                                          self.center,
                                          self.high,
                                          arcade.color.WHITE,
                                          30,
                                          align="center",
                                          anchor_x="center")

        icon_food = Food(0, self.center - 180, self.high - 50)
        icon_speed = Food(1, self.center - 180, self.high - 80)
        icon_slow = Food(2, self.center - 180, self.high - 110)
        icon_ghost_walk = Food(3, self.center - 180, self.high - 140)
        icon_color = Food(4, self.center - 180, self.high - 170)

        back_button = MenuButton("Close", self.center, self.high - 325, 15,
                                 self.setup)

        self.icons.append(icon_food)
        self.icons.append(icon_speed)
        self.icons.append(icon_slow)
        self.icons.append(icon_ghost_walk)
        self.icons.append(icon_color)

        self.elements.append(back_button)
        self.is_instruction = True
Esempio n. 3
0
def main():
    food = Food("grape", 3, True, 2)
    food1 = Food("chicken", 2, False, 1)
    food2 = Food("sushi", 3, True, 12)
    foods = [food, food1, food2]
    avg = average_calories(foods)
    print(avg)
Esempio n. 4
0
def routineTo(sf, cf):
    gen = Genetic(sf, cf)
    fen = fenetre()
    food = Food(fen)
    #newFen = newFenTop()
    #texts = addScoreOnTopWindows(newFen, int(Params.p['sizePop']))
    pop = Population(fen, food)
    pop.setInitialPositions()
    for i in range(int(Params.p['nbEvol'])):
        popName = "pop_" + str(i)
        if i > 0:
            gen.createNewPopulation(pop)
            food = Food(fen)
            pop.setFood(food)
            pop.setInitialPositions()
        #newFen[1].itemconfig(newFen[2], text=popName)
        t = time.time()
        #while time.time() - t < Params.p['lifeTime']:
        j = 0
        while j < Params.p['lifeTime']:
            #refreshScores(newFen, texts, pop)
            pop.routineForPopulation()
            fen.refreshScreen()
            j += 1
        timeGen = time.time() - t
        print("Execution time: ", timeGen)
        savePop(pop, popName = popName)
    fen.fen.destroy()
Esempio n. 5
0
def main():
    '''
    s = Stack()
    arr = [11, 22, 33, 44, 55, 66]
    array_to_stack(s, arr)
    for v in s:
        print(v)
    stack_to_array(s,arr)
    print(arr)
    '''
    '''
    arr2 = [1,2,3,4]
    s2 = Stack()
    for a in arr2:
        s2.push(a)
    stack_test(s2)
    for v in s2:
        print(v)
    '''
    #testing the stack
    arr2 = [1, 2, 3, 4]
    stack_test(arr2)

    f = Food("bread", 10, True, 55)
    g = Food("grape", 6, False, 9)
    foods = [f, g]
    stack_test(foods)
    '''
Esempio n. 6
0
def main():
    f1 = Food("not spring rolls", 1, False, 66)
    f2 = Food("spring rolls wrong", 2, True, 653)
    f3 = Food("good spring rolls", 1, True, 7)
    source = [f1, f2, f3]
    source2 = [6, 8, 2]
    list_test(source)
Esempio n. 7
0
def main():
    food = Food("grape", 3, True, 5)
    food1 = Food("chicken", 2, False, 67)
    food2 = Food("sushi", 3, True, 12)
    food3 = Food("water", 3, True, 0)
    foods = [food, food1, food2, food3]
    a = calories_by_origin(foods, 3)
    print(a)
Esempio n. 8
0
 def place_food(self):
     x = randint(0, self.height - 1)
     y = randint(0, self.width - 1)
     food = Food(x, y)
     while food.position in self.snake.snakeBody:
         x = randint(0, self.height - 1)
         y = randint(0, self.width - 1)
         food = Food(x, y)
     return food
Esempio n. 9
0
def main():

    food = Food("grape", 3, True, 67)
    food1 = Food("chicken", 2, False, 67)
    food2 = Food("sushi", 3, True, 67)
    foods = [food, food1, food2]
    v = by_origin(foods, 3)
    for s in v:
        print(s)
Esempio n. 10
0
def main():
    food = Food("grape", 3, True, 5)
    food1 = Food("chicken", 2, False, 67)
    food2 = Food("sushi", 3, True, 10)
    food3 = Food("water", 3, True, 0)
    foods = [food, food1, food2, food3]
    result = food_search(foods, -1, 0, True)

    for f in result:
        print(f)
def read_food(line):
    """
    -------------------------------------------------------
    Creates and returns a food object from a line of string data.
    Use: f = read_food(line)
    -------------------------------------------------------
    Parameters:
        line - a vertical bar-delimited line of food data in the format
          name|origin|is_vegetarian|calories (str)
    Returns:
        food - contains the data from line (Food)
    -------------------------------------------------------
    """

    l = line.split("|")
    name = l[0]
    ori = int(l[1])
    vegTemp = l[2]
    if vegTemp == "True":
        veg = True
    else:
        veg = False
    cal = int(l[3])
    food = Food(name, ori, veg, cal)

    return food
Esempio n. 12
0
def buildLargeMenu(numItems, maxValue, maxCost):
    items = []
    for i in range(numItems):
        items.append(
            Food('num-' + str(i), random.randint(1, maxValue),
                 random.randint(1, maxCost)))
    return items
Esempio n. 13
0
 def dropFood(self):
     for i in range(0, Constants.STARTING_FOOD):
         overlapping = True
         while overlapping:
             overlapping = False
             x = random.uniform(
                 Constants.FOOD_RADIUS * 2,
                 Constants.PETRI_DISH_WIDTH - Constants.FOOD_RADIUS * 2)
             y = random.uniform(
                 Constants.FOOD_RADIUS * 2,
                 Constants.PETRI_DISH_HEIGHT - Constants.FOOD_RADIUS * 2)
             for entity in self.entities:
                 delta = math.sqrt(
                     abs(
                         math.pow((entity.getMyX() - x), 2) +
                         math.pow((entity.getMyY() - y), 2)))
                 if (delta <=
                     (entity.getRadius() + Constants.FOOD_RADIUS + 20)):
                     overlapping = True
             for microbe in self.microbes:
                 delta = math.sqrt(
                     abs(
                         math.pow((microbe.getMyX() - x), 2) +
                         math.pow((microbe.getMyY() - y), 2)))
                 if (delta <=
                     (microbe.getRadius() + Constants.FOOD_RADIUS + 20)):
                     overlapping = True
         food = Food(x, y)
         self.addEntity(food)
Esempio n. 14
0
def test():
    fen = fenetre()
    food = Food(fen)
    ant = Ant(fen)
    fen.setObj(ant.id)
    fen.setFoodObj(food)
    fen.fen.mainloop()
Esempio n. 15
0
 def __init__(self):
     self.player = Player(self.screen ,self.x,self.y)
     self.collider=Collider(self.screen,self.player.arrows,self.badguys,self.player,self.foods)
     self.food = Food(self.screen,self.food_x, self.food_y)
     self.wl=WL(self.screen,self.exitcode)
     self.timer=Timer(self.screen,self.count)
     self.screen2=Screen2(self.screen,self.width,self.height)
Esempio n. 16
0
    def __init__(self, width, height):
        # Set the name of the game
        pygame.display.set_caption('Snake Game')
        
        # Define width and height for the game window
        self.width = width
        self.height = height

        # Create a window for the game with width and height. In this case the 
        # height is increased by 60 pixels to add extra components
        self.gameDisplay = pygame.display.set_mode((width, height + 60))
        
        # Load the background image
        self.background = pygame.image.load('img/background.png')

        # Initilizied the flag crash. It will be used to check the status of
        # the game
        self.crash = False

        # Initilize a player
        self.player = Snake(self)
        
        # Spawn a food
        self.food = Food()

        # Initialize the score to zero
        self.score = 0
Esempio n. 17
0
    def loadWorld(self, worldFile):
        self.reset()
        self.main_gui.button_go["text"] = "Go =>"
        if self.charged > 0 and self.main_gui.is_modifying.get() == True:
            self.main_gui.on_modif_state_change()
        self.charged += 1

        with open(f"worlds/{worldFile}") as file:
            data = file.read()
            world_data = json.loads(data)
            try:
                for food in world_data['food']:
                    self.add_food(
                        Food(self.canvas, food['x'], food['y'], food['size']))

                for nest in world_data['nests']:
                    self.add_nest(
                        Nest(self, len(self.nests), nest['x'], nest['y'],
                             nest['species'], nest['size']))

                if (world_data["wall"]):
                    for wall in world_data["wall"]:
                        self.add_wall(wall[0], wall[1])

                for i, species in enumerate(world_data["species"]):
                    for trait, value in species.items():
                        self.species[i].update_trait(trait, value)
                        self.main_gui.update_species_entry(trait, value)

            except BaseException:
                pass
Esempio n. 18
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        print("answer_price_food")
        food = str(tracker.get_slot('food'))
        if food is None:
            dispatcher.utter_message("Nhà hàng mình không có món kia bạn ạ")

        Max = SequenceMatcher(a=food, b="Lẩu dầu cay không vụn").ratio()

        for item in Menu():
            temp = SequenceMatcher(a=food, b=item.name).ratio()
            if temp >= Max:
                Max = temp
                max_food = Food(item.name, item.price, item.type, 0)

        if max_food.type == "beef":
            dispatcher.utter_message("Món " + max_food.name +
                                     " bên em đang bán có giá " +
                                     str(max_food.price) + "k/100g ạ")
        elif max_food.type == "special":
            dispatcher.utter_message(
                "Tiết mục " + max_food.name + " bên em đang bán có giá " +
                str(max_food.price) +
                "k bao gồm cả phần mì và nhân viên ra múa mì luôn ạ")
        elif max_food.type == "drink":
            dispatcher.utter_message("Dạ " + max_food.name +
                                     " bên em đang bán có giá " +
                                     str(max_food.price) + "k/chai ạ")
        else:
            dispatcher.utter_message("Món " + max_food.name +
                                     " bên em đang bán có giá " +
                                     str(max_food.price) + "k/suất ạ")

        return [SlotSet("food", None)]
Esempio n. 19
0
    def __init__(self, data):
        self._turn = data['turn']
        self._width = data['board']['width']
        self._height = data['board']['height']
        self._nodes = dict()

        self._food_list = []
        self._enemy_list = []

        self._our_snake = None

        our_id = data['you']['id']

        # Process Snakes
        for snake in data['board']['snakes']:
            snake_info = SnakeInfo(snake, self, our_id)

            if snake_info.is_enemy():
                self._enemy_list.append(snake_info)
            else:
                self._our_snake = snake_info

            for point in snake['body']:
                new_snake = SnakeNode(point, snake_info)
                self._nodes[new_snake.get_point()] = new_snake

        snake_head = self._our_snake.get_head()
        # Process Food
        for raw_data in data['board']['food']:
            new_food = Food(raw_data, snake_head)
            self._food_list.append(new_food)
            self._nodes[new_food.get_point()] = new_food

        self._food_list = sorted(self._food_list,
                                 key=operator.attrgetter('_start_distance'))
Esempio n. 20
0
def read_food(line):
    """
    -------------------------------------------------------
    Creates and returns a food object from a line of string data.
    Use: f = read_food(line)
    -------------------------------------------------------
    Parameters:
        line - a vertical bar-delimited line of food data in the format
          name|origin|is_vegetarian|calories (str)
    Returns:
        food - contains the data from line (Food)
    -------------------------------------------------------
    """

    line.strip()
    x = line.split("|")
    
    if x[2] == "True":
        x[2] = True
    if x[2] == "False":
        x[2] = False
        
    origin = int(x[1])
    
    food = Food(x[0], origin, x[2] , int(x[3]))

    return food
Esempio n. 21
0
def main():
    try:
        pygame.init()
        screen = pygame.display.set_mode((WIDTH, HEIGHT))
        pygame.display.set_caption('Змейка')

        running = True

        board = Board(20, 15, 40)
        snake = Snake(board)
        # snake.set_self_onboard()

        food = Food(board)
        # food.set_self_onboard()

        board.add_food(food)
        board.add_snake(snake)

        fps = 6
        clock = pygame.time.Clock()

        if board.start_screen(screen, clock):
            while running:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        running = False
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_SPACE:  # пауза
                            print('main.py:"SPACE"')
                            board.pause_play()
                        elif event.scancode == pygame.KSCAN_R:  # перезапуск
                            food.restart()
                            snake.restart()
                            board.pause_play()
                        elif board.playing:
                            # управление стрелками
                            if event.key == pygame.K_UP:
                                snake.UP()
                                break
                            elif event.key == pygame.K_RIGHT:
                                snake.RIGHT()
                                break
                            elif event.key == pygame.K_DOWN:
                                snake.DOWN()
                                break
                            elif event.key == pygame.K_LEFT:
                                snake.LEFT()
                                break
                screen.fill((0, 0, 0))

                # food.set_self_onboard()
                if board.playing:
                    snake.next_frame(screen)
                board.render(screen)
                pygame.display.flip()
                clock.tick(fps)
    except Exception as e:
        print(e)
    pygame.quit()
Esempio n. 22
0
        def start():
            worldGameObjects = []
            self.bossScene.objects["snake"] = Snake(self.bossScene,
                                                    Vector2(449, 449),
                                                    Vector2(30, 30),
                                                    pygame.Color(200, 0, 0))
            self.bossScene.objects["player"] = Player(
                self.bossScene.objects["snake"],
                0,
                Vector2(0, 0),
                atk=1,
                hp=self.mainScene.objects["player"].hp)
            food = Food(self.bossScene,
                        Vector2(30 * random.randint(2, 22) - 1,
                                30 * random.randint(2, 22) - 1),
                        1,
                        Vector2(30, 30),
                        pygame.Color(0, 247, 0),
                        None,
                        hp=1)
            boss = Enemy(self.bossScene,
                         Vector2(30 * random.randint(2, 22) - 1,
                                 30 * random.randint(2, 22) - 1),
                         0,
                         Vector2(30, 30),
                         pygame.Color(10, 0, 10),
                         self.bossScene.objects["snake"].getHead(),
                         atk=1,
                         hp=10,
                         speed=30)
            self.bossScene.objects["boss"] = boss
            self.bossScene.objects["scoreDisplay"] = Text(
                self.bossScene, Vector2(70, 1), Vector2(28, 30),
                pygame.Color(0, 0, 0), "Assets/Recreativos.otf", "")
            worldGameObjects = [food, boss]

            for i in range(0, 24):
                topWallBlock = WallE(self.bossScene, Vector2((30 * i) - 1, -1),
                                     Vector2(30, 30), pygame.Color(255, 0, 0))
                bottomWallBlock = WallE(self.bossScene,
                                        Vector2((30 * i) + 29, 689),
                                        Vector2(30, 30),
                                        pygame.Color(255, 0, 0))
                leftWallBlock = WallE(self.bossScene,
                                      Vector2(-1,
                                              (30 * i) - 1), Vector2(30, 30),
                                      pygame.Color(255, 0, 0))
                rightWallBlock = WallE(self.bossScene,
                                       Vector2(689, (30 * i) + 29),
                                       Vector2(30, 30),
                                       pygame.Color(255, 0, 0))
                wall = [
                    rightWallBlock, leftWallBlock, topWallBlock,
                    bottomWallBlock
                ]
                worldGameObjects.extend(wall)

            objects["worldGameObjects"] = worldGameObjects
            self.bossScene.objects = objects
Esempio n. 23
0
def create_food():
    for i in range(FOOD_AMOUNT):  # summon food
        randx = rand.randint(0, WIDTH - 10)
        randy = rand.randint(0, HEIGHT - 10)
        rands = rand.randint(3, 4)
        food = Food((220, 120, 10), randx, randy, rands)
        draw_food(food)
        foods.append(food)
Esempio n. 24
0
    def __init__(self, x, y):

        self.x = x
        self.y = y
        self.base_object = {}
        self.food_on_map = Food()
        self.material_on_map = Material()
        self.symbol = "X"
Esempio n. 25
0
 def __init__(self, xPos, yPos):
     self.holding = [Food(0, 0)]
     pChar = 'P'
     pCol = 5
     description = "an edible"
     shortdesc = "a plant"
     WorldObj.__init__(self, xPos, yPos, pChar, pCol, description,
                       shortdesc, True)
Esempio n. 26
0
 def __init__(self, theaterName, distance, theaterid, foodList):
     self.theaterid = theaterid
     self.name = theaterName
     self.distance = distance
     res= []
     for item in foodList:
         res.append(Food(item['foodid'],item['foodName'],item['foodprice']))
     self.foodList= res    
Esempio n. 27
0
    def __init__(self):
        self.window = pygame.display.set_mode((500, 500))
        pygame.display.set_caption("Hacktoberfest Snake Game")
        self.fps = pygame.time.Clock()

        self.score = 0
        self.snake = Snake()
        self.food = Food()
Esempio n. 28
0
    def get_food_data(self):
        food_file = open("./data/foods.csv")
        food_reader = csv.reader(food_file)

        for food in list(food_reader)[1:]:
            self.foods.append(Food(food[0], food[1], int(food[2])))

        food_file.close()
Esempio n. 29
0
 def initFood(self):
     for x in range(0, 100):
         xDir = choice((-1, 1))
         yDir = choice((-1, 1))
         self.foodGroup.add(
             Food(randint(4, 16), randint(40, 600), randint(40, 400),
                  randint(60, 100) * xDir,
                  randint(60, 100) * yDir, 640, 480, randint(1, 255),
                  randint(1, 255), randint(1, 255), self.foodGroup))
Esempio n. 30
0
def create_foods():
    numFood = int(WORLD_Y_SIZE * WORLD_X_SIZE * FOOD_DENSITY)
    foods = []
    for i in range(0, numFood):
        x = randint(0, WORLD_X_SIZE)
        y = randint(0, WORLD_Y_SIZE)
        newFood = Food(FOOD_STRENGTH, i, [x, y])
        foods.append(newFood)
    return foods