Here's my start on the Meteor problem.
The Java solution uses too many linked data structures to be transferable
to J.
At the stage of representing the pieces and board (though possibly not
when searching), the requirement that pieces be connected is
superfluous: you just want to record the relative positions of cells.
That's what coordinate systems are for. They also have the advantage
that operations like rotations and reflections can be described by
matrix operations, something J is good at.
I have only just started, however. So far, I have
1. A representation of a piece (an array of shape 5 2).
2. Two representations of positions on the board:
(a) Numbering the squares by i.50.
(b) (Non-rectangular) coordinates.
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.
Best wishes,
John
0 : 0
We use a nonrectangular coordinate system with origin in the top left
corner of the board. The x-axis is horizontal: the y-axis goes
through 0 5 11 16, etc. Then position 1 has coordinates 1 0, position
5 has coordinates 0 1, and position 12 has coordinates 1 2, for
example.
Our primary interest is to represent a single piece on the board as a
50-bit bitvector in a single 64-bit integer.
We represent a piece with a particular orientation as a list with
shape 5 2, in which the rows are the coordinates of the cells. Their
order is unimportant, and only the differences in coordinates are
significant.
)
NB.EG. Blue piece in Fig 1 of the Java article
blue=:5 2 $ 0 0 1 0 2 0 3 0 3 1
0 : 0
We will not have to type them all in, because we will ultimately read
the piece shapes from the winning position.
We want to represent positions on the board as both coordinate pairs
and position integers, so we need to be able to transform between the
two.
First we get coordinates from a position.
)
cfp=:13 : '((5|y)-<.y%10),<. y%5'
C=:cfp"0 i.50
getc=:({&C) :: (_ _"_) "0
0 : 0
Now we want to go the other way. We really just want to invert the
array but it has negative indices in the x-coordinate.
)
assert _4=minx=.<./ {."1 C
assert 9=dx=.>:>./ {."1 I=:C-"1 minx,0
assert 10=dy=.>:>./ {:"1 I
P=:(i.50) (<"1 I) } _ $~ dx,dy
getp=:(P {~ [: < {: ,~ minx-~ {. ) :: (_"_) "1
assert (-:getp@:getc) i.50
assert (-:getc@:getp) C
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm