Phase10/src/com/github/s7uxn37/phase10/Intelligence.java
/**
     * Calculates the probability to find a matching card when a unknown card is taken
     * @param isMatch Predicate to identify matches
     * @param isValidSample Predicate to identify valid sample space entries
     * @return The probability to find a matching card at any point in the sample space
     */
Calculates the probability to find a matching card when a unknown card is taken
@param isMatch Predicate to identify matches
@param isValidSample Predicate to identify valid sample space entries
@return The probability to find a matching card at any point in the sample space
Calculates the probability to find a matching card when a unknown card is taken @param isMatch Predicate to identify matches @param isValidSample Predicate to identify valid sample space entries @return The probability to find a matching card at any point in the sample space
private double unknownCardMatchProb(Predicate<Card> isMatch, Predicate<Card> isValidSample) {
        ArrayList<Card> known = new ArrayList<>();
        for (CARD_LOCATION card_location : CARD_LOCATION.values()) {
            ArrayList<Card> locationCards = getCardsInLocation(card_location);
            for (Card card : locationCards) {
                if (card.probIsOne())
                    known.add(card);
            }
        }
        ArrayList<Card> samples = new ArrayList<>();
        for (Card card : allExistingCards) {
            int index = known.indexOf(card);
            if (index != -1) { 
                known.remove(index);
            } else { 
                samples.add(card);
            }
        }
        samples.removeIf(isValidSample.negate());
        int matches = 0;
        for (Card card : samples) {
            if (isMatch.test(card))
                matches += card.prob;
        }
        return (double)matches / countCards(samples);
    }
private double unknownCardMatchProb ( Predicate < Card > isMatch , Predicate < Card > isValidSample ) { ArrayList < Card > known = new ArrayList < > ( ) ; for ( CARD_LOCATION card_location : CARD_LOCATION . values ( ) ) { ArrayList < Card > locationCards = getCardsInLocation ( card_location ) ; for ( Card card : locationCards ) { if ( card . probIsOne ( ) ) known . add ( card ) ; } } ArrayList < Card > samples = new ArrayList < > ( ) ; for ( Card card : allExistingCards ) { int index = known . indexOf ( card ) ; if ( index != - 1 ) { known . remove ( index ) ; } else { samples . add ( card ) ; } } samples . removeIf ( isValidSample . negate ( ) ) ; int matches = 0 ; for ( Card card : samples ) { if ( isMatch . test ( card ) ) matches += card . prob ; } return ( double ) matches / countCards ( samples ) ; }
Calculates the probability to find a matching card when a unknown card is taken
 @param isMatch Predicate to identify matches
 @param isValidSample Predicate to identify valid sample space entries
 @return The probability to find a matching card at any point in the sample space
Calculates the probability to find a matching card when a unknown card is taken @param isMatch Predicate to identify matches @param isValidSample Predicate to identify valid sample space entries @return The probability to find a matching card at any point in the sample space
// create list of all possible unknown cards (cache it?)
 // card has known location, remove from known
 // couldn't find card, add to unknown
 // filter list by isValidSample
 // count entries with isMatch
 // return matches/entries
