SlideShare a Scribd company logo
1 of 15
Download to read offline
Here is the game description:
Here is the sample game:
Goal: Your goal in this assignment is to write a Java program that simulates this card game
and prints the sequence of played cards and the winner at the end, as shown above. Use
Dealer.java, GeneralPlayer.java, Main.java, Card.java, Table.java, and Deck.java, complete
CardPlayer.java and CardTable.java.
Given codes:
Dealer.java :
import java.util.Random;
/**
* This class represents a dealer who shuffles a deck of cards and
* distributes them to players.
*/
public class Dealer {
private Deck deck;
/**
* Creates a new Dealer object with the specified players and deck.
*
* @param players the array of CardPlayer objects to distribute the cards to
* @param deck the Deck object to shuffle and distribute
*/
public Dealer(CardPlayer[] players, Deck deck) {
this.deck = deck;
this.shuffle();
this.distribute(players, this.deck);
}
/**
* Distributes the cards in the deck to the specified players.
*
* @param players the array of CardPlayer objects to distribute the cards to
* @param deck the Deck object to distribute
*/
private void distribute(CardPlayer[] players, Deck deck) {
for (int cardCounter = 0; cardCounter < deck.cards.length; cardCounter += players.length) {
for (int playerCounter = 0; playerCounter < players.length; playerCounter++) {
players[playerCounter].addToHand(deck.cards[cardCounter + playerCounter]);
}
}
}
/**
* Shuffles the cards in the deck; it generates two random variables as the card
* index and swaps them.
*/
private void shuffle() {
Random randomNumber = new Random();
for (int card = 0; card < this.deck.cards.length; card++) {
swap(randomNumber.nextInt(deck.cards.length), randomNumber.nextInt(deck.cards.length));
}
}
/**
* Swaps the positions of two cards in the deck.
*
* @param random1 the index of the first card to swap
* @param random2 the index of the second card to swap
*/
private void swap(int random1, int random2) {
Card temp;
temp = this.deck.cards[random1];
this.deck.cards[random1] = this.deck.cards[random2];
this.deck.cards[random2] = temp;
}
/**
* Prints out the identifier of each card in the deck.
*/
public void showDeck() {
for (Card card : this.deck.cards) {
System.out.println(card.identifier);
}
}
}
GeneralPlayer.java:
/**
* An abstract class representing a general player.
*
* @param <T> the type of the value returned by the player's play method.
*/
public abstract class GeneralPlayer<T> {
/** The name of the player. */
public String name;
/**
* Creates a new GeneralPlayer with a default name.
*/
public GeneralPlayer() {
this.name = "General Player";
}
/**
* Creates a new GeneralPlayer with the given name.
*
* @param name the name of the player.
*/
public GeneralPlayer(String name) {
this.name = name;
}
/**
* Makes a move or takes an action, depending on the implementation.
*
* @return the result of the player's action or move.
*/
public abstract T play();
}
Card.java:
/**
* A class that represents a playing card with a rank and suit.
*/
public class Card {
/**
* The rank of the card which is a number from 1 to 13.
* Includes King, Queen, Jack, and Ace.
*/
private int rank;
/**
* The suit of the card which is a number from 1 to 4
* Can be clubs (), diamonds (), hearts () or spades ().
*/
private int suit;
/**
* The identifier of the card.
* It is a unique number assigned to each card based on its rank and suit.
* The identifier is calculated as suit * 100 + rank.
*/
public final int identifier;
/**
* Creates a new Card with the given suit and rank.
* It assigns the identifier as well
*
* @param suit The suit of the card.
* @param rank The rank of the card.
*/
public Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
this.identifier = suit * 100 + rank;
}
/**
* Gets the rank of the card.
*
* @return The rank of the card.
*/
public int getRank() {
return rank;
}
/**
* Sets the rank of the card.
*
* @param rank The new rank of the card.
*/
public void setRank(int rank) {
this.rank = rank;
}
/**
* Gets the suit of the card.
*
* @return The suit of the card.
*/
public int getSuit() {
return suit;
}
/**
* Sets the suit of the card.
*
* @param suit The new suit of the card.
*/
public void setSuit(int suit) {
this.suit = suit;
}
}
Table.java:
/**
* An interface representing a table where cards are played and players can
* occupy places.
*
* @param <T> the type of cards that can be added to the table.
* @param <E> the type of players that can occupy places on the table.
*/
public interface Table<T extends Card, E extends GeneralPlayer> {
/**
* The number of places on the table that players can put their cards.
*/
final int NUMBER_OF_PLACES = 4;
/**
* Adds a card to the table at the first available place.
*
* @param card the card to add to the table.
*/
public void addCardToPlace(T card);
/**
* Returns the identifiers of the cards on places 1, 2, 3, and 4 on the table
* (in that same order).
*
* @return an array of integers representing the identifiers of all cards placed on the table
*/
public int[] getPlaces();
/**
* Checks the places on the table to see if any player occupies a place and
* removes any cards that they played.
*
* @param player the player to check for occupying a place.
*/
public void checkPlaces(E player);
}
Main.java:
/**
* The Main class represents the entry point for the card game.
*/
public class Main {
/**
* The main method initializes the game and starts playing until there's a
* winner.
*
* @param args command line arguments.
*/
public static void main(String[] args) {
// Create a new deck of cards.
Deck deck = new Deck();
// Create two players and assign their names.
CardPlayer[] players = new CardPlayer[2];
players[0] = new CardPlayer("Player 1");
players[1] = new CardPlayer("Player 2");
// Create a dealer and assign the players and deck to it.
Dealer dealer = new Dealer(players, deck);
// Create a new table to place the cards on.
CardTable table = new CardTable();
// Set the first player's turn.
players[0].setTurn(true);
// Print headers for table places.
System.out.println(" CardTable Places ");
System.out.println("-------------------------");
System.out.println("| p1 | p2 | p3 | p4 |");
System.out.println("-------------------------");
int numItrs = 0; // keep track of how many iterations are played
// Play until there's a winner.
while (players[0].getHand().size() != 0 && players[1].getHand().size() != 0) {
if (players[0].isTurn()) {
// Player 1 plays a card.
table.addCardToPlace(players[0].play());
table.checkPlaces(players[0]);
// Set Player 2's turn.
players[1].setTurn(true);
} else if (players[1].isTurn()) {
// Player 2 plays a card.
table.addCardToPlace(players[1].play());
table.checkPlaces(players[1]);
// Set Player 1's turn.
players[0].setTurn(true);
}
numItrs++; // update number of iterations counter
// Show the cards on the table
System.out.printf("| %3d | %3d | %3d | %3d | n",
table.getPlaces()[0], table.getPlaces()[1], table.getPlaces()[2], table.getPlaces()[3]);
}
System.out.println("-------------------------");
System.out.println("End of game. Total #iterations = " + numItrs);
// Display each player's bank of cards:
for (CardPlayer player : players) {
System.out.println(player.bankToString());
}
// Display the winner of the game:
CardPlayer winner = players[0];
for (CardPlayer player : players) {
if (player.getPoints() > winner.getPoints()) {
winner = player;
}
}
System.out.println("The winner is: " + winner.name + " (Points: " + winner.getPoints() + ")");
}
}
Codes needed to be completed:
CardPlayer.java:
/**
* A class that represents a card player.
*
* For each card player instance, we should keep track of how many points
* they earned in the game so far, as well as whether it is their turn or not.
* Additionally, their hand and bank of cards should be stored in two
* separate ArrayLists of Card objects.
*
* <p>
* A player's points, turn, and hand of cards should all be declared
* private fields, whereas the bank of cards should be public, as follows:
* <p>
* <code>
* private int points;
*
* private boolean turn;
*
* private ArrayList&lt;Card&gt; hand = new ArrayList&lt;Card&gt;();
*
* public ArrayList&lt;Card&gt; bank = new ArrayList&lt;Card&gt;();
* </code>
* <p>
*
* Note that the Field Summary section below will only show you public fields,
* but you must declare all the fields described above in your implementation of
this class,
* including the private fields. You are free to create additional fields if deemed
necessary.
*
* @param <Card> the type of card used in the game
*/
// TODO: Create class CardPlayer.
CardTable.java :
/**
*
* This class represents a table where a game is being played.
*
* It implements the Table interface and is designed to work with Card and
* CardPlayer objects.
*
* <p>
* Each table instance must keep track of the cards that players place on the table
* during the game. The number of places available has a fixed size
(<code>NUMBER_OF_PLACES</code>),
* so we use a regular Java array to represent a CardTable's places field.
* Each entry in this places array contains
* the cards that were added to that place, which is a more dynamic structure (we
don't know
* in advance how many cards will be added to this place!).
* <p>
* Therefore, each place
* entry in this array will reference an ArrayList of Card objects.
* <p>
* Here is how to declare the array of ArrayLists field <code>places</code>:
*
* <p>
* <code>
* private ArrayList&lt;Card&gt;[] places = new
ArrayList[NUMBER_OF_PLACES];
* </code>
* <p>
*
* Note that the Field Summary section below will only show you public fields,
* but you must declare the required field places described above, which is
private.
* You are also free to create additional fields in your class implementation, if
deemed necessary.
*
*/
// TODO: Complete the implementation of class CardTable below according
// to the class documentation described here:
// https://www.cs.emory.edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardTable.html
public class CardTable { // TODO: Fix class declaration to implement Table
interface (see documentation)
// TODO: create all required instance variables (you can add more variables
if needed)
// TODO: basic, no-argument constructor initializes all table
// places to new ArrayLists of Card objects
// TODO: implement all required CardTable methods (you can add helper methods
if needed)
}
Requirement: Finish CardPlayer.java and CardTable.java without changing any other given
code, to successfully generate a game with Main.java.
Game description: In this assignment, you will be implementing a simple game of cards. The
game uses a standard 52-card deck; there are four suits and each suit has 13 ranks. For
simplicity, we use numbers to identify cards in this sssignment. Thus, we have suits 1,2, 3, and 4,
and rarks from 1 to 13 (inclusive). Fach card is identified by its suit number followed by its rank.
For example, card 102 refers to the card whose suit is 1 and rank is 02 . Therefore, we can use
the simple formula suit*100+rank to produce a card's identifier. Figure - below shows the
different entities involved in this game: a dealer who has a deck of cards, two players, and a table
with exactly four places where players can place their cards during the game. Each player has a
hand of cards that is private to them (i.e., not visible to anyone else), and a bank of cards
containing all cards they won during the game (visible to the public). Figure 1: An illustration of
the different entities involved in our card game. The game begins with the dealer shuffling the
deck then distributing (i.e., dealing) the cards to the two players. The players then take turns in
placing their cards on the table, one card a time, starting with place 1 (i.e., places [ 0 ] in our
array implementation), followed by place 2, etc., when a player places a card in place 4 , the next
player places their card in place 1 , and so on. The top card in each place on the table is visible to
everyone. Note: We use the term current place to indicate where the current player can place
their card. 1 When a player wants to play a card, there are two possible scenarios: 1. If there is
another visible card (in places other than the current place) whose rank is the same as the current
player's card rank, then the player takes that card from the table and adds both cards to their
bank. One point is added to the player's score. 2. If none of the visible cards (in places other than
the current place) have a rank that matches the current player's card rank, then this new card
becomes the top card in the current place on the table. No points are added to the player's score.
Then, the next player plays a card, and so on. The game continues until both players finish their
cards. We then count the number of pairs of matching cards they have collected in their banks,
and the winner is the player with more pairs (the most points). If there is a tie, then for simplicity
we can consider player 1 to be the winner (after all, this is just a simulation ;-). Sample Game:
Below is the output of a sample game (where all the rules are implemented correctly). We print
the content of all 4 table places in each iteration, with 1 indicating that no card is placed in that
position 2 Player 1 bank has 10 carda: 401 101402 302 109409404204412112 playar 2 bank has
4 carda: 208 308 106206

