-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scissors_Gloria_Villa #66
base: master
Are you sure you want to change the base?
Changes from all commits
f96d52d
293e3b7
19d96fa
00ba0a2
c7d6278
84e8971
287a90f
85a8f2b
7efeba9
60a56cf
748ace4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from swap_meet.item import Item | ||
class Clothing(Item): | ||
|
||
def __init__(self,category = "", condition=0): | ||
super().__init__("Clothing", condition) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from swap_meet.item import Item | ||
class Decor(Item): | ||
|
||
def __init__(self,category = "", condition = 0): | ||
super().__init__("Decor", condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from swap_meet.item import Item | ||
class Electronics(Item): | ||
|
||
def __init__(self,category = "", condition=0): | ||
super().__init__("Electronics", condition) | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Item: | ||
def __init__(self, category = "", condition = 0): | ||
self.category = category | ||
self.condition = float(condition) | ||
|
||
def __str__(self): | ||
return 'Hello World!' | ||
def __repr__(self): | ||
return "Item('{}')".format(self.category) | ||
|
||
def condition_description(self): | ||
if self.condition == 5: | ||
desc = "mint" | ||
elif self.condition == 4: | ||
desc = "excellent" | ||
elif self.condition == 3: | ||
desc = "good" | ||
elif self.condition == 2: | ||
desc = "well used" | ||
elif self.condition == 1: | ||
desc = "Might use a glove" | ||
elif self.condition == 0: | ||
desc = "Make sure you really want to do this!" | ||
return desc | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
class Vendor: | ||
def __init__(self, inventory = None): | ||
if inventory == None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
""" | ||
function: adds Item to inventory | ||
input: Item to add | ||
output: Item (list) | ||
""" | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
""" | ||
function: removes Item from inventory | ||
input: Item to remove | ||
output: Item list if True, or False | ||
""" | ||
|
||
try: | ||
self.inventory.remove(item) | ||
return item | ||
except ValueError: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
""" | ||
function: groups the items by category passed in | ||
""" | ||
|
||
by_category_list = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
by_category_list.append(item) | ||
return by_category_list | ||
|
||
|
||
def swap_items(self, vendor,my_item,vendor_item ): | ||
""" | ||
function: checks Items are in inventory | ||
input: Self, Vendor and Items to swap | ||
output: Booleon (True for success) | ||
""" | ||
|
||
if my_item in self.inventory and vendor_item in vendor.inventory: | ||
self.add(vendor_item) | ||
self.remove(my_item) | ||
vendor.remove(vendor_item) | ||
vendor.add(my_item) | ||
return True | ||
return False | ||
|
||
|
||
def swap_first_item(self,vendor): | ||
""" | ||
function: swaps and removes item | ||
input: vendor | ||
output: True if successful, or False if empty list for vendor encountered | ||
""" | ||
if self.inventory == [] or vendor.inventory == []: | ||
return False | ||
|
||
self_first_item = self.inventory[0] | ||
vendor_first_item = vendor.inventory[0] | ||
self.remove(self_first_item) | ||
self.add(vendor_first_item) | ||
vendor.remove(vendor_first_item) | ||
vendor.add(self_first_item) | ||
return True | ||
Comment on lines
+67
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a whole lot like the code in the method above! I wonder if there's a way we could make use of that other method here... |
||
|
||
|
||
def get_best_by_category(self,category): | ||
""" | ||
function: Gets all the items by category | ||
input: category | ||
output: True if successful, or False if empty list for vendor encountered | ||
""" | ||
if self.get_by_category == None: | ||
return None | ||
|
||
best_item = None | ||
for item in self.get_by_category(category): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love that you made use of the existing method here! |
||
if best_item == None or item.condition > best_item.condition: | ||
best_item = item | ||
return best_item | ||
|
||
def swap_best_by_category(self,other,my_priority,their_priority): | ||
# my_priority is category that the Vendor wants to receive | ||
# their_priority represents the category the other Vendor wants | ||
""" | ||
function: Best item in inventory that matches category is swapped with the best item in `other`'s inventory that matches `my_priority` | ||
input: `their_priority`, my priority, other (the other vendor) | ||
output: Boolean. | ||
|
||
False -- If the `Vendor` has no item that matches `their_priority` category, swapping does not happen, and it returns `False. - If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False` | ||
""" | ||
|
||
if other.get_by_category(my_priority) == None or self.get_by_category(their_priority)== None: | ||
return False | ||
|
||
my_trade_to_other = self.get_best_by_category(their_priority) | ||
their_trade_to_me = other.get_best_by_category(my_priority) | ||
Comment on lines
+102
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One minor optimization here would be to store the results of |
||
|
||
result = self.swap_items(other,my_trade_to_other,their_trade_to_me) | ||
return result | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha