Bulgarian Solitaire in Java
<p>I have a project in Java which drives me crazy!
It is based on the Bulgarian Solitaire game.</p>

<p>DESCRIPTION GIVEN</p>

<p>The game of Bulgarian Solitaire uses 45 cards, which need not be playing cards -- even pieces of paper would do. The 45 cards are split into a random number of piles, for example
[15, 15, 3, 6, 3, 1, 2]
where the numbers indicate the number of cards in a pile. On each move of the game, a card is removed from each pile and place into a new pile. For example, in the above game, after one move we would have:
[14, 14, 2, 5, 2, 1, 7]</p>

<p>The game is over when the piles have sizes 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).
Model the game with the class BulgarianSolitaire, where you fill in the methods that are described in the javadoc. Here the output for the first test case:</p>

<p>We start with the following piles: </p>

<p>[1, 3, 3, 3, 5, 6, 7, 8, 9]</p>

<p>[2, 2, 2, 4, 5, 6, 7, 8, 9]</p>

<p>[1, 1, 1, 3, 4, 5, 6, 7, 8, 9]</p>

<p>[2, 3, 4, 5, 6, 7, 8, 10]</p>

<p>[1, 2, 3, 4, 5, 6, 7, 9, 8]</p>

<p>We ended up with: 
[1, 2, 3, 4, 5, 6, 7, 9, 8]</p>

<p>We started with: 
[1, 3, 3, 3, 5, 6, 7, 8, 9]</p>

<p>MY CODE</p>

<pre><code>import java.util.ArrayList ;

/**
   Models the Bulgarian Solitaire game.
 */
public class BulgarianSolitaire
{
    private ArrayList&lt;Integer&gt; piles ;

    /**
       Constructs the game with a given distribution of piles.
       @param list the given distribution of piles.
     */
    public BulgarianSolitaire(ArrayList&lt;Integer&gt; list)
    {
    this.piles = new ArrayList&lt;Integer&gt;(list) ;
    }
    /**
       Makes one move of the game
       @return the list of piles after one move
     */
    public ArrayList&lt;Integer&gt; play()
    {
        //Reminder: do not write or change code outside of the todo regions.
        //----------------------Start here. Do not remove this comment.
        // todo
        // approximate lines of code required: 8
        int newPileCards = 0;
        int i = 0;
        while(i &lt; piles.size()) {
            if(piles.get(i) == 1) piles.remove(i); else {
                piles.set(i, piles.get(i) - 1); i++;
            } newPileCards++;
        }
        piles.add(newPileCards);
        return piles;
        //----------------------End here. Do not remove this comment.
    }
    /**
       Tests if the game is over
       @return true if all of the numbers from 1 to 9 are present
     */
    public boolean isOver()
    {
    //Reminder: do not write or change code outside of the todo regions.
    //----------------------Start here. Do not remove this comment.
    // todo
    // approximate lines of code required: 5
    boolean result = true;
    for(int i = 1; i &lt; piles.size(); i++) {
        if(piles.get(0) != 1 || piles.get(i) != piles.get(i - 1) + 1) {
            result = false; break;
        }
    } return result;
    //----------------------End here. Do not remove this comment.
    }
}
</code></pre>

<p>So it takes an arrayList, goes through play() and then checks if game is over through isOver(). If not over runs play() again.</p>

<p>Both when the input is [1, 3, 3, 3, 5, 6, 7, 8, 9] and [1, 44], my program gives as result [1, 2, 3, 4, 5, 6, 7, 8, 9].</p>

<p>When I try to submit my code, it says it is wrong. I don't know why...
Any help, very much appreciated....</p>
