Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given files: // Abstract class Player I\'m not even sure where to start with the

ID: 3919064 • Letter: G

Question

Given files:

// Abstract class Player

I'm not even sure where to start with the CrazyEightsPlayer subclass. Any suggestions would be really appreciated!

Thank you.

4: Crazy Eights Consider the provided abstract Player class. You will create a new class called CrazyEightsPlayer that is a subclass the Player class The crazy eights player class simulates a valid player of the game crazy eights. The rules foir our version of Crazy Eights is as follows 1. The game starts with each player being given some number of cards from the deck. 2. A single card is taken from the deck and placed on top of the discard pile (and is visible to 3. A player's turn consists of taking zero or more cards from the deck (adding them to their 4. A player can always play a card from their hand that has the same rank as the top card in 5. A player can always play a card from their hand that has the same suit as the top card in the player) hand) and then playing a card on the top of the discard pile (removing it from their hand) the discard pile. the discard pile. 6. A player can always play a card with rank 8. When a player plays an 8, they are allowed to change the suit of the card to any of the four suits of their choosing. (You will do this by removing the eight from your hand and then returning a new Card object with the desired suit 7. A player is allowed to (repeatedly) take a card from the deck before playing a card to the discard pile. You must play a card if you are able to. If the deck runs out of cards, the game ends 8. The player that discards all their cards first is the winner. If the deck is exhausted before any player can play all their cards then there is no winner Note: You are NOT implementing a crazy eights game. You are building the classes that would be needed for such a game. You are building the model for the game Note: Your player should NOT cheat in their play method. When we test your player we will expect no cheating

Explanation / Answer

here is your class : ---------------->>>>>>>>>

import java.util.ArrayList;

public class CrazyEightsPlayer extends Player{
public CrazyEightsPlayer(Hand hand){
  super(hand);
}

public Card play(Card top_of_discard_pile,Deck deck){
  //getting cards from the hand
  ArrayList<Card> cards = hand.getCards();
  //checking the hand cards has same suit or same rank or it has the rank 8 card
  for(int i = 0;i<cards.size();i++){
   //here we check for same suit as the top_discard_pile
   if(cards.get(i).getSuit().equals(top_of_discard_pile.getSuit())){
    hand.remove(cards.get(i));
    return cards.get(i);//returning the card
   }
   //here we check for same rank as the top_discard_pile
   if(cards.get(i).getRank() == top_of_discard_pile.getRank()){
    hand.remove(cards.get(i));
    return cards.get(i);//returning the card
   }
   //here we check for card has rank = 8
   if(cards.get(i).getRank() == 8){
    hand.remove(cards.get(i));
    //making a new card with rank 8 and the suit of discard pile
    return new StandardCard(8,top_of_discard_pile.getSuit());
   }
  }
  Card card = null;//we make card local variable to get card from deck
  //below we loop until the deck is empty
  while((card = deck.getCard()) != null){
   hand.add(card);
   for(int i = 0;i<cards.size();i++){
    //here we check for same suit as the top_discard_pile
    if(cards.get(i).getSuit().equals(top_of_discard_pile.getSuit())){
     hand.remove(cards.get(i));
     return cards.get(i);//returning the card
    }
    //here we check for same rank as the top_discard_pile
    if(cards.get(i).getRank() == top_of_discard_pile.getRank()){
     hand.remove(cards.get(i));
     return cards.get(i);//returning the card
    }
    //here we check for card has rank = 8
    if(cards.get(i).getRank() == 8){
     hand.remove(cards.get(i));
     //making a new card with rank 8 and the suit of discard pile
     return new StandardCard(8,top_of_discard_pile.getSuit());
    }
   }
  }

  return null;//returning null because no move to take
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote