simulator (Re: [Icfp04-discuss] three liberal arts)

Alex Shinn foof at synthcode.com
Wed Jun 9 21:34:43 EDT 2004


At Wed, 09 Jun 2004 01:40:14 +0200, Laurent Desnogues wrote:
> 
> Some gain could come by encoding the map as a one-
> dimensional array so that direction selection is
> just loading an offset instead of switching and
> computing x and y.

This is what I did, but it's not quite so simple in a hex map.  On
both a square map and a hex map, moving left/right is an offset of
-/+1, but whereas in the square map moving up/down is -/+N and
diagonals are consistently +/-N+/-1, in a hex map the offset depends
on whether you're in an even or odd row.  If you have to pass and
check the row number, you're probably not gaining much over passing x
and y together.

However, if you artificially expand the column size to some 2^k > N,
then the index of a cell has the k-th bit set iff the cell is in an
even row, so you can quickly determine if you're in an even row just
from the index.

-- 
Alex


More information about the Icfp04-discuss mailing list