More Related Content

Similar to Here is the game description- Here is the sample game- Goal- Your goal (1).pdf

C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfezzi97
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfadwitanokiastore
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdfkavithaarp
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfasif1401
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfshahidqamar17
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 

Similar to Here is the game description- Here is the sample game- Goal- Your goal (1).pdf (10)

C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
 
public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 

More from trishulinoverseas1

Hi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdfHi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdftrishulinoverseas1
 
hey guys do fill the t accounts out of it in the below screenshot att.pdf
hey guys  do fill the t accounts out of it in the below screenshot att.pdfhey guys  do fill the t accounts out of it in the below screenshot att.pdf
hey guys do fill the t accounts out of it in the below screenshot att.pdftrishulinoverseas1
 
Hi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdfHi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdftrishulinoverseas1
 
Hi Expert ! could you please type the answers to see better! microbio.pdf
Hi Expert !  could you please type the answers to see better! microbio.pdfHi Expert !  could you please type the answers to see better! microbio.pdf
Hi Expert ! could you please type the answers to see better! microbio.pdftrishulinoverseas1
 
Hey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdfHey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdftrishulinoverseas1
 
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdfHhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdftrishulinoverseas1
 
here is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdfhere is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdftrishulinoverseas1
 
Here- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdfHere- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdftrishulinoverseas1
 
