array Loop, help please !

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limpor
    New Member
    • May 2006
    • 5

    #1

    array Loop, help please !

    Hi there,

    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:
    Code:
            newDeck = new Deck(seed);
            while (!(newDeck.numCardsRemaining() == 0)) {
                for (int i = 0; i < 8; i++) {
                    tableau[i].put(newDeck.nextCard()); 
                    i = (i + 1) % 8;
                }
            }
    .
    .
    .
    .
    Code:
            for(int i=0;i<8;i++){
                int s = i+8;
                System.out.println(s + ":" + " " + tableau[i].toString());
                s++;
            }
    This gives me:

    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!
  • Limpor
    New Member
    • May 2006
    • 5

    #2
    Never mind i figrued it out now.

    Comment

    Working...