subject
Computers and Technology, 03.03.2020 04:52 JBBunny

In this assignment, you will model the game of Bulgarian Solitaire. The game starts with 45 cards. (They need not be playing cards. Unmarked index cards work just as well.) Randomly divide them into some number of piles of random size. For example, you might start with piles of size 20, 5, 1, 9, and 10. In each round, you take one card from each pile, forming a new pile with these cards. For example, the sample starting configuration would be transformed into piles of size 19, 4, 8, 10, and 5. The solitaire is over when the piles have size 1, 2, 3, 4, 5, 6, 7, 8, and 9, in some order. (It can be shown that you always end up with such a configuration.)

In your program, produce a random starting configuration and print it. Then keep applying the solitaire step and print the result. Stop when the solitaire final configuration is reached.

Use the following class as your main class:

import java. util. ArrayList;
import java. util. Random;

public class BulgarianSolitaire
{
private ArrayList piles;

/**
Sets up the game randomly with some number of piles of random
size. The pile sizes add up to 45.
*/
public void setupRandomly()
{
. . .
}

/**
This method can be used to set up a pile with a known (non-random)
configuration for testing.
@param pileSizes an array of numbers whose sum is 45
*/
public void setup(int[] pileSizes)
{
piles = new ArrayList();
for (int s : pileSizes)
piles. add(s);
}

public String getPiles()
{
return piles. toString();
}

/**
Play the game.
*/
public void play()
{
while (!isDone())
{
System. out. println(getPiles());
playRound();
}
System. out. println(getPiles());
}

/**
Play one round of the game.
*/
public void playRound()
{
. . .
}

/**
Checks whether the game is done.
@return true when the piles have size
1, 2, 3, 4, 5, 6, 7, 8, and 9, in some order.
*/
public boolean isDone()
{
. . .
}
}

Sample run:

13 4 6 6 10 6

6 12 3 5 5 9 5

7 5 11 2 4 4 8 4

8 6 4 10 1 3 3 7 3

9 7 5 3 9 2 2 6 2

9 8 6 4 2 8 1 1 5 1

10 8 7 5 3 1 7 4

8 9 7 6 4 2 6 3

8 7 8 6 5 3 1 5 2

9 7 6 7 5 4 2 4 1

9 8 6 5 6 4 3 1 3

9 8 7 5 4 5 3 2 2

9 8 7 6 4 3 4 2 1 1

……….

9 8 7 6 4 5 3 2 1

9 8 7 6 5 3 4 2 1

9 8 7 6 5 4 2 3 1

9 8 7 6 5 4 3 1 2

9 8 7 6 5 4 3 2 1

Number of iterations: 52

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 06:30
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
question
Computers and Technology, 24.06.2019 00:10
Read each statement below. if the statement describes a peer-to-peer network, put a p next to it. if the statement describes a server-based network, put an s next to it. p - peer-to-peer s - server-based
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
Universal windows platform is designed for which windows 10 version?
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
In excel, what happens to the cell contents when you click and drag a cell into multiple cells?
Answers: 1
You know the right answer?
In this assignment, you will model the game of Bulgarian Solitaire. The game starts with 45 cards. (...
Questions
question
Advanced Placement (AP), 29.04.2021 02:30
question
Mathematics, 29.04.2021 02:30
question
Mathematics, 29.04.2021 02:30
question
Mathematics, 29.04.2021 02:30
question
Mathematics, 29.04.2021 02:30
Questions on the website: 13722363