On 5/28/07, John Randall <[EMAIL PROTECTED]> wrote:
I have verbs which convert between the two representations, but I have
not yet done rotations and reflections.  Any comments or suggestions
would be welcome.

My partial implementation I posted on May 26 dealt with rotations and
reflections.  Here's an extraction of that part of the code:

dirs=:0 2,1 1,1 _1,0 _2,_1 _1,:_1 1
piecedelta=:(0,+/\)"2 dirs{~0 2|:6|(,-)(i.6)+/0,.|:".;._2]0 :0
0 1 0 0 5 0 1 2 0 0
0 2 1 2 0 2 1 1 5 0
1 1 2 1 4 0 5 0 0 2 NB. replace last of 4 with middle of 1
)
piecedelta=: ((<4;a:;4)}~ (<1;a:;2){]) piecedelta

The result -- piecedelta has dimensions 10 12 5 2 where we have
  10 distinct pieces
  12 rotaions and permutations for each piece
  5 hexes occupied by each piece
  2 dimensions for the board (x,y)

The underlying board corresponds to the 1s in 10 10{.10 11$1 0

I believe you should be able to map from my above representation
to whatever representation you want to deal with.

Anyways, my fundamental technique was: arrange so that incrementing
or decrementing a "direction index" (modulo number of directions)
corresponds to rotation.  This allows me to use addition on these
indices to rotate and negation on these indices to reflect.  I then
used +/\ to convert from relative coordinates to a common origin.
One piece was not representable as a simple sequence of pieces,
so for that piece I copied the necessary position from a different
piece.

FYI,

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to