@Override
    public Card PlayAHand(Card topCard, Deck d)
    {
        log.entering("Play a hand", name);

        boolean done = false;
        boolean tried = false;
        int pos = 0; 
        Card toPlay = null; 

        log.fine("Trying to decide");

        int state = Decide(topCard);

        if (state == 1)
        {
            log.fine(String.format("Decided %s %s", state, playingCard.toString()));
        }
        else
        {
            log.fine(String.format("decided %s", state));
        }
        
        while (!done)
        {
           switch (state)
           {
                case 1: 
                        if (playingCard.getClass().equals(WildCard.class))
                        {
                            state = 4;
                        }
                        else
                        {
                            toPlay = hand.remove(FindCard(playingCard));
                            state = 5;
                        }
                        break;

                case 2: 
                        log.fine("Need to draw a card");
                        super.GetCard(d.DrawNext());
                        state = Decide(d.TopDiscard());
                        tried = true;
                        if (state == 2)
                        {
                            state = 3;
                        }
                        break;

                case 3: log.fine("Pass");
                        state = 5;
                        break;

                case 4: WildCard tmp = (WildCard)playingCard;
                        log.fine("Time for a wild card.");
                        int colorChoice = (int)(Math.random() * 3);
                        ByteArrayInputStream in = new ByteArrayInputStream(colorValues[colorChoice].toString().getBytes());
                        System.setIn(in);
                        tmp.Wild(new Scanner(System.in));
                        playingCard = (Card)tmp;
                        hand.remove(FindCard(playingCard));
                        state = 5;
                        break;

                case 5: log.fine("End turn");
                        done = true;
                        toPlay = playingCard;
                        break;

                default: log.severe("I don't know what to do");
                         break;
            }
        }

        log.exiting("Play a Hand", name);
        return toPlay;
    }