Phase10/src/com/github/s7uxn37/phase10/Intelligence.java
/**
     * Updates all information displayed within the DesirePanel: Targets, PartialTargets with partition and missing cards, fieldInfo.
     * If no targets are specified, desires will be set to add to completedTargets
     * @param targets The targets to achieve; runtime increases exponentially with the amount of targets
     */
Updates all information displayed within the DesirePanel: Targets, PartialTargets with partition and missing cards, fieldInfo.
If no targets are specified, desires will be set to add to completedTargets
@param targets The targets to achieve; runtime increases exponentially with the amount of targets
Updates all information displayed within the DesirePanel : Targets PartialTargets with partition and missing cards fieldInfo . If no targets are specified desires will be set to add to completedTargets @param targets The targets to achieve ; runtime increases exponentially with the amount of targets
public final void updateDesires(ArrayList<Target> targets) {
        isAddingToCompletedTargets = targets.size() == 0;
        if (isAddingToCompletedTargets) {
            partialTargets.clear();
            ArrayList<Card> combinedMissing = new ArrayList<>();
            int cardsUsed = 0;
            Iterator<PartialTarget> it = completedTargets.iterator();
            while (it.hasNext()) {
                PartialTarget completedTarget = it.next();
                if (completedTarget.target.cardCount < 1) {
                    it.remove();
                    continue;
                }
                ArrayList<Card> missing = new ArrayList<>();
                switch (completedTarget.target.type) {
                    case RUN:
                        int maxValue = 0;
                        int minValue = 13;
                        for (Card card : completedTarget.cards) {
                            if (card.number != -1) {
                                maxValue = Math.min(Math.max(maxValue, card.number), 12);
                                minValue = Math.max(Math.min(minValue, card.number), 1);
                            }
                        }
                        if (maxValue < 12) {
                            Card card = new Card();
                            card.number = maxValue + 1;
                            missing.add(card);
                        }
                        if (minValue > 1) {
                            Card card = new Card();
                            card.number = minValue - 1;
                            missing.add(card);
                        }
                        break;
                    case SAME_COLOR:
                        Card card = new Card();
                        card.colorIndex = completedTarget.cards[0].colorIndex;
                        missing.add(card);
                        break;
                    case SAME_NUMBER:
                        Card card2 = new Card();
                        card2.colorIndex = completedTarget.cards[0].colorIndex;
                        missing.add(card2);
                }
                ArrayList<Card> available = new ArrayList<>();
                Iterator<Card> missingIt = missing.iterator();
                outer_loop:
                while (missingIt.hasNext()) {
                    Card missingCard = missingIt.next();
                    for (Card handCard : player) {
                        if ((missingCard.number == -1 && handCard.colorIndex == missingCard.colorIndex) ||
                                (missingCard.colorIndex == -1 && handCard.number == missingCard.number)) { 
                            available.add(missingCard);
                            missingIt.remove();
                            continue outer_loop;
                        }
                    }
                }
                combinedMissing.addAll(missing);
                cardsUsed += available.size();
                PartialTarget completeTarget = new PartialTarget(completedTarget.target, available.toArray(new Card[0]), missing);
                partialTargets.add(completeTarget);
            }
            updateFieldInfo(combinedMissing, cardsUsed, player.size());
        } else {
            int[] partitioning = Optimizer.partition(player, targets);
            ArrayList<Card>[] splitCards = Optimizer.split(partitioning, player.toArray(new Card[0]), targets.size());
            partialTargets.clear();
            for (int i = 0; i < targets.size(); i++) {
                partialTargets.add(PartialTarget.getPartialTarget(targets.get(i), splitCards[i]));
            }
            ArrayList<Card> combinedMissing = new ArrayList<>();
            for (PartialTarget pt : partialTargets)
                combinedMissing.addAll(pt.desiredCards);
            ArrayList<Card> combinedUsed = new ArrayList<>();
            for (PartialTarget pt : partialTargets)
                Collections.addAll(combinedUsed, pt.cards);
            updateFieldInfo(combinedMissing, countCards(combinedUsed), countCards(combinedMissing));
        }
        causeUpdate();
    }
public final void updateDesires ( ArrayList < Target > targets ) { isAddingToCompletedTargets = targets . size ( ) == 0 ; if ( isAddingToCompletedTargets ) { partialTargets . clear ( ) ; ArrayList < Card > combinedMissing = new ArrayList < > ( ) ; int cardsUsed = 0 ; Iterator < PartialTarget > it = completedTargets . iterator ( ) ; while ( it . hasNext ( ) ) { PartialTarget completedTarget = it . next ( ) ; if ( completedTarget . target . cardCount < 1 ) { it . remove ( ) ; continue ; } ArrayList < Card > missing = new ArrayList < > ( ) ; switch ( completedTarget . target . type ) { case RUN : int maxValue = 0 ; int minValue = 13 ; for ( Card card : completedTarget . cards ) { if ( card . number != - 1 ) { maxValue = Math . min ( Math . max ( maxValue , card . number ) , 12 ) ; minValue = Math . max ( Math . min ( minValue , card . number ) , 1 ) ; } } if ( maxValue < 12 ) { Card card = new Card ( ) ; card . number = maxValue + 1 ; missing . add ( card ) ; } if ( minValue > 1 ) { Card card = new Card ( ) ; card . number = minValue - 1 ; missing . add ( card ) ; } break ; case SAME_COLOR : Card card = new Card ( ) ; card . colorIndex = completedTarget . cards [ 0 ] . colorIndex ; missing . add ( card ) ; break ; case SAME_NUMBER : Card card2 = new Card ( ) ; card2 . colorIndex = completedTarget . cards [ 0 ] . colorIndex ; missing . add ( card2 ) ; } ArrayList < Card > available = new ArrayList < > ( ) ; Iterator < Card > missingIt = missing . iterator ( ) ; outer_loop : while ( missingIt . hasNext ( ) ) { Card missingCard = missingIt . next ( ) ; for ( Card handCard : player ) { if ( ( missingCard . number == - 1 && handCard . colorIndex == missingCard . colorIndex ) || ( missingCard . colorIndex == - 1 && handCard . number == missingCard . number ) ) { available . add ( missingCard ) ; missingIt . remove ( ) ; continue outer_loop ; } } } combinedMissing . addAll ( missing ) ; cardsUsed += available . size ( ) ; PartialTarget completeTarget = new PartialTarget ( completedTarget . target , available . toArray ( new Card [ 0 ] ) , missing ) ; partialTargets . add ( completeTarget ) ; } updateFieldInfo ( combinedMissing , cardsUsed , player . size ( ) ) ; } else { int [ ] partitioning = Optimizer . partition ( player , targets ) ; ArrayList < Card > [ ] splitCards = Optimizer . split ( partitioning , player . toArray ( new Card [ 0 ] ) , targets . size ( ) ) ; partialTargets . clear ( ) ; for ( int i = 0 ; i < targets . size ( ) ; i ++ ) { partialTargets . add ( PartialTarget . getPartialTarget ( targets . get ( i ) , splitCards [ i ] ) ) ; } ArrayList < Card > combinedMissing = new ArrayList < > ( ) ; for ( PartialTarget pt : partialTargets ) combinedMissing . addAll ( pt . desiredCards ) ; ArrayList < Card > combinedUsed = new ArrayList < > ( ) ; for ( PartialTarget pt : partialTargets ) Collections . addAll ( combinedUsed , pt . cards ) ; updateFieldInfo ( combinedMissing , countCards ( combinedUsed ) , countCards ( combinedMissing ) ) ; } causeUpdate ( ) ; }
Updates all information displayed within the DesirePanel: Targets, PartialTargets with partition and missing cards, fieldInfo.
Updates all information displayed within the DesirePanel : Targets PartialTargets with partition and missing cards fieldInfo .
// make list of cards to add to completedTarget
 // if player has cards, move from missing to available
 // isMatch = (colorKnown && colorMatch) || (numberKnown && numberMatch)
 // save cards for updateFieldInfo
 // update partialTargets so cards are displayed after causeUpdate()
 // call updateFieldInfo()
 // ############# create PartialTargets with best partitioning and find missing cards
 // find best card partitioning for targets
 // update partialTargets with partitioning
 // ############# update partialTargets moves:
 // combine missing cards from all targets
