Computers and Technology
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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, ericadawn2852
How do i draw hello world in python and how do i make it loop?
Answers: 1
image
Computers and Technology, 22.06.2019 18:30, smariedegray
All of the following are characteristics that must be contained in any knowledge representation scheme except
Answers: 3
image
Computers and Technology, 23.06.2019 01:30, winstonbendariovvygn
1. which of the following is a search engine? a) mozilla firefox b)internet explorer c)google d)safari 2. which of the following statements is true? a) all search engines will provide the same results when you enter the same query. b) all search engines use the same amount of advertisements. c) some search engines are also browsers. d) search engines often provide different results, even when you enter the same query.
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, taiyana74
Ramona enjoys her job because she is able to kids in an after school program. the work value ramona feels strongest about is a. leadership b. risk c. independence d. work with people select the best answer from the choices provided a b c d
Answers: 1
Do you know the correct answer?
In this assignment, you will model the game of Bulgarian Solitaire. The game starts with 45 cards. (...

Questions in other subjects:

Konu
Biology, 30.06.2019 11:30
Konu
Mathematics, 30.06.2019 11:30