For quad tree algorithm
((4^depth)-1)/3
For example, with a depth of 3 you get
(64-1)/3 = 21
and if you count three layers, you will get
1 + 4 + 16 = 21
In my implementation, I even divided it into two arrays where the size for all nodes left without attacks is
((4^(depth-1))-1)/3
and leave the nodes
4^(depth-1)
I do these calculations at compile time with a metaprogram for pow and a template argument for depth. So I just allocate my nodes in two arrays.
source share