def find_optimal_decision(our_hand, their_hand, decisions, num_epochs=NUM_EPOCHS): decision_to_ev = dict() for decision in decisions: tmp_ofc_hand = OfcHand( our_hand.top.row, our_hand.middle.row, our_hand.bottom.row, ) for placement in decision.placements: if placement.row == Row.TOP: tmp_ofc_hand.add_top(placement.card) elif placement.row == Row.MIDDLE: tmp_ofc_hand.add_middle(placement.card) elif placement.row == Row.BOTTOM: tmp_ofc_hand.add_bottom(placement.card) else: raise AssertionError("wtf") hand_ev_estimator = HandEvEstimator( our_ofc_hand=tmp_ofc_hand, their_ofc_hand=their_hand, dead_cards=decision.dead_cards, ) ev = hand_ev_estimator.estimate(num_epochs=num_epochs) decision_to_ev[tuple(decision.placements)] = ev return decision_to_ev
def _create_ofc_hand(top, middle, bottom): ofc_hand = OfcHand() for c in parse_cards(top.split(" ")): ofc_hand.add_top(c) for c in parse_cards(middle.split(" ")): ofc_hand.add_middle(c) for c in parse_cards(bottom.split(" ")): ofc_hand.add_bottom(c) return ofc_hand
def test_ofc_hand_golden(): ofc_hand = OfcHand() for c in parse_cards(["2c", "2d", "2h"]): ofc_hand.add_top(c) for c in parse_cards(["6h", "6d", "6c", "6s", "As"]): ofc_hand.add_middle(c) for c in parse_cards(["8h", "8d", "8c", "8s", "9s"]): ofc_hand.add_bottom(c) assert ofc_hand.completed
def test_no_foul(): ofc_hand = OfcHand() for c in parse_cards(["2c", "2d", "2h"]): ofc_hand.add_top(c) for c in parse_cards(["6h", "6d", "6c", "6s", "As"]): ofc_hand.add_middle(c) for c in parse_cards(["8h", "8d", "8c", "8s", "9s"]): ofc_hand.add_bottom(c) assert not ofc_hand.foul
def arrange_best_hand(cls, ofc_hand, cards): best_ofc_hand = None best_ofc_hand_royalties = -1 top_cards_remaining = 3 - ofc_hand.top.total_cards middle_cards_remaining = 5 - ofc_hand.middle.total_cards bottom_cards_remaining = 5 - ofc_hand.bottom.total_cards cards_set = set(cards) top_iter = combinations(cards_set, top_cards_remaining) if top_cards_remaining > 0 else 'e' num = 0 for top_cards in top_iter: remaining_cards = cards_set - set(top_cards) if top_cards != 'e' else cards_set middle_iter = combinations(remaining_cards, middle_cards_remaining) if middle_cards_remaining > 0 else 'e' for middle_cards in middle_iter: remaining_cards_2 = remaining_cards - set(middle_cards) if middle_cards != 'e' else remaining_cards bottom_iter = combinations(remaining_cards_2, bottom_cards_remaining) if bottom_cards_remaining > 0 else 'e' for bottom_cards in bottom_iter: num += 1 add_top = list(top_cards) if top_cards != 'e' else [] add_middle = list(middle_cards) if middle_cards != 'e' else [] add_bottom = list(bottom_cards) if bottom_cards != 'e' else [] tmp_ofc_hand = OfcHand( ofc_hand.top.row + add_top, ofc_hand.middle.row + add_middle, ofc_hand.bottom.row + add_bottom, ) tmp_ofc_hand_royalties = tmp_ofc_hand.calculate_total_royalties() if best_ofc_hand is None: best_ofc_hand = tmp_ofc_hand if not tmp_ofc_hand.foul and tmp_ofc_hand_royalties > best_ofc_hand_royalties: best_ofc_hand = tmp_ofc_hand best_ofc_hand_royalties = tmp_ofc_hand_royalties return best_ofc_hand