Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write java classes for each strategy below.for the game to play make a new instant of each class in the Crazy8Game given at the end:

write java classes for each strategy below.for the game to play make a new instant of each class in the Crazy8Game given at the end:

Your Tasks

You will implement several new player classes that implement different strategies for players and modify Crazy8s to visualize game play. You must ensure that the games are played properly. You may modify any of the provided classes.

Game Play

You must ensure that a proper game of crazy 8's is played. This means that all played cards (cards added to the discard pile) are valid. At the end of a game, points should be awarded to the winning player.

There should be choice for 2,3 or 4 player games and whether or not it is a single game play or multiple game (with a set points goal).

Player Strategies : make each strategy a class which extends the player class. add alot of comment to explain your work.

RandomPlayer should play a random valid card.

MindTheEights should always be aware of any eights they are holding. This player will their eights until late in the game, but won't hold on to them too long (as they are worth a lot of points). Once any opponent goes down to one card, it's time to play your eight. If you have two eights, start playing them once an opponent goes down to two cards. (Expand this for 3 or 4 or more eights.)

HamperLeader will try to hamper the progress of the leader if the leader is either the next or previous player. If the next player is the leader (least amount of cards) then this player will try to hamper their progress by playing a power card. If the previous player is the leader, this player will hold on to their power cards until the direction of play is reversed and then hamper them (if this player has a seven they will change direction so that they can try to hamper the leader).

DiscardHighPoints will try to discard their highest point cards as soon as they can. This strategy aims to prevent the winner of a game (if is a different player) from obtaining too many points. This player will try to change suits whenever possible to a different suit if they have high point cards of that different suit.

ExtraCards will risk taking cards from the draw pile in an effort to get power cards. They will be clever with this though. If the next player only has 1 card left, they will keep picking a card until they get a power card (if they do not already have one) so that they can try to prevent the next player from winning. They will not take more than one extra card in the early rounds of the game. They will not take extra cards if they already have power cards in their hand.

Five player teams: MemoryPlayer will analyze the full discard pile at each turn and make decisions based on cards played by every player. A MemoryPlayer player is not allowed to use the instanceof method to check which kind of player each player is. This player should simulate a clever player who remembers each card played by each player during the game.

crazy 8 rules :https://www.thespruce.com/crazy-eights-rules-card-game-411132

crazy8Game code:

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Stack;
import java.util.Random;
public class Crazy8Game{
public static void main(String[] args){
/* create the deck */
Card[] deck = new Card[52];
int index = 0;
for(int r=2; r<=14; r+=1){
for(int s=0; s<4; s+=1){
deck[index++] = new Card(Card.SUITS[s], Card.RANKS[r]);
}
}
/* shuffle the deck */
Random rnd = new Random();
Card swap;
for(int i = deck.length-1; i>=0; i=i-1){
int pos = rnd.nextInt(i+1);
swap = deck[pos];
deck[pos] = deck[i];
deck[i] = swap;
}
/* players in the game */
Player[] players = new Player[3];
players[0] = new BadPlayer( Arrays.copyOfRange(deck, 0, 5) );
System.out.println("0 : " + Arrays.toString( Arrays.copyOfRange(deck, 0, 5)));
players[1] = new BadPlayer( Arrays.copyOfRange(deck, 5, 10) );
System.out.println("0 : " + Arrays.toString( Arrays.copyOfRange(deck, 5, 10)));
players[2] = new BadPlayer( Arrays.copyOfRange(deck, 10, 15) );
System.out.println("0 : " + Arrays.toString( Arrays.copyOfRange(deck, 10, 15)));
/* discard and draw piles */
DiscardPile discardPile = new DiscardPile();
Stack drawPile = new Stack();
for(int i=15; i
drawPile.push(deck[i]);
}
System.out.println("draw pile is : " + Arrays.toString( Arrays.copyOfRange(deck, 15, deck.length) ));
deck = null;
boolean win = false;
int player = -1; // start game play with player 0
ArrayList people = new ArrayList(Arrays.asList(players));
discardPile.add( drawPile.pop() );
while( !win ){
player = (player + 1) % players.length;
System.out.println("player " + player);
System.out.println("draw pile : " + drawPile.peek() );
System.out.println("discard pile : " + discardPile.top() );
win = people.get(player).play(discardPile, drawPile, people);
System.out.println("draw pile : " + drawPile.peek() );
System.out.println("discard pile : " + discardPile.top() );
}
System.out.println("winner is player " + player);
}
}

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

Students also viewed these Databases questions

Question

What are the limits of the production-line approach to services?

Answered: 1 week ago

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

Identify five strategies to prevent workplace bullying.

Answered: 1 week ago