*/
    public static int xCount(Card c, String s) {
        int n = 0;

        Player cardController = c.getController();
        Player oppController = cardController.getOpponent();

        final String[] l = s.split("/");
        final String[] m = parseMath(l);

        //accept straight numbers
        if (l[0].contains("Number$")) {
            String number = l[0].replace("Number$", "");
            return doXMath(Integer.parseInt(number), m, c);
        }

        //Manapool
        if (l[0].contains("ManaPool")) {
            String color = l[0].split(":")[1];
            return AllZone.getManaPool().getAmountOfColor(color);
        }

        // count valid cards on the battlefield
        if (l[0].contains("Valid")) {
            String restrictions = l[0].replace("Valid ", "");
            restrictions = restrictions.replace("Count$", "");
            final String rest[] = restrictions.split(",");
            CardList cardsonbattlefield = AllZoneUtil.getCardsInPlay();
            cardsonbattlefield = cardsonbattlefield.getValidCards(rest, cardController, c);

            n = cardsonbattlefield.size();

            return doXMath(n, m, c);
        }
        
        if (l[0].contains("ImprintedCardPower")) {
        	if (c.getImprinted().size() > 0) {
        		return c.getImprinted().get(0).getNetAttack();	
        	}
        }
        if (l[0].contains("ImprintedCardToughness")) {
        	if (c.getImprinted().size() > 0) {
        		return c.getImprinted().get(0).getNetDefense();
        	}
        }
        
        if(l[0].contains("GreatestPowerYouControl")) {
        	CardList list = AllZoneUtil.getCreaturesInPlay(c.getController());
        	int highest = 0;
            for (Card crd : list) {
                if (crd.getNetAttack() > highest) highest = crd.getNetAttack();
            }
            return highest;
        }
        
        final String[] sq;
        sq = l[0].split("\\.");

        if (sq[0].contains("xPaid")) {
            return c.getXManaCostPaid();
        }

        if (sq[0].contains("xLifePaid")) {
            if (c.getController().isHuman()) {
                return c.getXLifePaid();
            } else {
                //copied for xPaid
                //not implemented for Compy
                //int dam = ComputerUtil.getAvailableMana().size()- CardUtil.getConvertedManaCost(c);
                //if (dam < 0) dam = 0;
                //return dam;
                return 0;
            }
        }

        CardList someCards = new CardList();

        //Complex counting methods

        //TriggeringObjects
        if (sq[0].startsWith("Triggered")) {
            return doXMath((Integer) c.getTriggeringObject(sq[0].substring(9)), m, c);
        }

        // Count$Domain
        if (sq[0].contains("Domain")) {
            someCards.addAll(AllZoneUtil.getPlayerCardsInPlay(cardController));
            String basic[] = {"Forest", "Plains", "Mountain", "Island", "Swamp"};

            for (int i = 0; i < basic.length; i++)
                if (!someCards.getType(basic[i]).isEmpty()) n++;

            return doXMath(n, m, c);
        }

        // Count$YourLifeTotal
        if (sq[0].contains("YourLifeTotal")) {
            if (cardController.isComputer()) return doXMath(AllZone.getComputerPlayer().getLife(), m, c);
            else if (cardController.isHuman()) return doXMath(AllZone.getHumanPlayer().getLife(), m, c);

            return 0;
        }

        // Count$OppLifeTotal
        if (sq[0].contains("OppLifeTotal")) {
            if (oppController.isComputer()) return doXMath(AllZone.getComputerPlayer().getLife(), m, c);
            else if (oppController.isHuman()) return doXMath(AllZone.getHumanPlayer().getLife(), m, c);

            return 0;
        }

        // Count$YourPoisonCounters
        if (sq[0].contains("YourPoisonCounters")) {
            if (cardController.isComputer()) return doXMath(AllZone.getComputerPlayer().getPoisonCounters(), m, c);
            else if (cardController.isHuman()) return doXMath(AllZone.getHumanPlayer().getPoisonCounters(), m, c);

            return 0;
        }

        // Count$OppPoisonCounters
        if (sq[0].contains("OppPoisonCounters")) {
            if (oppController.isComputer()) return doXMath(AllZone.getComputerPlayer().getPoisonCounters(), m, c);
            else if (oppController.isHuman()) return doXMath(AllZone.getHumanPlayer().getPoisonCounters(), m, c);

            return 0;
        }

        // Count$HighestLifeTotal
        if (sq[0].contains("HighestLifeTotal")) {
            return Math.max(AllZone.getHumanPlayer().getLife(), AllZone.getComputerPlayer().getLife());
        }

        // Count$LowestLifeTotal
        if (sq[0].contains("LowestLifeTotal")) {
            return Math.min(AllZone.getHumanPlayer().getLife(), AllZone.getComputerPlayer().getLife());
        }

        // Count$TopOfLibraryCMC
        if (sq[0].contains("TopOfLibraryCMC")) {
            CardList topcard = AllZoneUtil.getPlayerCardsInLibrary(cardController, 1);
            return doXMath(topcard.getTotalConvertedManaCost(), m, c);
        }
        
        // Count$EnchantedControllerCreatures
        if (sq[0].contains("EnchantedControllerCreatures")) {
        	CardList EnchantedControllerInPlay = AllZoneUtil.getPlayerCardsInPlay(c.getEnchantingCard().getController());
            EnchantedControllerInPlay = EnchantedControllerInPlay.getType("Creature");
            return EnchantedControllerInPlay.size();
        }
        
        // Count$LowestLibrary
        if (sq[0].contains("LowestLibrary")) {
        return Math.min(AllZone.getHumanLibrary().size(),AllZone.getComputerLibrary().size());
        }
    
        // Count$Chroma.<mana letter>
        if (sq[0].contains("Chroma")) return doXMath(
                getNumberOfManaSymbolsControlledByColor(sq[1], cardController), m, c);

        // Count$Hellbent.<numHB>.<numNotHB>
        if (sq[0].contains("Hellbent")) {
            if (cardController.hasHellbent())
                return doXMath(Integer.parseInt(sq[1]), m, c); // Hellbent
            else
                return doXMath(Integer.parseInt(sq[2]), m, c); // not Hellbent
        }

        //Count$Metalcraft.<numMC>.<numNotMC>
        if (sq[0].contains("Metalcraft")) {
            if (cardController.hasMetalcraft())
                return doXMath(Integer.parseInt(sq[1]), m, c);
            else
                return doXMath(Integer.parseInt(sq[2]), m, c);
        }

        if (sq[0].contains("Threshold")) {
            if (cardController.hasThreshold())
                return doXMath(Integer.parseInt(sq[1]), m, c); // Have Threshold
            else
                return doXMath(Integer.parseInt(sq[2]), m, c); // not Threshold
        }
        
        if (sq[0].contains("Landfall")) {
            if (cardController.hasLandfall())
                return doXMath(Integer.parseInt(sq[1]), m, c); // Have Landfall
            else
                return doXMath(Integer.parseInt(sq[2]), m, c); // not Landfall
        }

        if (sq[0].startsWith("Devoured")) {
            final String validDevoured = l[0].split(" ")[1];
            final Card csource = c;
            CardList cl = c.getDevoured();

            cl = cl.filter(new CardListFilter() {
                public boolean addCard(Card cdev)
                {
                    return cdev.isValidCard(validDevoured.split(","),csource.getController(),csource);
                }
            });

            return doXMath(cl.size(),m,c);
        }

        // Count$CardPower
        if (sq[0].contains("CardPower")) return doXMath(c.getNetAttack(), m, c);
        // Count$CardToughness
        if (sq[0].contains("CardToughness")) return doXMath(c.getNetDefense(), m, c);
        // Count$CardPowerPlusToughness
        if (sq[0].contains("CardSumPT")) return doXMath((c.getNetAttack() + c.getNetDefense()), m, c);
        // Count$CardManaCost
        if (sq[0].contains("CardManaCost")) return doXMath(CardUtil.getConvertedManaCost(c), m, c);
        // Count$CardCounters.<counterType>
        if (sq[0].contains("CardCounters"))
            return doXMath(c.getCounters(Counters.getType(sq[1])), m, c);
        // Count$TimesKicked
        if (sq[0].contains("TimesKicked"))
            return doXMath(c.getMultiKickerMagnitude(), m, c);
        if (sq[0].contains("NumCounters")) {
            int num = c.getCounters(Counters.getType(sq[1]));
            return doXMath(num, m, c);
        }
        if (sq[0].contains("NumBlockingMe"))
            return doXMath(AllZone.getCombat().getBlockers(c).size(), m, c);

        //Count$IfMainPhase.<numMain>.<numNotMain> // 7/10
        if (sq[0].contains("IfMainPhase")) {
            String cPhase = AllZone.getPhase().getPhase();
            if ((cPhase.equals(Constant.Phase.Main1) ||
                    cPhase.equals(Constant.Phase.Main2)) &&
                    AllZone.getPhase().getPlayerTurn().equals(cardController))
                return doXMath(Integer.parseInt(sq[1]), m, c);
            else
                return doXMath(Integer.parseInt(sq[2]), m, c); // not Main Phase
        }

        //Count$ThisTurnEntered <ZoneDestination> <ZoneOrigin> <Valid>
        //or
        //Count$ThisTurnEntered <ZoneDestination <Valid>
        if (sq[0].startsWith("ThisTurnEntered")) {
            String[] workingCopy = l[0].split(" ");
            String destination, origin, validFilter;

            destination = workingCopy[1];
            if (workingCopy[2].equals("from")) {
                origin = workingCopy[3];
                validFilter = workingCopy[4];
            } else {
                origin = "Any";
                validFilter = workingCopy[2];
            }

            final String[] valid = validFilter.split(",");
            final Card csource = c;
            CardList res = ((DefaultPlayerZone) AllZone.getZone(destination, AllZone.getHumanPlayer())).getCardsAddedThisTurn(origin);
            res.addAll(((DefaultPlayerZone) AllZone.getZone(destination, AllZone.getComputerPlayer())).getCardsAddedThisTurn(origin));

            res = res.filter(new CardListFilter() {
                public boolean addCard(Card csubject) {
                    return csubject.isValidCard(valid, csource.getController(), csource);
                }
            });


            return doXMath(res.size(), m, c);
        }

        //Generic Zone-based counting
        // Count$QualityAndZones.Subquality

        // build a list of cards in each possible specified zone

        // if a card was ever written to count two different zones,
        // make sure they don't get added twice.
        boolean MF = false, MY = false, MH = false;
        boolean OF = false, OY = false, OH = false;

        if (sq[0].contains("YouCtrl")) if (MF == false) {
            someCards.addAll(AllZoneUtil.getPlayerCardsInPlay(cardController));
            MF = true;
        }

        if (sq[0].contains("InYourYard")) if (MY == false) {
            someCards.addAll(AllZoneUtil.getPlayerGraveyard(cardController));
            MY = true;
        }

        if (sq[0].contains("InYourLibrary")) if (MY == false) {
            someCards.addAll(AllZoneUtil.getPlayerCardsInLibrary(cardController));
            MY = true;
        }

        if (sq[0].contains("InYourHand")) if (MH == false) {
            someCards.addAll(AllZoneUtil.getPlayerHand(cardController));
            MH = true;
        }

        if (sq[0].contains("OppCtrl")) if (OF == false) {
            someCards.addAll(AllZoneUtil.getPlayerCardsInPlay(oppController));
            OF = true;
        }

        if (sq[0].contains("InOppYard")) if (OY == false) {
            someCards.addAll(AllZoneUtil.getPlayerGraveyard(oppController));
            OY = true;
        }

        if (sq[0].contains("InOppHand")) if (OH == false) {
            someCards.addAll(AllZoneUtil.getPlayerHand(oppController));
            OH = true;
        }

        if (sq[0].contains("OnBattlefield")) {
            if (MF == false) someCards.addAll(AllZoneUtil.getPlayerCardsInPlay(cardController));
            if (OF == false) someCards.addAll(AllZoneUtil.getPlayerCardsInPlay(oppController));
        }

        if (sq[0].contains("InAllYards")) {
            if (MY == false) someCards.addAll(AllZoneUtil.getPlayerGraveyard(cardController));
            if (OY == false) someCards.addAll(AllZoneUtil.getPlayerGraveyard(oppController));
        }

        if (sq[0].contains("InAllHands")) {
            if (MH == false) someCards.addAll(AllZoneUtil.getPlayerHand(cardController));
            if (OH == false) someCards.addAll(AllZoneUtil.getPlayerHand(oppController));
        }

        // filter lists based on the specified quality


        // "Clerics you control" - Count$TypeYouCtrl.Cleric
        if (sq[0].contains("Type")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    if (c.isType(sq[1])) return true;

                    return false;
                }
            });
        }

        // "Named <CARDNAME> in all graveyards" - Count$NamedAllYards.<CARDNAME>

        if (sq[0].contains("Named")) {
            if (sq[1].equals("CARDNAME"))
                sq[1] = c.getName();

            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    if (c.getName().equals(sq[1])) return true;

                    return false;
                }
            });
        }

        // Refined qualities

        // "Untapped Lands" - Count$UntappedTypeYouCtrl.Land
        if (sq[0].contains("Untapped")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return !c.isTapped();
                }
            });
        }

        if (sq[0].contains("Tapped")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return c.isTapped();
                }
            });
        }

        // "White Creatures" - Count$WhiteTypeYouCtrl.Creature
        if (sq[0].contains("White")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return CardUtil.isColor(c, Constant.Color.White);
                }
            });
        }

        if (sq[0].contains("Blue")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return CardUtil.isColor(c, Constant.Color.Blue);
                }
            });
        }

        if (sq[0].contains("Black")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return CardUtil.isColor(c, Constant.Color.Black);
                }
            });
        }

        if (sq[0].contains("Red")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return CardUtil.isColor(c, Constant.Color.Red);
                }
            });
        }

        if (sq[0].contains("Green")) {
            someCards = someCards.filter(new CardListFilter() {
                public boolean addCard(Card c) {
                    return CardUtil.isColor(c, Constant.Color.Green);
                }
            });
        }

        if (sq[0].contains("Multicolor")) someCards = someCards.filter(new CardListFilter() {
            public boolean addCard(Card c) {
                return (CardUtil.getColors(c).size() > 1);
            }
        });

        if (sq[0].contains("Monocolor")) someCards = someCards.filter(new CardListFilter() {
            public boolean addCard(Card c) {
                return (CardUtil.getColors(c).size() == 1);
            }
        });

        //Count$CardMulticolor.<numMC>.<numNotMC>
        if (sq[0].contains("CardMulticolor")) {
            if (CardUtil.getColors(c).size() > 1)
                return doXMath(Integer.parseInt(sq[1]), m, c);
            else
                return doXMath(Integer.parseInt(sq[2]), m, c);
        }

        // 1/10 - Count$MaxCMCYouCtrl
        if (sq[0].contains("MaxCMC")) {
            int mmc = 0;
            int cmc = 0;
            for (int i = 0; i < someCards.size(); i++) {
                cmc = CardUtil.getConvertedManaCost(someCards.getCard(i).getManaCost());
                if (cmc > mmc) mmc = cmc;
            }

            return doXMath(mmc, m, c);
        }

        n = someCards.size();

        return doXMath(n, m, c);
    }