Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 4 : Implementation of Card game 7 8 9 1 0 The course of the game is simulated in the beggar man's class. For

Task 4: Implementation
of
Card game
78910 The course of the game is simulated in the beggar man's class. For the face-down deck of cards
closedPilely and closedPile2 the structure Deque (double-ended queue) is used (in
Contrast to the term deck of cards). This data structure can be used as a stack (e.g. with the
Methods addLast () and pollLast (), as well as a queue (e.g. with the methods
addLast) and pollfirst () can be used. The reason for using deque is
that both functionalities are required here. When the cards are dealt, the cards are dealt
placed on the face down piles. The last cards dealt are drawn first (last-in
first-out), the cards won in a round will be pushed under the pile and
new cards are removed from above, i.e. first-in, first-out.
The description of the individual methods can be found in the following API and thJAVA programming homework
I need to write a specific method ( public void playRound())in JAVA in a given file, I'm having big troubles and am close to deadline. This is the code that I have to change, I started doing the playRound method via AI, I know that's how its supposed to look like but I'm not getting any further.
public void playRound(){
// Erstellen Sie zwei Stacks fr die whrend der Runde gezogenen Karten
Stack openPile1= new Stack>();
Stack openPile2= new Stack>();
// Ziehen Sie die obersten Karten von den verdeckten Stapeln
Card card1= closedPile1.pollLast();
Card card2= closedPile2.pollLast();
// Vergleichen Sie die gezogenen Karten
while (card1!= null && card2!= null){
// Wenn die Karten gleichwertig sind, ziehen Sie die nchste Karte
if (card1.compareTo(card2)==0){
card1= closedPile1.pollLast();
card2= closedPile2.pollLast();
} else if (card1.compareTo(card2)0){
// Wenn die erste Karte kleiner ist, fgen Sie sie dem offenen Stapel des zweiten Spielers hinzu
openPile2.push(card1);
card1= closedPile1.pollLast();
} else {
// Wenn die zweite Karte kleiner ist, fgen Sie sie dem offenen Stapel des ersten Spielers hinzu
openPile1.push(card2);
card2= closedPile2.pollLast();
}
}
// Am Ende der Runde, wenn einer der Stapel leer ist, setzen Sie den Gewinner
if (closedPile1.isEmpty()){
winner =2;
} else if (closedPile2.isEmpty()){
winner =1;
} else {
// Wenn beide Stapel nicht leer sind, setzen Sie den Gewinner basierend auf den offenen Stapeln
if (openPile1.size()> openPile2.size()){
winner =1;
} else if (openPile1.size() openPile2.size()){
winner =2;
} else {
// Falls beide Stapel gleich gro sind, bleibt der Gewinner unbestimmt
winner =-1;
}
}
// Sammeln Sie die whrend der Runde gezogenen Karten
closedPile1.addAll(openPile1);
closedPile2.addAll(openPile2);
}
what's wrong about this is the logic, you basically have a closed pile and you need to draw the top card of the pile (LIFO) now you compare the drawn card with the drawn card from the other closed pile, and they become your opnened stack, now you compare the cards with card1.compareTo(card2), if the returned number is negative, card1 has a lower value than card2, player 2 has won and the won card1 gets put on card2, they get flipped over and put on the bottom of the closed pile. That's relevant, because in the case that after the compare you get the value zero, both players take another card from the top of the pile. If the value then is positive player 1 has won and the won cards from player 2 get put on the opened cards flipped over and then put onto the bottom of the pile of the closed pile of player 1. As soon as a player is out of cards while drawing or after the end of the round, the other player wins. If both players end up with no cards at the same time its a draw.
This programming task is about simulating the course of the game round by round. Loading
First seek the Card class, which can be a playing card in the game of Skat. The class
implements the Comparable interface. For two objects cardl and card2 of the type Ca approx
gives
card1.compareTo (card2)
returns a negative number if the card cardl has a lower value than the card card2,
a positive number if it has a higher value and 0 if the cards are of the same value
stt, t.e. only differ in color (clubs, spades, hearts, diamonds). A card is placed over the
Calling the constructor
public card (int id)
generated with an input argument id between 0 and 31. The specific assignment of ID to card
is not relevant for the task, but if you are interested it can be opened by executing the main 0 method of
Card can be issued.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

Students also viewed these Databases questions