If we are doing "real 2048" I am pretty sure that 8 4 4 8 should become 8 8 8 (with a zero on the left or the right, depending on which direction was requested). And, of course, one of the zeros on the resulting board would become a 2...
If I wanted to implement this using an f/ mechanism, I would make the "combined result" be negative (and take the absolute value when I'm randomly placing that new 2). Since existing values will never be negative, this would prevent "overmerging". Thanks, -- Raul On Thu, May 23, 2019 at 2:38 PM 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote: > > to match the left to right processing of 2048, add &.|. adverb to > temporarily reverse list > > f/&.|. 8 4 4 4 8 8 4 > > 8 8 4 16 4 > > > though this doesn't quite match the 2048 rules in: > > f/&.|. 8 4 4 8 > > 8 16 > > result should be > 16 8 > in this case (8 8 8 intermediate merged with the first 2 merged to 16) > > > On Wednesday, May 22, 2019, 7:58:04 p.m. EDT, Raul Miller > <rauldmil...@gmail.com> wrote: > > You need to apply your rank operation to the entire operation for the > second case. > > This might be easier to see if you eliminated some extra, unnecessary code? > > ... > > Actually ... those rank statements don't help you at all - get rid of them. > > Also, your = test should really be (= {.) because your are building a list. > > This does what you said you want: > > f=: , ` ((+{.),}.@])@.(={.) > > And f/"1 is kind of like a 2048 mechanism. Maybe (4 {. f)/"1 is where you > were heading with this? > > Anyways... one problem was that f was adding unwanted leading dimensions on > intermediate results, which made your first and rest do something different > from what you intended. > > I hope this helps, > > -- > Raul > > > > On Wed, May 22, 2019 at 6:41 PM Luca Masini <lmas...@web.de> wrote: > > > Hi, > > > > I'm trying to come out with a few primitives for a 2048-like-game > > operations. > > > > I did the following > > > > first =: {. > > rest =. }. > > f =: ((dyad def 'x,y')"(0 1)`(dyad def '(x + first y) , rest y'"(0 > > 1))@.=) > > > > In words f should do the following > > - if x = first y the reduce it to x+y > > - if x not = first y then give back the sequence x,y > > > > > > The intended use would be, for ex. > > > > f/ 4 4 4 > > 4 8 > > > > f/ 4 4 4 4 > > 8 8 > > > > In the first case it works. > > > > > > In the second case the result is the following: > > > > f/ 4 4 4 4 > > 8 0 > > 4 8 > > > > My idea was > > > > f/ x x x x > > > > is equivalent to > > 4 f 4 f 4 f 4 > > > > then, working right-to-left, 4 = first 4, so it simplify to > > 4 f 4 f 8 > > > > now, 4 is not = first 8, so it should simplify to > > 4 f 4 8 > > > > now, 4 is = first 4 8, so it should simplify to > > 8 8 > > > > > > What could be a way to implement the behavior that I described? > > > > MfG > > > > Luca. > > > > ---------------------------------------------------------------------- > > 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