Here are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdfHere are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdftrishulinoverseas1
 
Here is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdfHere is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdftrishulinoverseas1
 
Here is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdfHere is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdftrishulinoverseas1
 
Here are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdfHere are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdftrishulinoverseas1
 
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdfHomework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdftrishulinoverseas1
 
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdfHot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdftrishulinoverseas1
 
Housing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdfHousing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdftrishulinoverseas1
 
hotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdfhotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdftrishulinoverseas1
 
Herb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdfHerb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdftrishulinoverseas1
 
Homework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdfHomework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdftrishulinoverseas1
 
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdfHomework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdftrishulinoverseas1
 
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdf
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdfHome Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdf
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdftrishulinoverseas1
 

More from trishulinoverseas1 (20)

Hi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdfHi I need help with this problem thank you! Hi I need help with this p.pdf
Hi I need help with this problem thank you! Hi I need help with this p.pdf
 
hey guys do fill the t accounts out of it in the below screenshot att.pdf
hey guys  do fill the t accounts out of it in the below screenshot att.pdfhey guys  do fill the t accounts out of it in the below screenshot att.pdf
hey guys do fill the t accounts out of it in the below screenshot att.pdf
 
Hi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdfHi Expert- could you please type the answers to see better )micro cour.pdf
Hi Expert- could you please type the answers to see better )micro cour.pdf
 
