From 362f7c5051b7172aa0043d25932cf9e115265205 Mon Sep 17 00:00:00 2001 From: drakeblood4 Date: Sun, 8 May 2016 03:49:02 -0600 Subject: [PATCH 1/2] Update pucauto.py --- pucauto.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/pucauto.py b/pucauto.py index 007647a..b70c7b1 100755 --- a/pucauto.py +++ b/pucauto.py @@ -317,6 +317,59 @@ def find_highest_value_bundle(trades): return None +def optimal_bundle(highest_value_bundle): + """The best bundle if you have more tradable cards than the other guy has + points is the group of cards that comes closest to reaching that. + + This does the old sort from complete_trades prior to this commit if there + is less value than the guy has available points. + + Otherwise, it finds the biggest bundle, sorts that by biggest first, then + sorts the leftovers by biggest first just in case one of the things you're + trying to ship out gets jumped on by a third party.""" + + + + cards = highest_value_bundle[1]["cards"] + sorted_cards = [] + + + + if highest_value_bundle[1]["value"] <= highest_value_bundle[1]["points"]: + sorted_cards = sorted(cards, key=lambda k: k["value"], reverse=True) + else: + largest = 0 + sorted_cards = [] + for i in range (1, len(cards)): + can_change = False + for j in itertools.combinations(cards, i): + bundle_value = 0 + for k in j: + bundle_value += k["value"] + if bundle_value <= highest_value_bundle[1]["points"]: + can_change = True + if bundle_value > largest: + largest = bundle_value + sorted_cards = list(j) + + if can_change == 0: + break + + + sorted_cards.sort( key=lambda k: k["value"], reverse=True) + + leftovers = [] + for m in cards: + if m not in sorted_cards: + leftovers.append(m) + + for n in leftovers: + sorted_cards.append(n) + + return(sorted_cards) + + + def complete_trades(highest_value_bundle): """Sort the cards by highest value first and then send them all. @@ -329,8 +382,8 @@ def complete_trades(highest_value_bundle): return cards = highest_value_bundle[1]["cards"] - # Sort the cards by highest value to make the most valuable trades first. - sorted_cards = sorted(cards, key=lambda k: k["value"], reverse=True) + # Here's the fancy new change. Trade as much stuff to the other guy as possible + sorted_cards = optimal_bundle(highest_value_bundle) member_name = highest_value_bundle[1]["name"] member_points = highest_value_bundle[1]["points"] From 96cb29cdd4fd3e74a984b97e5079561c31bcff15 Mon Sep 17 00:00:00 2001 From: drakeblood4 Date: Sun, 8 May 2016 03:56:12 -0600 Subject: [PATCH 2/2] Update pucauto.py --- pucauto.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pucauto.py b/pucauto.py index b70c7b1..894ffa0 100755 --- a/pucauto.py +++ b/pucauto.py @@ -319,14 +319,16 @@ def find_highest_value_bundle(trades): def optimal_bundle(highest_value_bundle): """The best bundle if you have more tradable cards than the other guy has - points is the group of cards that comes closest to reaching that. + points is the group of cards that comes closest to reaching their + available points. This does the old sort from complete_trades prior to this commit if there - is less value than the guy has available points. + is less value than the reciever has available points. - Otherwise, it finds the biggest bundle, sorts that by biggest first, then - sorts the leftovers by biggest first just in case one of the things you're - trying to ship out gets jumped on by a third party.""" + Otherwise, it finds the biggest bundle under their available poits, sorts + that by card value, then sorts the leftovers by card value just in case + one of the things you're trying to trade out gets jumped on by a third + party."""