simulator (Re: [Icfp04-discuss] three liberal arts)
Tomas G. Rokicki
rokicki at CS.Stanford.EDU
Thu Jun 10 08:59:46 EDT 2004
There's really never any need to index x/y, or to do the +1/-1
odd/even stuff. Just store in each ant a pointer directly to
the appropriate square, and simply use a "shifted" board.
For instance, for 100x100:
cell board[100*(100+1)]
+x is +1
-x is -1
+y left is +100
+y right is +101
-y left is -101
-y right is -100
The guaranteed rocky borders mean you never have to worry about
running off the edge.
This is the standard trick for working with hex board; just pick
two of the three main directions as "orthogonal" (map those to x and
y) and the third is simply the sum of the other two. The six
directions are then (+x), (+y), (+x,+y), and their inverses.
There's no reason memory access should slow you down in the
simulations, since the simulation pretty much should run out of
cache. What will probably slow you down is indirect jumps and
branch mispredictions. Keep these down and you should fly.
-tom
More information about the Icfp04-discuss
mailing list