Hi Expert ! could you please type the answers to see better! microbio.pdf
Hi Expert !  could you please type the answers to see better! microbio.pdfHi Expert !  could you please type the answers to see better! microbio.pdf
Hi Expert ! could you please type the answers to see better! microbio.pdf
 
Hey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdfHey- I am struggling with this question- please help Journal entrv wor.pdf
Hey- I am struggling with this question- please help Journal entrv wor.pdf
 
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdfHhiory and Fhoweal Labocatery Results  Complete the diagram by draggin.pdf
Hhiory and Fhoweal Labocatery Results Complete the diagram by draggin.pdf
 
here is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdfhere is my code so far but I cant get it to run properly because I kee.pdf
here is my code so far but I cant get it to run properly because I kee.pdf
 
Here- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdfHere- for esample- HTTH represents the outcome that the first toss is.pdf
Here- for esample- HTTH represents the outcome that the first toss is.pdf
 
Here are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdfHere are the errors associated with a particular forecast over the pas.pdf
Here are the errors associated with a particular forecast over the pas.pdf
 
Here is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdfHere is an example of active- natural immunity- If you had chicken pox.pdf
Here is an example of active- natural immunity- If you had chicken pox.pdf
 
Here is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdfHere is a chart of the Nasdaq Composite- the world's main technology i.pdf
Here is a chart of the Nasdaq Composite- the world's main technology i.pdf
 
Here are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdfHere are the alphas and the betas for Company A and Company B- Alpha i.pdf
Here are the alphas and the betas for Company A and Company B- Alpha i.pdf
 
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdfHomework for Day 1 Design and carry out a simulation to answer the fol.pdf
Homework for Day 1 Design and carry out a simulation to answer the fol.pdf
 
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdfHot spots are used as a proof of P2T- the continent sliding over a sta.pdf
Hot spots are used as a proof of P2T- the continent sliding over a sta.pdf
 
