I’m working on a freeCell homework, there are 8 piles in the tableau (which is an array of Pile objects), and i need go through a loop, and take a card from the deck , and put it into the current tableau pile, then step to the next tableau pile, and back to the first one when it reach 8th tableau pile.
This is my code:
Expand|Select|Wrap|Line Numbers
- newDeck = new Deck(seed);
- while (!(newDeck.numCardsRemaining() == 0)) {
- for (int i = 0; i < 8; i++) {
- tableau[i].put(newDeck.nextCard());
- i = (i + 1) % 8;
- }
- }
.
.
.
Expand|Select|Wrap|Line Numbers
- for(int i=0;i<8;i++){
- int s = i+8;
- System.out.println(s + ":" + " " + tableau[i].toString());
- s++;
- }
Tableau:
8: [DK,H7,D7,HQ,C3,HK,D5,C5,SA,S10,C6,S5,C8]
9: []
10: [D10,S3,S7,D3,H8,H6,C2,CA,CQ,C4,H4,C10,D8]
11: []
12: [SJ,D2,CJ,S9,S2,D4,S4,H9,SK,D9,HA,H3,HJ]
13: []
14: [C7,H5,CK,SQ,H2,D6,C9,DQ,H10,S8,S6,DA,DJ]
15: []
But it should be:
Tableau:
8: [DK,D7,C3,D5,SA,C6,C8]
9: [D10,S7,H8,C2,CQ,H4,D8]
10: [SJ,CJ,S2,S4,SK,HA,HJ]
11: [C7,CK,H2,C9,H10,S6,DJ]
12: [H7,HQ,HK,C5,S10,S5]
13: [S3,D3,H6,CA,C4,C10]
14: [D2,S9,D4,H9,D9,H3]
15: [H5,SQ,D6,DQ,S8,DA]
Any Help will be much appreciated.
Thanks!