Answered step by step
Verified Expert Solution
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 : Implementation
of
Card game
The course of the game is simulated in the beggar man's class. For the facedown deck of cards
closedPilely and closedPile the structure Deque doubleended queue is used in
Contrast to the term deck of cards This data structure can be used as a stack eg with the
Methods addLast and pollLast as well as a queue eg 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 lastin
firstout the cards won in a round will be pushed under the pile and
new cards are removed from above, ie firstin firstout.
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 playRoundin JAVA in a given file, Im 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 Im not getting any further.
public void playRound
Erstellen Sie zwei Stacks fr die whrend der Runde gezogenen Karten
Stack openPile new Stack;
Stack openPile new Stack;
Ziehen Sie die obersten Karten von den verdeckten Stapeln
Card card closedPilepollLast;
Card card closedPilepollLast;
Vergleichen Sie die gezogenen Karten
while card null && card null
Wenn die Karten gleichwertig sind ziehen Sie die nchste Karte
if cardcompareTocard
card closedPilepollLast;
card closedPilepollLast;
else if cardcompareTocard
Wenn die erste Karte kleiner ist, fgen Sie sie dem offenen Stapel des zweiten Spielers hinzu
openPilepushcard;
card closedPilepollLast;
else
Wenn die zweite Karte kleiner ist, fgen Sie sie dem offenen Stapel des ersten Spielers hinzu
openPilepushcard;
card closedPilepollLast;
Am Ende der Runde, wenn einer der Stapel leer ist, setzen Sie den Gewinner
if closedPileisEmpty
winner ;
else if closedPileisEmpty
winner ;
else
Wenn beide Stapel nicht leer sind setzen Sie den Gewinner basierend auf den offenen Stapeln
if openPilesize openPilesize
winner ;
else if openPilesize openPilesize
winner ;
else
Falls beide Stapel gleich gro sind bleibt der Gewinner unbestimmt
winner ;
Sammeln Sie die whrend der Runde gezogenen Karten
closedPileaddAllopenPile;
closedPileaddAllopenPile;
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 cardcompareTocard if the returned number is negative, card has a lower value than card player has won and the won card gets put on card 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 has won and the won cards from player get put on the opened cards flipped over and then put onto the bottom of the pile of the closed pile of player 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 card of the type Ca approx
gives
cardcompareTo card
returns a negative number if the card cardl has a lower value than the card card
a positive number if it has a higher value and if the cards are of the same value
stt te 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 and 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 method of
Card can be issued.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started