Not quite. The rightmost one initially has 6 closed cards and 1 revealed card which can be a king, so you can put 12 more cards on top of it, for a total of 6+13 = 19 cards. So I'd make 7 arrays for 20 cards each, just to be safe. Or just use 52-long arrays for every table slot, that too is an option.
and a pile of up to 24 remaining cards. (You don't need two piles of remaining cards.)
Hm. True, but I'd still probably use two arrays/gap buffer instead of a single array with an index into it.
12 bytes to store lengths,
Eh, you can reserve a zero to be a "no card here" value and use NUL-termination instead; the card ranks start up from 1 (the ace) anyhow.
Also, don't forget to track card orientations: some of them are face down, some of them are face up. I usually do it by using the negative numbers for the cards face down :)
All in all, the whole game state fits into a L1 cache of any processor that even has an on-board cache, which is why card games has been around on pretty much every computer ever made.
Not quite. The rightmost one initially has 6 closed cards and 1 revealed card which can be a king, so you can put 12 more cards on top of it, for a total of 6+13 = 19 cards. So I'd make 7 arrays for 20 cards each, just to be safe. Or just use 52-long arrays for every table slot, that too is an option.
You're right. And I hadn't considered tracking the index of the first revealed card.
Anyway, my point is that you can map out the memory allocation quite easily and it's static and small, so you don't have to worry about malloc and free.
Comments
Not quite. The rightmost one initially has 6 closed cards and 1 revealed card which can be a king, so you can put 12 more cards on top of it, for a total of 6+13 = 19 cards. So I'd make 7 arrays for 20 cards each, just to be safe. Or just use 52-long arrays for every table slot, that too is an option.
Hm. True, but I'd still probably use two arrays/gap buffer instead of a single array with an index into it.
Eh, you can reserve a zero to be a "no card here" value and use NUL-termination instead; the card ranks start up from 1 (the ace) anyhow.
Also, don't forget to track card orientations: some of them are face down, some of them are face up. I usually do it by using the negative numbers for the cards face down :)
All in all, the whole game state fits into a L1 cache of any processor that even has an on-board cache, which is why card games has been around on pretty much every computer ever made.
You're right. And I hadn't considered tracking the index of the first revealed card.
Anyway, my point is that you can map out the memory allocation quite easily and it's static and small, so you don't have to worry about malloc and free.