Skip to main content
deleted 438 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

Or play around with the version that prints the board after each step.

Or play around with the version that prints the board after each step.

deleted 438 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

J, 456 441 441399 bytes

0=[:+./@,@>(@><@(<4|.@|:@4 o@,&4(4|.@|:@4 o@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b)([:(([*0=[:+/@,[*(e.10&l)*(e.11&l)y*w)ur)@(([:><@]><@[([+({:-{.)~/@]*(={.))~&.>/@,~[:<"1@\:~@;o~@;e(]<@<@(l,.4-~[~])"~"{~4+[~+&4)[~])~ur)(4-[)o(o=:|.@|:~&0)(u=.([[*0=[:,+/3[\"1(@,|y*1|.(w=:)e.l&11)*0=p)@]([(]((*-.)+_1|.*)(2=[:r&z&.|.(p*0<[)>.2*(e.10&l)*1|.p)~)([*0=[y=:+/@,(e.10&ll&10)*1|.(e.11&l)*0=p=p=:((0=[:(r=z=:(2*4<3#.|:@,:)/\.)(0<[)+e*@[+e.)oe-.10&ll&10,12&l=:(o#~]el=:#&e@e.~(4+o=4+(e=:1+i.4)(,9&,.5)"0/[&,.)&12))~])(r=:3[\"1(,@,|.@|:~&0))@])&.>/@,~<"0@|.@])

Try it online!Try it online!

It goes quite well as an tacit definition, as we're just working on the matrix itself. It maps the characters to numbers according to the list in level.

Ungolfed:

NB. level=. '.BFRWbfrwiynp' iNB. ([;._2)map 0stored :as 0
NB.base rip....RRR.
NB.13, ......R...R
NB.then biy.B.R.F.R
NB.padded ......R...R
NB.with fin....RRR.
NB.floors )

NB.and packedwalls
map=:4|.@|walls=:@4 rot@,&4(4|.@|:@4 rot@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b
 NB. rotate matrix x times
rot=:|.@|:~&0
 NB. BFRW as numbers
objs=:1 2 3 4
 NB. get all 1x3 fieldslists (possibleof rules)the original and the transposed matrix
rules=:([: ,/ 3 [\"1 (,@,|:))
 NB. BFRWcheck if rule exists, e.g isrule&10 -> things that can be pushed
objs=:1isrule 2=: 3(#&objs@e.~ (4 + objs ,. 5)&,.)
 NB. 10 2 1 0 0 1 1 2 01 0 -> 0 2 2 0 0 2 2 2 0 0
 NB. used for checking which fields can move/get pushed
red=:(2* 4< 3#. |: @ ,:)/\.
 NB. bitmap of thingsplaces that can gobe downwalked into
pass=:((0 = [: red (0<[)*@[ + e.)  objs -. 10&isruleisrule&10 , 12&isruleisrule&12)
 NB. get the objectswin thatplace fulfillcan't abe rule
isrulewalked =:into (objs #~ ]e.~not (4pushable +or objsblocked) (,9&,)"0/[)
 NB. if moving into anwith unpushablea winyou-entity object,that setwalks boarddown to-> 0won
wonpush=: ([ * 0 = [: +/@, (e. 10&isruleisrule&10) * 1 |. (e. 11&isruleisrule&11) * 0 = pass)
 NB. if there is anexists objectentity that is win and you, set board toand 0win?
wonyou =: ([ * 0 = [: +/@, [ * (e. 10&isruleisrule&10) * (e. 11&isruleisrule&11))
 NB. thingscalculate thatwhich willplaces begets movemoved or be pushed down in a step
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. 10&isruleisrule&10) * 1 |. pass)~
 NB. applyactually shiftsmove ondown matrixentities
move_down=:(][ ((*-.)+_1 |.  *) shifts)
 NB. findget all `rib`rules etc.of andthe replaceform in(objs alphabeticalis orderobjs), sort them, replace them
replace=: ([: > <@]<@[ ([ + ({: - {.)~/@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (] <@(isrule ,. 4-~[~])~"_ 0~"{~ (4+[)+&4)~ [])
 NB. gather rules, rotate matrix byso leftmovement handgoes sidedown,
NB. (with unrotated rules) check for wonpush, move down, rotate back,
NB. replace and, check wonyou
step=move=: ([: (] wonyou rules)@(rules replace ]rules) (4-[) |.@|:~&0rot rules@]rot ([wonpush move_down wonpush~]) |.@|:~&0rules@] )
 NB. pack map andappend moves intoto athe listmatrix thatand getsreduce reducedfrom right to left: with move,
 NB. e.g. 1 step 2 step0 2move step1 stepmove 0 stepmove mapwalls
sim2=: (<@map<@walls step&move&.>/@,~ <"0@|.@])
 NB. check if the board was set toafter 0everything (sois itfinished, isdoes acontain winningmatrix state)
sim=:only (0? =if [:yes +./@,@>-> sim2)won

It goes quite well as an tacit definition, as we're just working on the matrix itself. It maps the characters to numbers according to the list in level. Only the rule checking (the multiple (e.10&isrule)) might be worth going for an explicit definition / having the matrix as a global.

replace is probably more complicated then it has to be, as the order in step with the similar checks wonpush and wonyou. Because of this the dense function is not golfed much further, just variables replaced with their definitions and spaces removed. :-)

J, 456 441 bytes

0=[:+./@,@>((<4|.@|:@,&4(4|.@|:@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b)([:(([*0=[:+/@,[*(e.10&l)*(e.11&l))u)@(([:><@]([+({:-{.)@]*(={.))~&.>/@,~[:<"1@\:~@;o(]<@(l,.4-~[)"{~4+[)[)~u)(4-[)|.@|:~&0(u=.([:,/3[\"1(,|:)))@]([(]((*-.)+_1|.*)(2=[:r&.|.(p*0<[)>.2*(e.10&l)*1|.p)~)([*0=[:+/@,(e.10&l)*1|.(e.11&l)*0=p=:((0=[:(r=:(2*4<3#.|:@,:)/\.)(0<[)+e.)o-.10&l,12&l=:(o#~]e.~(4+o=:1+i.4)(,9&,)"0/[)))~)|.@|:~&0)&.>/@,~<"0@|.@])

Try it online!

Ungolfed:

NB. level=. '.BFRWbfrwiynp' i. ([;._2) 0 : 0
NB. rip....RRR.
NB. ......R...R
NB. biy.B.R.F.R
NB. ......R...R
NB. fin....RRR.
NB. )

NB. packed
map=:4|.@|:@,&4(4|.@|:@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b
NB. get all 1x3 fields (possible rules)
rules=:([: ,/ 3 [\"1 (,|:))
NB. BFRW
objs=:1 2 3 4
NB. 1 2 1 0 0 2 0 0 -> 0 2 2 0 0 2 0 0
red=:(2* 4< 3#. |: @ ,:)/\.
NB. bitmap of things that can go down
pass=:((0 = [: red (0<[) + e.)  objs -. 10&isrule , 12&isrule)
NB. get the objects that fulfill a rule
isrule =: (objs #~ ]e.~ (4 + objs) (,9&,)"0/[)
NB. if moving into an unpushable win object, set board to 0
wonpush=: ([ * 0 = [: +/@, (e. 10&isrule) * 1 |. (e. 11&isrule) * 0 = pass)
NB. if there is an object that is win and you, set board to 0
wonyou =: ([ * 0 = [: +/@, [ * (e. 10&isrule) * (e. 11&isrule))
NB. things that will be move or be pushed down
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. 10&isrule) * 1 |. pass)~
NB. apply shifts on matrix
move_down=:(] ((*-.)+_1 |.  *) shifts)
NB. find all `rib` etc. and replace in alphabetical order
replace=: ([: > <@] ([ + ({: - {.)@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (] <@(isrule ,. 4-~[)~"_ 0 (4+[)) [)
NB. gather rules, rotate matrix by left hand side,
NB. (with unrotated rules) check for wonpush, move down, rotate back,
NB. replace and check wonyou
step=: ([: (] wonyou rules)@(rules replace ]) (4-[) |.@|:~&0 rules@] ([ move_down wonpush~) |.@|:~&0 )
NB. pack map and moves into a list that gets reduced right to left:
NB. e.g. 1 step 2 step 2 step step 0 step map
sim2=: (<@map step&.>/@,~ <"0@|.@])
NB. check if the board was set to 0 (so it is a winning state)
sim=: (0 = [: +./@,@> sim2)

It goes quite well as an tacit definition, as we're just working on the matrix itself. It maps the characters to numbers according to the list in level. Only the rule checking (the multiple (e.10&isrule)) might be worth going for an explicit definition / having the matrix as a global.

replace is probably more complicated then it has to be, as the order in step with the similar checks wonpush and wonyou. Because of this the dense function is not golfed much further, just variables replaced with their definitions and spaces removed. :-)

J, 456 441 399 bytes

0=[:+./@,@><@(4 o@,&4(4 o@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b)([:(([*0=[:+/@,y*w)r)@(([:><@[([+-~/@]*(={.))~&.>/@,~[:<"1@\:~@;e(<@(l,.4-~])~"{~+&4)~])r)(4-[)o(o=:|.@|:~&0)(([*0=[:+/@,y*1|.(w=:e.l&11)*0=p)([((*-.)+_1|.*)2=[:z&.|.(p*0<[)>.2*(y=:e.l&10)*1|.p=:((0=[:(z=:(2*4<3#.|:@,:)/\.)*@[+e.)e-.l&10,(l=:#&e@e.~(4+(e=:1+i.4),.5)&,.)&12))])(r=:3[\"1(,@,|:))@])&.>/@,~<"0@|.@]

Try it online!

It goes quite well as an tacit definition, as we're just working on the matrix itself. It maps the characters to numbers according to the list in level.

Ungolfed:

 NB. map stored as base 13, then padded with floors and walls
walls=:4 rot@,&4(4 rot@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b
 NB. rotate matrix x times
rot=:|.@|:~&0
 NB. BFRW as numbers
objs=:1 2 3 4
 NB. get all 1x3 lists of the original and the transposed matrix
rules=:(3 [\"1 (,@,|:))
 NB. check if rule exists, e.g isrule&10 -> things that can be pushed
isrule =: (#&objs@e.~ (4 + objs ,. 5)&,.)
 NB. 0 2 0 0 1 1 2 1 0 -> 0 2 0 0 2 2 2 0 0
 NB. used for checking which fields can move/get pushed
red=:(2* 4< 3#. |: @ ,:)/\.
 NB. places that can be walked into
pass=:((0 = [: red *@[ + e.)  objs -. isrule&10 , isrule&12)
 NB. win place can't be walked into (not pushable or blocked),
 NB. with a you-entity that walks down -> won
wonpush=: ([ * 0 = [: +/@, (e. isrule&10) * 1 |. (e. isrule&11) * 0 = pass)
 NB. exists entity that is you and win?
wonyou =: ([ * 0 = [: +/@, (e. isrule&10) * (e. isrule&11))
 NB. calculate which places gets moved or pushed down in a step
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. isrule&10) * 1 |. pass)
 NB. actually move down entities
move_down=:([ ((*-.)+_1 |.  *) shifts)
 NB. get all rules of the form (objs is objs), sort them, replace them
replace=: ([: > <@[ ([ + -~/@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (<@(isrule ,. 4-~])~"{~ +&4)~ ])
 NB. rotate so movement goes down, check wonpush, move down, rotate back, replace, check wonyou
move=: ([: (wonyou rules)@(replace rules) (4-[) rot rot (wonpush move_down ]) rules@] )
 NB. append moves to the matrix and reduce from right to left with move,
 NB. e.g. 0 move 1 move 0 move walls
sim2=: (<@walls move&.>/@,~ <"0@|.@])
 NB. after everything is finished, does contain matrix only 0? if yes -> won
added 1153 characters in body
Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39

J, 456456 441 bytes

0=[:+./@,@>((<4&,@|:@|<4|.^:4(0&,@|:@|@,&4(4|.^@|:4@,&0])(5 3$13#13#.inv 30567092372354562),.536bdnnshw5d 8$4648796544822946234620x#:~40#485686 36ba491bbil 85686 36bbvydg17b)([:(([*0=[:+/@,[*(e.10&l)*(e.11&l))u)@(([:><@]([+({:-{.)@]*(={.))~&.>/@,~[:<"1@\:~@;o(]<@(l,.4-~[)"{~4+[)[)~u)(4-[)|.@|:~&0(u=.([:,/3[\"1(,|:)))@]([(]((*-.)+_1|.*)(2=[:r&.|.(p*0<[)>.2*(e.10&l)*1|.p)~)([*0=[:+/@,(e.10&l)*1|.(e.11&l)*0=p=:((0=[:(r=:(2*4<3#.|:@,:)/\.)(0<[)+e.)o-.10&l,12&l=:(o#~]e.~(4+o=:1+i.4)(,9&,)"0/[)))~)|.@|:~&0)&.>/@,~<"0@|.@])

Try it online!Try it online!

NB. level=. '.BFRWbfrwiynp' i. ([;._2) 0 : 0
NB. rip....RRR.
NB. ......R...R
NB. biy.B.R.F.R
NB. ......R...R
NB. fin....RRR.
NB. )

NB. packed
map=:4&,@|:@|4|.^:4 (0&,@|:@|@,&4(4|.^@|:4@,&0]) (5 3$13#13#.inv 30567092372354562),.536bdnnshw5d 8$4648796544822946234620x#:~40#485686 36ba491bbil 85686 36bbvydg17b
NB. get all 1x3 fields (possible rules)
rules=:([: ,/ 3 [\"1 (,|:))
NB. BFRW
objs=:1 2 3 4
NB. 1 2 1 0 0 2 0 0 -> 0 2 2 0 0 2 0 0
red=:(2* 4< 3#. |: @ ,:)/\.
NB. bitmap of things that can go down
pass=:((0 = [: red (0<[) + e.)  objs -. 10&isrule , 12&isrule)
NB. get the objects that fulfill a rule
isrule =: (objs #~ ]e.~ (4 + objs) (,9&,)"0/[)
NB. if moving into an unpushable win object, set board to 0
wonpush=: ([ * 0 = [: +/@, (e. 10&isrule) * 1 |. (e. 11&isrule) * 0 = pass)
NB. if there is an object that is win and you, set board to 0
wonyou =: ([ * 0 = [: +/@, [ * (e. 10&isrule) * (e. 11&isrule))
NB. things that will be move or be pushed down
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. 10&isrule) * 1 |. pass)~
NB. apply shifts on matrix
move_down=:(] ((*-.)+_1 |.  *) shifts)
NB. find all `rib` etc. and replace in alphabetical order
replace=: ([: > <@] ([ + ({: - {.)@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (] <@(isrule ,. 4-~[)~"_ 0 (4+[)) [)
NB. gather rules, rotate matrix by left hand side,
NB. (with unrotated rules) check for wonpush, move down, rotate back,
NB. replace and check wonyou
step=: ([: (] wonyou rules)@(rules replace ]) (4-[) |.@|:~&0 rules@] ([ move_down wonpush~) |.@|:~&0 )
NB. pack map and moves into a list that gets reduced right to left:
NB. e.g. 1 step 2 step 2 step step 0 step map
sim2=: (<@map step&.>/@,~ <"0@|.@])
NB. check if the board was set to 0 (so it is a winning state)
sim=: (0 = [: +./@,@> sim2)

I'm not yet satisfied with the map-packing (left side base 13, right side base 4, then padded with ., then with walls). Also replace is probably more complicated then it has to be, as the order in step with the similar checks wonpush and wonyou. Because of this the dense function is not golfed much further, just variables replaced with their definitions and spaces removed. :-)

J, 456 bytes

0=[:+./@,@>((<4&,@|:@|.^:4(0&,@|:@|.^:4)(5 3$13#.inv 30567092372354562),.5 8$4648796544822946234620x#:~40#4)([:(([*0=[:+/@,[*(e.10&l)*(e.11&l))u)@(([:><@]([+({:-{.)@]*(={.))~&.>/@,~[:<"1@\:~@;o(]<@(l,.4-~[)"{~4+[)[)~u)(4-[)|.@|:~&0(u=.([:,/3[\"1(,|:)))@]([(]((*-.)+_1|.*)(2=[:r&.|.(p*0<[)>.2*(e.10&l)*1|.p)~)([*0=[:+/@,(e.10&l)*1|.(e.11&l)*0=p=:((0=[:(r=:(2*4<3#.|:@,:)/\.)(0<[)+e.)o-.10&l,12&l=:(o#~]e.~(4+o=:1+i.4)(,9&,)"0/[)))~)|.@|:~&0)&.>/@,~<"0@|.@])

Try it online!

NB. level=. '.BFRWbfrwiynp' i. ([;._2) 0 : 0
NB. rip....RRR.
NB. ......R...R
NB. biy.B.R.F.R
NB. ......R...R
NB. fin....RRR.
NB. )

NB. packed
map=:4&,@|:@|.^:4 (0&,@|:@|.^:4) (5 3$13#.inv 30567092372354562),.5 8$4648796544822946234620x#:~40#4
NB. get all 1x3 fields (possible rules)
rules=:([: ,/ 3 [\"1 (,|:))
NB. BFRW
objs=:1 2 3 4
NB. 1 2 1 0 0 2 0 0 -> 0 2 2 0 0 2 0 0
red=:(2* 4< 3#. |: @ ,:)/\.
NB. bitmap of things that can go down
pass=:((0 = [: red (0<[) + e.)  objs -. 10&isrule , 12&isrule)
NB. get the objects that fulfill a rule
isrule =: (objs #~ ]e.~ (4 + objs) (,9&,)"0/[)
NB. if moving into an unpushable win object, set board to 0
wonpush=: ([ * 0 = [: +/@, (e. 10&isrule) * 1 |. (e. 11&isrule) * 0 = pass)
NB. if there is an object that is win and you, set board to 0
wonyou =: ([ * 0 = [: +/@, [ * (e. 10&isrule) * (e. 11&isrule))
NB. things that will be move or be pushed down
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. 10&isrule) * 1 |. pass)~
NB. apply shifts on matrix
move_down=:(] ((*-.)+_1 |.  *) shifts)
NB. find all `rib` etc. and replace in alphabetical order
replace=: ([: > <@] ([ + ({: - {.)@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (] <@(isrule ,. 4-~[)~"_ 0 (4+[)) [)
NB. gather rules, rotate matrix by left hand side,
NB. (with unrotated rules) check for wonpush, move down, rotate back,
NB. replace and check wonyou
step=: ([: (] wonyou rules)@(rules replace ]) (4-[) |.@|:~&0 rules@] ([ move_down wonpush~) |.@|:~&0 )
NB. pack map and moves into a list that gets reduced right to left:
NB. e.g. 1 step 2 step 2 step step 0 step map
sim2=: (<@map step&.>/@,~ <"0@|.@])
NB. check if the board was set to 0 (so it is a winning state)
sim=: (0 = [: +./@,@> sim2)

I'm not yet satisfied with the map-packing (left side base 13, right side base 4, then padded with ., then with walls). Also replace is probably more complicated then it has to be, as the order in step with the similar checks wonpush and wonyou. Because of this the dense function is not golfed much further, just variables replaced with their definitions and spaces removed. :-)

J, 456 441 bytes

0=[:+./@,@>((<4|.@|:@,&4(4|.@|:@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b)([:(([*0=[:+/@,[*(e.10&l)*(e.11&l))u)@(([:><@]([+({:-{.)@]*(={.))~&.>/@,~[:<"1@\:~@;o(]<@(l,.4-~[)"{~4+[)[)~u)(4-[)|.@|:~&0(u=.([:,/3[\"1(,|:)))@]([(]((*-.)+_1|.*)(2=[:r&.|.(p*0<[)>.2*(e.10&l)*1|.p)~)([*0=[:+/@,(e.10&l)*1|.(e.11&l)*0=p=:((0=[:(r=:(2*4<3#.|:@,:)/\.)(0<[)+e.)o-.10&l,12&l=:(o#~]e.~(4+o=:1+i.4)(,9&,)"0/[)))~)|.@|:~&0)&.>/@,~<"0@|.@])

Try it online!

NB. level=. '.BFRWbfrwiynp' i. ([;._2) 0 : 0
NB. rip....RRR.
NB. ......R...R
NB. biy.B.R.F.R
NB. ......R...R
NB. fin....RRR.
NB. )

NB. packed
map=:4|.@|:@,&4(4|.@|:@,&0])13#.inv 36bdnnshw5d 85686 36ba491bbil 85686 36bbvydg17b
NB. get all 1x3 fields (possible rules)
rules=:([: ,/ 3 [\"1 (,|:))
NB. BFRW
objs=:1 2 3 4
NB. 1 2 1 0 0 2 0 0 -> 0 2 2 0 0 2 0 0
red=:(2* 4< 3#. |: @ ,:)/\.
NB. bitmap of things that can go down
pass=:((0 = [: red (0<[) + e.)  objs -. 10&isrule , 12&isrule)
NB. get the objects that fulfill a rule
isrule =: (objs #~ ]e.~ (4 + objs) (,9&,)"0/[)
NB. if moving into an unpushable win object, set board to 0
wonpush=: ([ * 0 = [: +/@, (e. 10&isrule) * 1 |. (e. 11&isrule) * 0 = pass)
NB. if there is an object that is win and you, set board to 0
wonyou =: ([ * 0 = [: +/@, [ * (e. 10&isrule) * (e. 11&isrule))
NB. things that will be move or be pushed down
shifts=:( 2 = [: red&.|. (  pass * 0 < [) >. 2 * (e. 10&isrule) * 1 |. pass)~
NB. apply shifts on matrix
move_down=:(] ((*-.)+_1 |.  *) shifts)
NB. find all `rib` etc. and replace in alphabetical order
replace=: ([: > <@] ([ + ({: - {.)@] * (={.))~&.>/@,~ [: <"1@\:~@; objs (] <@(isrule ,. 4-~[)~"_ 0 (4+[)) [)
NB. gather rules, rotate matrix by left hand side,
NB. (with unrotated rules) check for wonpush, move down, rotate back,
NB. replace and check wonyou
step=: ([: (] wonyou rules)@(rules replace ]) (4-[) |.@|:~&0 rules@] ([ move_down wonpush~) |.@|:~&0 )
NB. pack map and moves into a list that gets reduced right to left:
NB. e.g. 1 step 2 step 2 step step 0 step map
sim2=: (<@map step&.>/@,~ <"0@|.@])
NB. check if the board was set to 0 (so it is a winning state)
sim=: (0 = [: +./@,@> sim2)

replace is probably more complicated then it has to be, as the order in step with the similar checks wonpush and wonyou. Because of this the dense function is not golfed much further, just variables replaced with their definitions and spaces removed. :-)

Source Link
xash
  • 11.3k
  • 1
  • 14
  • 39
Loading