import java.util.ArrayList;
import java.util.Scanner;

/**
 * Class that represents a row of cards.   
 *   @author Dave Reed
 *   @version 8/20/15
 */
public class RowOfCards {
    private ArrayList<Card> row;
    
    /**
     * Constructs an empty row of cards.
     */
    public RowOfCards() {
        this.row = new ArrayList<Card>();
    }
    
    /**
     * Adds a new card at the end of the current row of cards.
     *   @param newCard the card to be added
     */
    public void addCardAtEnd(Card newCard) {
        this.row.add(newCard);
    }
    
    /**
     * Moves a card on top of another card a specified number of spots away.
     *   @param cardToMove the card in the row to be moved
     *   @param numSpots the number of spots it is to be moved (to the left)
     *   @return true if the move was completed (i.e., there is a card the
     *           specified number of spots away that matches cardToMove).
     */
    public boolean moveCard(Card cardToMove, int numSpots) {
        int fromIndex = this.row.indexOf(cardToMove);
        int toIndex = fromIndex - numSpots;
        
        if (toIndex >= 0 && cardToMove.matches(this.row.get(toIndex))) {
                this.row.set(toIndex, cardToMove);
                this.row.remove(fromIndex);
                return true;
        }
        else {
            return false;
        }
    }
    
    /**
     * Determines the number of cards in the row.
     *   @return the number of cards
     */
    public int rowSize() {
        return this.row.size();
    }
      
    /**
     * Returns a string representation of the row.
     *   @return a string containing all of the cards from the row
     */
    public String toString() {
        String rowStr = "";
        for (Card c: this.row) {
            rowStr += c + " ";    
        }
        return rowStr;
    }
}