//
//  AIPlayer.java
//  cribbage
//
//  Created by Nathan Haug on Tue Apr 06 2004.
//  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

public class AIPlayer extends Player {

	public AIPlayer (String name,int playerID) {
		super(name,playerID);
	}

	public void addScore(int pointsScored) {
		this.setScore(getScore() + pointsScored);
	}

	public void putCard(Card aCard) {
		this.getHand().putCard(aCard);
	}

	public int getDiscardCard (Cribbage gameManager) {
		// The player must decide which card is best to discard to the crib
		
		// Call the tallyHand() function for each combonation of numCards-1 cards
		// We'll discard the card that makes the this.getHand() least valuable.
		Card returnCard;
		Hand testHand;
		int returnPos = 0;
		int highestScore = -1;
		int testScore;
		returnCard = this.getHand().getCard(3);
		
		for (int i=0; i < this.getHand().numCards(); i++) {
			testHand = new Hand(this.getHand());
			testHand.deleteCard(i);
			testScore = testHand.tally();
			
			if (testScore > highestScore) {
				highestScore = testScore;
				returnPos = i;
			}
		}
		System.out.println(this.getName()+" discards a card.");
		
		// Now we'll also make our copy of the this.getHand() for "The Show" later
		Hand myPeggingHand = new Hand(this.getHand());
		setPeggingHand(myPeggingHand);
		getPeggingHand().deleteCard(returnPos);
		
		return returnPos;
		
	}
	
	public int getPeggingCard (CurrentPlay cardsInPlay, Cribbage gameManager) {
		// The player chooses the card he wishes to play in pegging
		// if he has no playable cards, -1 is returned
		if (gameManager.isHumanMode())
			try {Thread.sleep(300);} catch (InterruptedException e) {}
		
		return getPeggingHand().getPeggingCard(cardsInPlay); // Returns -1 if no playable cards
	}

}


