previous | start | next

Example B: Concentrate calculations (especially bit math) in lower level classes.

 Agents keep track of the world by strings of  bits (actually, "trits"), as in [01 10 00 10 01 10 01 10].
 To save memory, this is packed into a 16 bit integer, and the 0's and 1's are manipulated with bit math.

Usage example:

 myworld[WORD(i)] |= realworld[n] << SHIFT[i];


    This accesses the i'th "trit" in a larger sequence, and adjust it, using a SHIFT macro which is defined elsewhere.

Within the plain C approach, this was necessary because there was no object to whom one could delegate the bit math.
 



previous | start | next