package wargame;
import java.util.*;
public class Table {
public int n, p, c;
public LinkedList<String> shuffle = new LinkedList<String>();
public LinkedList<String> card = new LinkedList<String>();
public CompleteDeckCard getcard = new CompleteDeckCard();
LinkedList<String> playerNum = new LinkedList();
LinkedList<String> shuffledCards = cardShuffle();
public LinkedList<String> rank = new LinkedList<String>();
public CompleteDeckCard getrank = new CompleteDeckCard();
boolean winner;
//Determining the number of shuffles
public int tablePlay() {
System.out.println ("How many shuffles do you want? ");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println ("Your input is: " + n);
System.out.println ("Shuffling cards, please wait a moment ...");
return n;
}
//Shuffling of cards
public LinkedList<String> cardShuffle(){
card = getcard.cards();
for (int sc = 0; sc < n; sc++){
for( int x=0, y=26; x<26; x++,y++){
shuffle.add(card.get(x));
shuffle.add(card.get(y));
}
card.clear();
card.addAll(shuffle);
shuffle.clear();
}
//System.out.println("New Deck: " + shuffle);
return card;
}
//Determining the number of players
public LinkedList<String>[] player() {
rank = getrank.ranks();
Scanner in = new Scanner(System.in);
p = in.nextInt();
System.out.println ("Number of players: " + p);
System.out.println ("Creating list of players ... " );
//return p;
//Distribution of cards
shuffledCards = cardShuffle();
LinkedList<String>[] playerNum = new LinkedList[p];
for (int z=0; z<p; z++){
playerNum[z] = new LinkedList<String>();
System.out.println ("playerNum[" + z + "]");
}
while (!shuffledCards.isEmpty()){
for (int v=0; v<p; v++){
playerNum[v].addFirst(shuffledCards.pollFirst());
if (playerNum[v].contains(null))
playerNum[v].remove(null);
}
}
System.out.println (" ");
System.out.println ("Distributing cards ...");
for (int m=0; m<p; m++){
System.out.println ("playerNum[" + m + "]" + playerNum[m] );
}
//Getting the top card
while (!winner){
LinkedList<String> getTopCards = new LinkedList<String>();
for (int g=0; g<p; g++){
getTopCards.add(playerNum[g].pollFirst());
}
System.out.println (" ");
System.out.println ("Top Cards: " + getTopCards);
System.out.println (" ");
//Comparing the values
LinkedList<Integer> evaluate = new LinkedList<Integer>();
Collections.reverse(rank);
System.out.println ("Order of card: " +rank);
for( int s = 0; s < getTopCards.size(); s++){
evaluate.add(rank.indexOf(getTopCards.get(s)));
}
System.out.println(" ");
//System.out.println("Ranking: " + evaluate);
int e = evaluate.indexOf(Collections.max(evaluate));
System.out.println( "playerNum[" + e + "] is the winner. ");
System.out.println(" " );
//Collect the initial cards and give to the winner of the round
LinkedList<String> entry = new LinkedList<String>();
for (int d=e; d<p; d++){
entry.add(getTopCards.get(d));
}
if (e!=0){
for (int f=0; f<e; f++){
entry.add(getTopCards.get(f));
}
}
playerNum[e].addAll(entry);
while (playerNum[e].contains(null)){
playerNum[e].remove(null);
}
System.out.println ("Collected cards: " + entry);
//Determine number of rounds
LinkedList<Integer> rounds = new LinkedList<Integer> ();
for (int g=0; g<p; g++){
System.out.println (playerNum[g]);
//for (int h=0; h<p; h++){
if (playerNum[g].size() == 52){
winner = true;
break;
}
}
//}
}
return playerNum;
}
}