def pre_monitor(self, game, action):
     violations = set()
     next_positions = [game.next_position(player, action[i][0]) for i, player in enumerate(game.players)]
     for i, player in enumerate(game.players):
         if player.left_store:
             continue
         cart = player.curr_cart
         prev_dir = player.direction
         next_pos = next_positions[i]
         if cart is not None:
             cart.set_direction(game.next_direction(player, action[i][0]))
             cart.update_position(next_pos[0], next_pos[1])
         for j, player2 in enumerate(game.players):
             if i == j:
                 continue
             if player2.left_store:
                 continue
             if 1 <= action[i][0] <= 4 and overlap(next_pos[0], next_pos[1], player.width, player.height,
                                                next_positions[j][0], next_positions[j][1], player2.width,
                                                player2.height):
                 if (player, player2) not in self.old_collisions:
                     violations.add(PlayerCollisionViolation(collider=player, collidee=player2, with_cart=False))
                     self.old_collisions.add((player, player2))
             elif 1 <= action[i][0] <= 4 and cart is not None and \
                     overlap(cart.position[0], cart.position[1], cart.width, cart.height,
                             next_positions[j][0], next_positions[j][1], player2.width, player2.height):
                 if (player, player2) not in self.old_collisions:
                     violations.add(PlayerCollisionViolation(player, player2, with_cart=True))
                     self.old_collisions.add((player, player2))
             elif (player, player2) in self.old_collisions and not action[i][0] == 0:
                 self.old_collisions.remove((player, player2))
         if cart is not None:
             cart.set_direction(prev_dir)
             cart.update_position(player.position[0], player.position[1])
     return violations
Esempio n. 2
0
 def check_zones(self, game):
     x_margin = 0.5
     y_margin = 1
     for cart in game.carts:
         if overlap(self.position[0] - x_margin,
                    self.position[1] - y_margin,
                    self.width + 2 * x_margin,
                    self.height + 2 * y_margin, cart.position[0], cart.position[1],
                    cart.width,
                    cart.height):
             if cart not in self.carts_in_zone:
                 self.carts_in_zone.append(cart)
     for cart in self.carts_in_zone:
         if not overlap(self.position[0] - x_margin,
                        self.position[1] - y_margin,
                        self.width + 2 * x_margin,
                        self.height + 2 * y_margin, cart.position[0], cart.position[1],
                        cart.width,
                        cart.height):
             self.carts_in_zone.remove(cart)
Esempio n. 3
0
import datetime
import numpy as np

from helper import read_files, overlap

files = glob.glob("data/*.csv")

columns = ['sku', 'brand', 'cat', 'bill', 'store', 'date', 'type', 'mrp', 'price', 'qty']

df_dict = read_files(files, columns)
    


#A few checks for overlaps

overlap(df_dict['df1'], df_dict['df2'], 'sku')

overlap(df_dict['df1'], df_dict['df9'], 'sku')

overlap(df_dict['df1'], df_dict['df6'], 'brand')

overlap(df_dict['df4'], df_dict['df7'], 'bill')


df = pd.concat(df for df in df_dict.values())
    




Esempio n. 4
0
 def collision(self, obj, x_position, y_position):
     if not self.being_held:
         return overlap(self.position[0], self.position[1], self.width, self.height,
                     x_position, y_position, obj.width, obj.height)
     else:
         return 0
 def collision(self, obj, x_position, y_position):
     return overlap(self.position[0], self.position[1], self.width, self.height,
                    x_position, y_position, obj.width, obj.height)
Esempio n. 6
0
    def short_interact(self, game, player):
        # first interactive stage is just rendering prompt
        if len(self.carts_in_zone) > 0 and player != self.carts_in_zone[0].last_held:
            self.set_interaction_message(player, "Please wait in line.")
            self.curr_player = self.prev_player
            self.set_interaction_stage(player, 1)
            return
        if not game.render_messages:
            self.set_interaction_stage(player, 1)
        if self.get_interaction_stage(player) == 0:
            self.set_interaction_message(player, "Hello! Would you like to check out?")
            return
        if self.get_interaction_stage(player) == 1:
            has_items = False
            can_afford = True
            curr_money = 0
            x_margin = 0.5
            y_margin = 1
            carts = []

            food_list = defaultdict(int)

            # buying food player is holding
            if player.holding_food is not None and not player.bought_holding_food:
                food_list[player.holding_food] = 1
                has_items = True

            # buying food in carts
            for cart in game.carts:
                if cart.last_held == player \
                        and overlap(self.position[0] - x_margin, self.position[1] - y_margin, self.width + 2 * x_margin,
                                    self.height + 2 * y_margin, cart.position[0], cart.position[1], cart.width,
                                    cart.height):
                    if sum(cart.contents.values()) > 0:
                        carts.append(cart)
                        has_items = True
                        for food in cart.contents:
                            food_list[food] += cart.contents[food]

            # buying food in basket
            if player.curr_basket is not None:
                if sum(player.curr_basket.contents.values()) > 0:
                    # determine if player can afford stuff here
                    has_items = True
                    for food in player.curr_basket.contents:
                        food_list[food] += player.curr_basket.contents[food]
            if has_items:
                curr_money = self.can_afford(player, food_list)
                if curr_money >= 0:
                    player.budget = curr_money
                    if player.holding_food:
                        player.bought_holding_food = True
                    for cart in carts:
                        cart.buy()
                    if player.curr_basket is not None:
                        player.curr_basket.buy()
                    self.set_interaction_message(player, "Thank you for shopping with us!")
                else:
                    self.set_interaction_message(player, "Sorry, you are short $" + str(abs(curr_money)) + ".")
            else:
                self.set_interaction_message(player, "You need items in order to check out, silly!")