import java.util.Scanner;

/*******************************************************************
 Name: Trevor Spalt
 Date: March 12, 2007
 Section: 2
 Lab: PA2
/*******************************************************************
 * This is the main driver. It will act as the dealer and fill use
 * the other classes to fill the players hands (deal). It will also
 * take in the players names, and finally give the output at the end
 * of the program.
 /*******************************************************************
 *
 * I recieved limited help on this assignment by a PA.
 */

public class Dealer
{
   public static void main (String [] args)
   {
		Deck myDeck;
		myDeck = new Deck();
		Card myCard;
		
		int pointHolder1, pointHolder2, pointHolder3, pointHolder4;
		
		String playerName1, playerName2, playerName3, playerName4;
		
		Scanner inputScanner;
		inputScanner = new Scanner(System.in);
		
		// This variable will hold the string of all winning players
		String winningPlayers;
		
		// Create four Bridge hands for the four players
		BridgeHand player1, player2, player3, player4;
		player1 = new BridgeHand();
		player2 = new BridgeHand();
		player3 = new BridgeHand();
		player4 = new BridgeHand();
		
		// Introduce the program and give explanation to what it does
		System.out.println
		("************ Welcome to the BridgeHand Program ************");
		System.out.println
		("This program will take in four different players names. It ");
		System.out.println
		("will then create four unique bridge hands, each consisting ");
		System.out.println
		("of 13 cards, and evaluate those hands to find which one is ");
		System.out.println
		("the best bridge hand.");
		
		// Take in the players names and assign them to seperate player
		// objects.
		System.out.print("\nEnter player Name: ");
		playerName1 = inputScanner.next();
		System.out.print("\nEnter player Name: ");
		playerName2 = inputScanner.next();
		System.out.print("\nEnter player Name: ");
		playerName3 = inputScanner.next();
		System.out.print("\nEnter player Name: ");
		playerName4 = inputScanner.next();		
		
		// Shuffle the deck
		myDeck.Shuffle();
		
		// Place the card in each of the players hands
		// using a loop to do so
		for(int i = 0; i < 13; i++)
		{			
			// Get a card to put in the player1's hand
			myCard = myDeck.Deal();
			player1.putCardInHand(myCard);
			
			// Get a card to put in the player2's hand
			myCard = myDeck.Deal();
			player2.putCardInHand(myCard);
			
			// Get a card to put in the player3's hand
			myCard = myDeck.Deal();
			player3.putCardInHand(myCard);
			
			// Get a card to put in the player4's hand
			myCard = myDeck.Deal();
			player4.putCardInHand(myCard);
		}
		
		// Create 4 player object. One for each player.
		player play1, play2, play3, play4;
		play1 = new player(playerName1, player1);
		play2 = new player(playerName2, player2);
		play3 = new player(playerName3, player3);
		play4 = new player(playerName4, player4);
		
		// Evaluate the point value of each of the four players hands
		pointHolder1 = player1.evaluateHand();
		pointHolder2 = player2.evaluateHand();
		pointHolder3 = player3.evaluateHand();
		pointHolder4 = player4.evaluateHand();
		
		// Output the player's name, hand, and total points
		System.out.println("\n" + play1 + "\n" + "Total Number of points: " + pointHolder1);
		System.out.println("\n" + play2 + "\n" + "Total Number of points: " + pointHolder2);
		System.out.println("\n" + play3 + "\n" + "Total Number of points: " + pointHolder3);
		System.out.println("\n" + play4 + "\n" + "Total Number of points: " + pointHolder4);
		
		// Use an if statement to find which hand(s) is the winner
		if(pointHolder1 > pointHolder2)
		{
			if(pointHolder1 > pointHolder3)
			{
				if(pointHolder1 > pointHolder4)
				{
					winningPlayers = play1.getName();
				}// end if
				else if(pointHolder1 == pointHolder4)
				{
					//player4 wins and 1
					winningPlayers = play1.getName() + " " + play4.getName();
				}// end else if
				else
				{
					winningPlayers = play4.getName();
				}// end else
			}// end if
			else if(pointHolder3 > pointHolder4)
			{
				winningPlayers = play3.getName();
			}// end else if
			else if(pointHolder3 == pointHolder4)
			{
				winningPlayers = play3.getName() + " " + play4.getName();
			}// end else if
			else
			{
				winningPlayers = play4.getName();
			}// end else
		}// end if
		else if(pointHolder2 > pointHolder3)
		{
			if(pointHolder2 > pointHolder4)
			{
				winningPlayers = play2.getName();
			}// end if
			else if(pointHolder2 == pointHolder4)
			{
				winningPlayers = play2.getName() + " " + play4.getName();
			}// end else if
			else
			{
				winningPlayers = play4.getName();
			}// end else
		}// end else if
		else if(pointHolder3 > pointHolder4)
		{
			winningPlayers = play3.getName();
		}// end else if
		else if(pointHolder3 == pointHolder4)
		{
			winningPlayers = play3.getName() + " " + play4.getName();
		}// end else if
		else
		{
			winningPlayers = play4.getName();
		}// end else
		
		// Output the winner or winners and then display end message.
		System.out.println("\nThe winner(s) is: " + winningPlayers);
		System.out.print("\nThe program has ended normally");
  	}// end main
}// end class