That pattern - selecting some kind of legal moves on a board - is, I think, better solved with a table of indices (one row per board position, one column per direction, use _ for illegal moves). And, for something like othello, you would probably add another dimension so you get each of the relevant pieces. That way, you pre-compute the move table for the board and then have a relatively simple (and relatively fast) per-move mechanism.
Or, at least, that is how I approached that problem when I last implemented something vaguely similar... Thanks, -- Raul On Wed, Feb 17, 2016 at 6:24 PM, Pascal Jasmin <[email protected]> wrote: > The reason I asked, was to make this seemingly useful adverb that lends well > to J patterns. The pattern is applying a verb 8 distinct directions across a > table (rows cols 2 diagonals front and back) > > unoblique =: 4 : ' (;y) (;</.{i.&.> x)} (x $ 0)' > eightdirs =: 1 : '[: |:@:(|."1) $ unoblique [: u&.|. each@:(</.)@:(|."1)@:|: > [: |:@:(|."1) $ unoblique [: u each@:(</.)@:(|."1)@:|: $ unoblique [: u&.|. > each@:(</.) $ unoblique [: u each@:(</.) [: u"1&.|."1 [: u"1&.|."1&.|: [: u"1 > u"1&.|:' > > > An example use is solving legal moves for othello, > > a =. '-OX' i. > cutLF 0 : 0 > -------- > -------- > ---OX--- > --XXXO-- > --XOO--- > ---O---- > -------- > --------) > > legal x moves, > > '-OX_*' {~ 2&(4 : ' (({:y) , 2 {.`4:@.( (0 , 2 1 {~ 2=x)&-:)\ ])^:(x&e.) > y') eightdirs a > -------- > --***--- > --*OX--- > --XXXO*- > --XOO**- > --*O**-- > ---**--- > -------- > > > > legal o moves, > > '-OX_*' {~ 1&(4 : ' (({:y) , 2 {.`4:@.( (0 , 2 1 {~ 2=x)&-:)\ ])^:(x&e.) > y') eightdirs a > -------- > ---**--- > -**OX*-- > -*XXXO-- > -*XOO*-- > ---O---- > -------- > -------- > > 2dirs and 4dirs adverbs are just shorter versions of this that many of us > have likely used without naming the pattern. More complex 3d versions, if > you need them, shouldn't be insanely hard, and useful if you have a verb to > use the pattern. > > > ----- Original Message ----- > From: Roger Hui <[email protected]> > To: Programming forum <[email protected]> > Sent: Wednesday, February 17, 2016 2:48 PM > Subject: Re: [Jprogramming] an inverse to oblique > > Instead of portrait and landscape matrices, I myself use tall and wide > matrices, terminology I first heard used by Eugene McDonnell. > > On Wed, Feb 17, 2016 at 11:18 AM, Mike Day <[email protected]> > wrote: > >> I started with the rectangular case, so have this rather more complicated >> monad: >> >> deo =: 13 : 's$i{;y[ i =. /:;</.i.s =. (((+/(],%)>./)@:(#every)))y' >> >> I was a bit surprised that the result is tacit. >> deo >> (+/ (% , ]) >./)@:(#&>) $ ; {~ [: /: [: ; [: </. [: i. (+/ (] , %) >> >./)@:(#&>) >> >> As Marshall observes, it's not possible to deduce the orientation of >> the rectangle. The verb here assumes a landscape shape. >> >> Unfortunately, the result is wrong if the original was portrait... >> >> eg >> [land =: </.(a.{~97+i.25){~i.3 8 >> +-+--+---+---+---+---+---+---+--+-+ >> |a|bi|cjq|dkr|els|fmt|gnu|hov|pw|x| >> +-+--+---+---+---+---+---+---+--+-+ >> >> [port =: </.(a.{~97+i.25){~i.8 3 >> +-+--+---+---+---+---+---+---+--+-+ >> |a|bd|ceg|fhj|ikm|lnp|oqs|rtv|uw|x| >> +-+--+---+---+---+---+---+---+--+-+ >> >> deo land NB. ok >> abcdefgh >> ijklmnop >> qrstuvwx >> >> deo port NB. !!! >> abcfilor >> dehknqtu >> gjmpsvwx >> >> This dyad allows us to specify landscape or portrait with the >> optional left argument; explicit odd x forces portrait; the default >> is landscape. >> >> deod =: 3 : 0 >> 0 deod y >> : >> s =. (((+/(] (x |.,) %)>./)@:(#every)))y >> i =. /:;</.i.s >> s$i{;y >> ) >> >> deod land >> abcdefgh >> ijklmnop >> qrstuvwx >> >> 1 deod port >> abc >> def >> ghi >> jkl >> mno >> pqr >> stu >> vwx >> >> I've assumed that the input is properly derived from oblique >> boxing of a rectangular array. >> >> Mike >> >> >> >> On 17/02/2016 17:42, Marshall Lochbaum wrote: >> >>> deoblique =: ($:~ [: ((1+i.,i:)>./) #@>) : ([ $ (/:&; </.@:i.)~) >>> >> >> >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >> >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
