Question: IN JAVA // This card game is a variation of the War card game described // in the book Object-Oriented Data Structures Using Java by
IN JAVA
// This card game is a variation of the War card game described // in the book "Object-Oriented Data Structures Using Java" by // N.Dale, D.T.Joyce and C.Weems. import java.util.*; public class StrangeCardGame { public static void main (String[] argv) { // Use cards numbered 0,..,9 and deal 5 cards to each player. playGame (5, 10); } static void playGame (int dealSize, int numCards) { // Cards dealt out to player 1: LinkedList player1 = new LinkedList(); // Cards dealt out to player 2: LinkedList player2 = new LinkedList(); // The pile between the two players: LinkedList pile = new LinkedList(); // Make the cards and shuffle them randomly. int[] cards = new int [numCards]; for (int i=0; i player1 gets pile"); } else if (player2first > player1first+2) { // Add pile into player 2's cards. addListToList (pile, player2); System.out.println (" => player2 gets pile"); } else { System.out.println (" => both cards added to pile"); } if (player1.isEmpty()) { System.out.println ("Player 2 wins!"); done = true; } else if (player2.isEmpty()) { System.out.println ("Player 1 wins!"); done = true; } } //end-while } static void shuffle (int[] A) { for (int i=0; i list1, LinkedList list2) { // INSERT YOUR CODE HERE. // This method should extract every item in list1 and add them to list2. } } 

Consider the following two-person card game: There are N cards numbered 0,. N-1 . Each player is dealt M cards from a shuffled deck. Each player is required to keep their pile of cards face down Players can't see the cards they haven't played yet. There is a common pile, initially empty, onto which players will add their cards. At every turn, each player "plays" by taking the card on top of their own pile and placing that in the common pile. The cards are revealed when "played" on to the common pile. If, in one turn, any one player's card exceeds the other's card by by more than 2, then that player gets to keep all the cards in the common pile. For example, if player 2 plays "7" and player 1 plays "3", then player 2 scoops up the common pile and adds it to the bottom of their own pile. The first player to have no cards remaining loses Consider the following two-person card game: There are N cards numbered 0,. N-1 . Each player is dealt M cards from a shuffled deck. Each player is required to keep their pile of cards face down Players can't see the cards they haven't played yet. There is a common pile, initially empty, onto which players will add their cards. At every turn, each player "plays" by taking the card on top of their own pile and placing that in the common pile. The cards are revealed when "played" on to the common pile. If, in one turn, any one player's card exceeds the other's card by by more than 2, then that player gets to keep all the cards in the common pile. For example, if player 2 plays "7" and player 1 plays "3", then player 2 scoops up the common pile and adds it to the bottom of their own pile. The first player to have no cards remaining loses
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
