package piles;

/**
 * PileChecker.
 *
 * A class to create a pile and check its validity(whether it is fully
 * descending or not)
 *
 * @author: Alvin Chao
 * @version 1.0
 */

public class PileChecker {

    private Hand hand;
    private boolean validity;

    public PileChecker(Hand hand) {
        this.hand = hand;
        validity = check(hand, 0);
    }

    public boolean getValidity() {
        return this.validity;
    }

    public static boolean check(Hand h, int index) {
        // Base case: end of hand all cards descending order.
        if (index == h.size() - 1) {
            return true;
        }
        // Check if current card is greater than the next card
        if (h.getCard(index).getRank() > h.getCard(index + 1).getRank()) {
            // Recursively check the rest of the hand
            return check(h, index + 1);
        } else {
            return false;
        }
    }
}