Housing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdfHousing DataThe accompanying frequency distribution represents the own.pdf
Housing DataThe accompanying frequency distribution represents the own.pdf
 
hotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdfhotel BLU Vancouver what steps and progress has been achieved 6points.pdf
hotel BLU Vancouver what steps and progress has been achieved 6points.pdf
 
Herb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdfHerb and Alice are married and file a joint return- Herb is 74 years o.pdf
Herb and Alice are married and file a joint return- Herb is 74 years o.pdf
 
Homework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdfHomework E-1- Write a class for a School- Use a School object in the S.pdf
Homework E-1- Write a class for a School- Use a School object in the S.pdf
 
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdfHomework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
Homework - Unanswered - Due Today- 4-45 PM assume 100 units of energy.pdf
 
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdf
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdfHome Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdf
Home Insert Page Layout Formulas Data Review View HelpL34- 7 In cell M.pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of PlayPooky Knightsmith
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 

Recently uploaded (20)

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 

Here is the game description- Here is the sample game- Goal- Your goal (1).pdf

  • 1. Here is the game description: Here is the sample game: Goal: Your goal in this assignment is to write a Java program that simulates this card game and prints the sequence of played cards and the winner at the end, as shown above. Use Dealer.java, GeneralPlayer.java, Main.java, Card.java, Table.java, and Deck.java, complete CardPlayer.java and CardTable.java. Given codes: Dealer.java : import java.util.Random; /** * This class represents a dealer who shuffles a deck of cards and * distributes them to players. */ public class Dealer { private Deck deck; /** * Creates a new Dealer object with the specified players and deck. * * @param players the array of CardPlayer objects to distribute the cards to * @param deck the Deck object to shuffle and distribute */ public Dealer(CardPlayer[] players, Deck deck) { this.deck = deck; this.shuffle(); this.distribute(players, this.deck);
  • 2. } /** * Distributes the cards in the deck to the specified players. * * @param players the array of CardPlayer objects to distribute the cards to * @param deck the Deck object to distribute */ private void distribute(CardPlayer[] players, Deck deck) { for (int cardCounter = 0; cardCounter < deck.cards.length; cardCounter += players.length) { for (int playerCounter = 0; playerCounter < players.length; playerCounter++) { players[playerCounter].addToHand(deck.cards[cardCounter + playerCounter]); } } } /** * Shuffles the cards in the deck; it generates two random variables as the card * index and swaps them. */ private void shuffle() { Random randomNumber = new Random(); for (int card = 0; card < this.deck.cards.length; card++) { swap(randomNumber.nextInt(deck.cards.length), randomNumber.nextInt(deck.cards.length)); }
  • 3. } /** * Swaps the positions of two cards in the deck. * * @param random1 the index of the first card to swap * @param random2 the index of the second card to swap */ private void swap(int random1, int random2) { Card temp; temp = this.deck.cards[random1]; this.deck.cards[random1] = this.deck.cards[random2]; this.deck.cards[random2] = temp; } /** * Prints out the identifier of each card in the deck. */ public void showDeck() { for (Card card : this.deck.cards) { System.out.println(card.identifier); } } } GeneralPlayer.java:
  • 4. /** * An abstract class representing a general player. * * @param <T> the type of the value returned by the player's play method. */ public abstract class GeneralPlayer<T> { /** The name of the player. */ public String name; /** * Creates a new GeneralPlayer with a default name. */ public GeneralPlayer() { this.name = "General Player"; } /** * Creates a new GeneralPlayer with the given name. * * @param name the name of the player. */ public GeneralPlayer(String name) { this.name = name; } /**
  • 5. * Makes a move or takes an action, depending on the implementation. * * @return the result of the player's action or move. */ public abstract T play(); } Card.java: /** * A class that represents a playing card with a rank and suit. */ public class Card { /** * The rank of the card which is a number from 1 to 13. * Includes King, Queen, Jack, and Ace. */ private int rank; /** * The suit of the card which is a number from 1 to 4 * Can be clubs (), diamonds (), hearts () or spades (). */ private int suit; /** * The identifier of the card.
  • 6. * It is a unique number assigned to each card based on its rank and suit. * The identifier is calculated as suit * 100 + rank. */ public final int identifier; /** * Creates a new Card with the given suit and rank. * It assigns the identifier as well * * @param suit The suit of the card. * @param rank The rank of the card. */ public Card(int suit, int rank) { this.suit = suit; this.rank = rank; this.identifier = suit * 100 + rank; } /** * Gets the rank of the card. * * @return The rank of the card. */ public int getRank() { return rank;
  • 7. } /** * Sets the rank of the card. * * @param rank The new rank of the card. */ public void setRank(int rank) { this.rank = rank; } /** * Gets the suit of the card. * * @return The suit of the card. */ public int getSuit() { return suit; } /** * Sets the suit of the card. * * @param suit The new suit of the card. */ public void setSuit(int suit) {
  • 8. this.suit = suit; } } Table.java: /** * An interface representing a table where cards are played and players can * occupy places. * * @param <T> the type of cards that can be added to the table. * @param <E> the type of players that can occupy places on the table. */ public interface Table<T extends Card, E extends GeneralPlayer> { /** * The number of places on the table that players can put their cards. */ final int NUMBER_OF_PLACES = 4; /** * Adds a card to the table at the first available place. * * @param card the card to add to the table. */ public void addCardToPlace(T card); /**
  • 9. * Returns the identifiers of the cards on places 1, 2, 3, and 4 on the table * (in that same order). * * @return an array of integers representing the identifiers of all cards placed on the table */ public int[] getPlaces(); /** * Checks the places on the table to see if any player occupies a place and * removes any cards that they played. * * @param player the player to check for occupying a place. */ public void checkPlaces(E player); } Main.java: /** * The Main class represents the entry point for the card game. */ public class Main { /** * The main method initializes the game and starts playing until there's a * winner. *
  • 10. * @param args command line arguments. */ public static void main(String[] args) { // Create a new deck of cards. Deck deck = new Deck(); // Create two players and assign their names. CardPlayer[] players = new CardPlayer[2]; players[0] = new CardPlayer("Player 1"); players[1] = new CardPlayer("Player 2"); // Create a dealer and assign the players and deck to it. Dealer dealer = new Dealer(players, deck); // Create a new table to place the cards on. CardTable table = new CardTable(); // Set the first player's turn. players[0].setTurn(true); // Print headers for table places. System.out.println(" CardTable Places "); System.out.println("-------------------------"); System.out.println("| p1 | p2 | p3 | p4 |"); System.out.println("-------------------------"); int numItrs = 0; // keep track of how many iterations are played // Play until there's a winner. while (players[0].getHand().size() != 0 && players[1].getHand().size() != 0) {
  • 11. if (players[0].isTurn()) { // Player 1 plays a card. table.addCardToPlace(players[0].play()); table.checkPlaces(players[0]); // Set Player 2's turn. players[1].setTurn(true); } else if (players[1].isTurn()) { // Player 2 plays a card. table.addCardToPlace(players[1].play()); table.checkPlaces(players[1]); // Set Player 1's turn. players[0].setTurn(true); } numItrs++; // update number of iterations counter // Show the cards on the table System.out.printf("| %3d | %3d | %3d | %3d | n", table.getPlaces()[0], table.getPlaces()[1], table.getPlaces()[2], table.getPlaces()[3]); } System.out.println("-------------------------"); System.out.println("End of game. Total #iterations = " + numItrs); // Display each player's bank of cards: for (CardPlayer player : players) { System.out.println(player.bankToString());
  • 12. } // Display the winner of the game: CardPlayer winner = players[0]; for (CardPlayer player : players) { if (player.getPoints() > winner.getPoints()) { winner = player; } } System.out.println("The winner is: " + winner.name + " (Points: " + winner.getPoints() + ")"); } } Codes needed to be completed: CardPlayer.java: /** * A class that represents a card player. * * For each card player instance, we should keep track of how many points * they earned in the game so far, as well as whether it is their turn or not. * Additionally, their hand and bank of cards should be stored in two * separate ArrayLists of Card objects. * * <p> * A player's points, turn, and hand of cards should all be declared * private fields, whereas the bank of cards should be public, as follows: * <p> * <code> * private int points; * * private boolean turn; * * private ArrayList&lt;Card&gt; hand = new ArrayList&lt;Card&gt;(); * * public ArrayList&lt;Card&gt; bank = new ArrayList&lt;Card&gt;();
  • 13. * </code> * <p> * * Note that the Field Summary section below will only show you public fields, * but you must declare all the fields described above in your implementation of this class, * including the private fields. You are free to create additional fields if deemed necessary. * * @param <Card> the type of card used in the game */ // TODO: Create class CardPlayer. CardTable.java : /** * * This class represents a table where a game is being played. * * It implements the Table interface and is designed to work with Card and * CardPlayer objects. * * <p> * Each table instance must keep track of the cards that players place on the table * during the game. The number of places available has a fixed size (<code>NUMBER_OF_PLACES</code>), * so we use a regular Java array to represent a CardTable's places field. * Each entry in this places array contains * the cards that were added to that place, which is a more dynamic structure (we don't know * in advance how many cards will be added to this place!). * <p> * Therefore, each place * entry in this array will reference an ArrayList of Card objects. * <p> * Here is how to declare the array of ArrayLists field <code>places</code>: * * <p> * <code> * private ArrayList&lt;Card&gt;[] places = new ArrayList[NUMBER_OF_PLACES]; * </code> * <p> * * Note that the Field Summary section below will only show you public fields, * but you must declare the required field places described above, which is
  • 14. private. * You are also free to create additional fields in your class implementation, if deemed necessary. * */ // TODO: Complete the implementation of class CardTable below according // to the class documentation described here: // https://www.cs.emory.edu/~nelsay2/cs171_s23/a2/doc/cs171a2/CardTable.html public class CardTable { // TODO: Fix class declaration to implement Table interface (see documentation) // TODO: create all required instance variables (you can add more variables if needed) // TODO: basic, no-argument constructor initializes all table // places to new ArrayLists of Card objects // TODO: implement all required CardTable methods (you can add helper methods if needed) } Requirement: Finish CardPlayer.java and CardTable.java without changing any other given code, to successfully generate a game with Main.java. Game description: In this assignment, you will be implementing a simple game of cards. The game uses a standard 52-card deck; there are four suits and each suit has 13 ranks. For simplicity, we use numbers to identify cards in this sssignment. Thus, we have suits 1,2, 3, and 4, and rarks from 1 to 13 (inclusive). Fach card is identified by its suit number followed by its rank. For example, card 102 refers to the card whose suit is 1 and rank is 02 . Therefore, we can use the simple formula suit*100+rank to produce a card's identifier. Figure - below shows the different entities involved in this game: a dealer who has a deck of cards, two players, and a table with exactly four places where players can place their cards during the game. Each player has a hand of cards that is private to them (i.e., not visible to anyone else), and a bank of cards containing all cards they won during the game (visible to the public). Figure 1: An illustration of the different entities involved in our card game. The game begins with the dealer shuffling the deck then distributing (i.e., dealing) the cards to the two players. The players then take turns in placing their cards on the table, one card a time, starting with place 1 (i.e., places [ 0 ] in our array implementation), followed by place 2, etc., when a player places a card in place 4 , the next player places their card in place 1 , and so on. The top card in each place on the table is visible to everyone. Note: We use the term current place to indicate where the current player can place their card. 1 When a player wants to play a card, there are two possible scenarios: 1. If there is another visible card (in places other than the current place) whose rank is the same as the current player's card rank, then the player takes that card from the table and adds both cards to their bank. One point is added to the player's score. 2. If none of the visible cards (in places other than the current place) have a rank that matches the current player's card rank, then this new card becomes the top card in the current place on the table. No points are added to the player's score. Then, the next player plays a card, and so on. The game continues until both players finish their cards. We then count the number of pairs of matching cards they have collected in their banks, and the winner is the player with more pairs (the most points). If there is a tie, then for simplicity
  • 15. we can consider player 1 to be the winner (after all, this is just a simulation ;-). Sample Game: Below is the output of a sample game (where all the rules are implemented correctly). We print the content of all 4 table places in each iteration, with 1 indicating that no card is placed in that position 2 Player 1 bank has 10 carda: 401 101402 302 109409404204412112 playar 2 bank has 4 carda: 208 308 106206