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