SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 5 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 01 Nov 2017 My Price 10.00

implement several new player classes that implement

Need help in this java program:

Provided Classes

You are given the following classCard, Player (abstract), BadPlayer (as an example player), DiscardPile, Crazy8Game.

Tasks:

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 goa

 

PlayerStrategies:(make each strategy a class which extend the player class.write the methods in each class.

first create 2 java classes for each strategy RandomPlayer class and MindTheEights class)

 

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.)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<Card> drawPile = new Stack<Card>();
        for(int i=15; i<deck.length; 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<Player> people = new ArrayList<Player>(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);
        
    }
}

Answers

(5)
Status NEW Posted 01 Nov 2017 06:11 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)