package newpackage; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.Scanner; public class GoFish { public static int draw(ArrayList deck) { Random random = new Random(); int cardChosen = 0; int cardChoice = random.nextInt(deck.size()); cardChosen = deck.get(cardChoice); deck.remove(cardChoice); return cardChosen; } public static int[] deal(int num, ArrayList deck) { int[] positionarray = new int[num]; int[] positionarraysorted = new int[num]; int[] outputarray = new int[num]; int arrayCounter = 0; for (int x = 0; x < num; x++) { Random random = new Random(); int position = random.nextInt(deck.size()); positionarray[x] = position; } Arrays.sort(positionarray); int stupidjvariable = 0; for (int j = 0; j < positionarray.length; j++); { positionarraysorted[arrayCounter] = positionarray[positionarray.length - stupidjvariable - 1]; stupidjvariable++; arrayCounter++; } for (int i = 0; i < positionarraysorted.length; i++) { outputarray[i] = deck.get(i); deck.remove(i); } return outputarray; } public static ArrayList> take(ArrayList hand1, ArrayList hand2, int card) { ArrayList> returnlist = new ArrayList>(); for (int x = 0; x < hand2.size(); x++) { if (hand2.get(x).equals(card)) { hand1.add(hand2.get(x)); } } for (int x = hand2.size(); x > 0; x--) { if(hand2.get(x-1).equals(card)) { hand2.remove(x-1); } } returnlist.add(hand1); returnlist.add(hand2); return returnlist; } public static String ArrayListToString(ArrayList array) { int[] str = new int[array.size()]; for (int j = 0; j < array.size(); j++) { str[j] = array.get(j); } String converted = Arrays.toString(str); return converted; } public static void main(String[] args) { ArrayList MainDeck = new ArrayList(); ArrayList PlayerOneDeck = new ArrayList(); ArrayList PlayerTwoDeck = new ArrayList(); int[] PlayerOneOccurences = new int[13]; int[] PlayerTwoOccurences = new int[13]; @SuppressWarnings("resource") Scanner input = new Scanner(System.in); int playeronepoints = 0; int playertwopoints = 0; for(int x = 1; x < 14; x++) { MainDeck.add(x); MainDeck.add(x); MainDeck.add(x); MainDeck.add(x); } Collections.shuffle(MainDeck); System.out.println("Program Debug."); int[] a = (deal(7, MainDeck)); for (int i=0; i 0; y--) { if (PlayerOneDeck.get(y-1) == IndexCounterOne-1) { PlayerOneDeck.remove(y-1); } } x = 0; } } Arrays.fill(PlayerOneOccurences, 0); Arrays.fill(PlayerTwoOccurences, 0); for (int x : PlayerTwoDeck) { PlayerTwoOccurences[x-1]++; } for (int x : PlayerTwoOccurences) { IndexCounterTwo++; if (x == 4) { playertwopoints++; System.out.println("Player Two get's a point for matching: " + (IndexCounterTwo-1)); for (int y = PlayerTwoDeck.size(); y > 0; y--) { if (PlayerTwoDeck.get(y-1) == IndexCounterTwo-1) { PlayerTwoDeck.remove(y-1); } } x = 0; } } System.out.println("Current Score is: " + playeronepoints + " to " + playertwopoints + "."); System.out.println("Player One's Hand: " + ArrayListToString(PlayerOneDeck)); System.out.print("Player One, choose a number to GoFish: "); int fishinput = input.nextInt(); if (PlayerTwoDeck.contains(fishinput)) { System.out.println("It's a match!"); take(PlayerOneDeck, PlayerTwoDeck, fishinput); System.out.println("Player One's Hand: " + ArrayListToString(PlayerOneDeck)); } else if (MainDeck.size() == 0) { System.out.println("The deck is empty!"); System.out.println("Player One's Hand: " + ArrayListToString(PlayerOneDeck)); } else { System.out.println("GoFish!"); PlayerOneDeck.add(draw(MainDeck)); System.out.println("Player One's Hand: " + ArrayListToString(PlayerOneDeck)); } System.out.println("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n "); Arrays.fill(PlayerOneOccurences, 0); Arrays.fill(PlayerTwoOccurences, 0); for (int x : PlayerOneDeck) { PlayerOneOccurences[x-1]++; } for (int x : PlayerOneOccurences) { IndexCounterOne++; if (x == 4) { playeronepoints++; System.out.println("Player One get's a point for matching: " + (IndexCounterOne-1)); for (int y = PlayerOneDeck.size(); y > 0; y--) { if (PlayerOneDeck.get(y-1) == IndexCounterOne-1) { PlayerOneDeck.remove(y-1); } } x = 0; } } for (int x : PlayerTwoDeck) { PlayerTwoOccurences[x-1]++; } for (int x : PlayerTwoOccurences) { IndexCounterTwo++; if (x == 4) { playertwopoints++; System.out.println("Player Two get's a point for matching: " + (IndexCounterTwo-1)); for (int y = PlayerTwoDeck.size(); y > 0; y--) { if (PlayerTwoDeck.get(y-1) == IndexCounterTwo-1) { PlayerTwoDeck.remove(y-1); } } x = 0; } } Arrays.fill(PlayerOneOccurences, 0); Arrays.fill(PlayerTwoOccurences, 0); System.out.println("Current Score is: " + playeronepoints + " to " + playertwopoints + "."); System.out.println("Player Two's Hand: " + ArrayListToString(PlayerTwoDeck)); System.out.print("Player Two, choose a number to GoFish: "); fishinput = input.nextInt(); if (PlayerOneDeck.contains(fishinput)) { System.out.println("It's a match!"); take(PlayerTwoDeck, PlayerOneDeck, fishinput); System.out.println("Player Two's Hand: " + ArrayListToString(PlayerTwoDeck)); } else if (MainDeck.size() == 0) { System.out.println("The deck is empty!"); System.out.println("Player Two's Hand: " + ArrayListToString(PlayerTwoDeck)); } else { System.out.println("GoFish!"); PlayerTwoDeck.add(draw(MainDeck)); System.out.println("Player Two's Hand: " + ArrayListToString(PlayerTwoDeck)); } System.out.println("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n "); } if (playeronepoints > playertwopoints) { System.out.println("PLAYER ONE WINS!"); } else if (playeronepoints < playertwopoints) { System.out.println("PLAYER TWO WINS!"); } else { System.out.println("It's a TIE! (Which consequently means that the program bugged because that isn't supposed to happen!)"); } } }