title: Uno Project: Making sure that a illegal plays return correctly?
body: <p>I am writing a chunk of program to play Uno with other classes. My Uno project is almost finished, but I need to be sure that the part which checks to make sure that on moves after a Wild Card is played, I play either a legal card or return a -1. Here is my code:</p>
  
  <pre><code>import java.util.*;
  public class AlexaL_UnoPlayer implements UnoPlayer
  {
  public int play(List&lt;Card&gt; hand, Card upCard, Color calledColor, GameState state)
  {
      int play = -1;
      boolean haveWild = false;
      boolean matchesWildCall = false;
      int indexOfWild = 0;
      //turn number of cards all players are holding into ints for later use
      int[] array = state.getNumCardsInHandsOfUpcomingPlayers();
      int playerNext = array[0];
      int playerTwoNext = array[1];
      int playerBefore = array[2];
      Color upCardColor = upCard.getColor();
  
      for(int i = 0; i &lt; hand.size(); i++)
      {
          //see if I have any wilds
          if(hand.get(i).getRank().equals(Rank.WILD) || hand.get(i).getRank().equals (Rank.WILD_D4))
          {
              haveWild = true;
              indexOfWild = i;
          }
          //set upCard color to calledColor if wild or wild_d4 are played
          if (upCard.getRank().equals(Rank.WILD) || upCard.getRank().equals(Rank.WILD_D4))
          {
              upCardColor = calledColor;
          }
          //always play a card matching rank of upCard, if possible, or play the first in hand which matches color
          if(hand.get(i).getColor().equals(upCardColor))
          {
              if(hand.get(i).getNumber() == upCard.getNumber())
              {
                  play = i;
              }
          }
  
          //if cornered(no matching number or color), play a wild
          else if(haveWild == true)
          {
              play = indexOfWild;
          }
  
          //hold reverse cards until person next after me has less cards than person before me
          if(hand.get(i).getRank().equals(Rank.REVERSE) &amp;&amp; playerNext &lt; playerBefore)
          {
              play = i;
          }
  
          //play skips when person next to me has less cards than me
          if((hand.get(i).getRank().equals(Rank.SKIP) || hand.get(i).getRank().equals(Rank.DRAW_TWO)) &amp;&amp; playerNext &lt; hand.size())
          {
              play = i;
          }
  
      }
      return play;
  }
  
  public Color callColor(List&lt;Card&gt; hand)
  {
      //strategy: change the color to the one i'm holding the most of
      Color changeTo = Color.GREEN;
      int numBlues = 0;
      int numGreens = 0;
      int numReds = 0;
      int numYellows = 0;
      //find out how many of each color i'm holding
      for(int i = 0; i &lt; hand.size(); i++)
      {
          if(hand.get(i).getColor().equals(Color.BLUE))
          {
              numBlues++;
          }
          else if(hand.get(i).getColor().equals(Color.RED))
          {
              numReds++;
          }
          else if(hand.get(i).getColor().equals(Color.GREEN))
          {
              numGreens++;
          }
          else if(hand.get(i).getColor().equals(Color.YELLOW))
          {
              numYellows++;
          }
      }
      //find out which i'm holding the most of and call that color
      //if no majority, return my favorite color(green)
      if(numBlues &gt; numReds &amp;&amp; numBlues &gt; numGreens &amp;&amp; numBlues &gt; numYellows)
      {
          changeTo = Color.BLUE;
      }
      else if(numReds &gt; numBlues &amp;&amp; numReds &gt; numGreens &amp;&amp; numReds &gt; numYellows)
      {
          changeTo = Color.RED;
      }
      else if(numGreens &gt; numBlues &amp;&amp; numGreens &gt; numYellows &amp;&amp; numGreens &gt; numReds)
      {
          changeTo = Color.GREEN;
      }
      else if(numYellows &gt; numBlues &amp;&amp; numYellows &gt; numGreens &amp;&amp; numYellows &gt; numReds)
      {
          changeTo = Color.YELLOW;
      }
      else 
      {
          changeTo = Color.GREEN;            
      }
      return changeTo;
  }
  }
  </code></pre>
  
  <p>For some reason, my output is telling me this:</p>
  
  <pre><code>You were given this hand:
    0. G7
    1. G5
    2. G+2
  and the up card was: W
  and the called color was: YELLOW
  and you (wrongly) returned 2.
  Valid plays would have included: -1
  </code></pre>
  
  <p>Can anyone provide some insight on why I am getting this error and how to fix it? Much appreciated!</p>