1. ## Allocation

Hi guys,
I've been with some difficulties on dynamic allocation. I have to code a kind of simplified FreeCell within an array of 60 positions (all 52 cards must be inside it) and I don't know how the stacks can be allocated in a way that the overflow doesn't happen.
Does anybody know how to do it?
Thanks a lot.

2. Originally Posted by freecell help
The game area consists of four home cells, four free cells, and a deck of cards, which is dealt face up in eight columns at the beginning of the game.
Any given card must always be in one of those 16 places (each can be viewed as a list with zero or more cards associated with it).

The free cells are special in that they can only have either 0 or 1 card. All the others can be an arbitrary list of cards.

If you create 52 cards, each with suit, rank, list identity, I don't see why you would need any extra allocations.

All the operations you can do take 'n' (1 or more) cards from the tail of one list and append it to the tail of another list. Again, there is an exception that the home cells can only be appended to. Once you've sent a card home, you can't get it back.

3. Salem,
I really appreciate your help, but my problem is the stacks. How can I put 8 columns, 4 free cells and 4 home cells inside an limited area (60 positions of an array) without overflowing it? I know that there's enough space for the operations, however, I don't know how to implement my logic here. I can't limit the stacks, because each column of FreeCell supports more than 7 cards (for example). My doubt is what can I do to avoid overflowing (first stack's top with second stack's base, for example).
Sorry, I don't have enough experience to do this kinds of code, but I've been asked for it at university and now I have to do it so.
And thanks a lot for your comprehension and help.

4. Why do you think you need to do this in an array with 60 positions - it doesn't seem quite sensible.

An approach where you have a deck of cards and then a set of "places" for the list of cards to be held would be the right solution, I would think.

--
Mats

5. Mats,
these is not my specification. It's professor's.

6. Ok, so whilst the 60-position solution still (despite coming from a professor) doesn't seem like the solution I would prefer, I think you can work something out with it. You don't need more than 52 positions to hold 52 cards, so doing so with 8 more positions seems doable.

--
Mats

7. I don't see what the other 8 would be used for, and still be able to call it a 'card'.

Sure the 4 free cell positions could be implemented as a single card, but the 4 home cells and the 8 files(?) need to be another kind of data structure (an "x" of cards).

Whether "x" is a stack, list, or whatever is entirely up to you.

• Freecell has a finite number of stacks across the screen
• Each stack can have an infinite (theoretically) amount of cards in it.
• The game has finite number of 'free' cells (4)

With this information you should be able to devise some data structures for the game.