chiark / gitweb /
22b: move padding into Main and pad much more
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 4 Jun 2024 13:41:34 +0000 (14:41 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 4 Jun 2024 13:41:34 +0000 (14:41 +0100)
I'm going to want a whole face's worth of padding all round, and at the
moment only Main knows how big the faces are.

22/22b.bqn

index e63865d4daac44b8673d9cf335e86a26149cb69a..ce191a896943a11425d3c6b3aed5ff7e7b2fd9ff 100644 (file)
@@ -1,5 +1,4 @@
-Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »˘»(2+w)↑˘(2+h)↑𝕩 }
-PrepMap←{ Pad >(⌈´≠¨𝕩)⊸↑¨𝕩 }
+PrepMap←{ >(⌈´≠¨𝕩)⊸↑¨𝕩 }
 PrepStep←{ 𝕊"L": 'L'; 𝕊"R": 'R'; •ParseFloat 𝕩 }
 PrepPath←{ PrepStep¨(+`⟨0⟩∾≠˝⍉2↕𝕩∊"LR")⊔𝕩 }
 Prep←{ ⟨ PrepMap ¯2↓𝕩, PrepPath ¯1⊑𝕩 ⟩ }
@@ -12,6 +11,9 @@ TL←{⟨¯1,1⟩×⌽𝕩}
 TR←{⟨1,¯1⟩×⌽𝕩}
 
 Main←{𝕊⟨map,path⟩:
+  sidelen←√(+´⥊' '≠map)÷6
+  Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »⍟sidelen˘»⍟sidelen(w+2×sidelen)↑˘(h+2×sidelen)↑𝕩 }
+  map ↩ Pad map
   Move←{
     'L' 𝕊 ⟨pos,dir⟩: ⟨pos,TL dir⟩;
     'R' 𝕊 ⟨pos,dir⟩: ⟨pos,TR dir⟩;
@@ -22,10 +24,10 @@ Main←{𝕊⟨map,path⟩:
     dest↩{ (≢map)|𝕩+dir } •_while_ { ' '=𝕩⊑map } dest
     ⟨('.'=dest⊑map)⊑⟨pos,dest⟩,dir⟩
   }
-  pos←⟨1,⊑(1⊏map)⊐'.'⟩
+  pos←⟨sidelen,⊑(sidelen⊏map)⊐'.'⟩
   dir←⟨0,1⟩
   ⟨⟨r,c⟩,d⟩ ← ⟨pos,dir⟩ Move´ ⌽path
-  (1000×r) + (4×c) + (|1-˜+´⟨2,1⟩×d)
+  (1000×r+1-sidelen) + (4×c+1-sidelen) + (|1-˜+´⟨2,1⟩×d)
 }
 
 •Show Main Prep •file.Lines ⊑•args