diff --git a/logic.bqn b/logic.bqn index ac6e369..91eb2e3 100644 --- a/logic.bqn +++ b/logic.bqn @@ -51,6 +51,7 @@ Game⇐{ # The Game function creates a game object # Rules: # ------------------------------------------------------------------------------- # + # --- Rule 1: ------------------------------------------------------------------- # - The player can push but not pull any movable object one tile away in the # current direction to an empty tile: @@ -81,28 +82,34 @@ Game⇐{ # The Game function creates a game object # Calculates the bounces of a laser beam recursively Bounce←{(w‿d)S x:{ # Base case: ⊑opaque∊˜⊑w⊑x? # When the beam touches an opaque object (not a mirror): - (machine=⊑w⊑x)◶⟨x, # we do nothing if it doesn't touch a machine - ⟨pmachine⟩˙⌾(w⊸⊑)x # and if it does we change it to a powered machine - ⟩@; # and the recursion stops - ⊑empties∊˜⊑w⊑x ? # When the beam passes through an empty space: - # we draw the laser beam and recurse to the next: - ⟨w+d,d⟩S{ # we choose the type of laser beam to draw - cTile←(floor‿hbeam‿vbeam‿xbeam⊐𝕩) # depending on the current tile: - # floor hbeam vbeam xbeam | floor hbeam vbeam xbeam - cBeam← ((×⊑d) ⊑ ⟨hbeam‿hbeam‿xbeam‿xbeam , vbeam‿xbeam‿vbeam‿xbeam⟩) - # and beam direction Horizontal | Vertical - cTile⊏cBeam - }⌾(w⊸⊑)x; - # When the beam touches a mirror: - d←⌽d×-⊸¬lmirror=⊑w⊑x # calculate the mirror bounce direction - ⟨w+d,d⟩S x # and recurse to the next position - } + + (machine=⊑w⊑x)◶⟨ # if it's not a machine: + x, # we do nothing + ⟨pmachine⟩˙⌾(w⊸⊑)x # and if it is, we change it to a powered machine + ⟩@; # and the recursion stops + + ⊑empties∊˜⊑w⊑x ? # When the beam passes through an empty space: + + # we draw the laser beam and recurse to the next: + ⟨w+d,d⟩S{ # we choose the type of laser beam to draw + cTile←(floor‿hbeam‿vbeam‿xbeam⊐𝕩) # depending on the current tile: + # floor hbeam vbeam xbeam | floor hbeam vbeam xbeam + cBeam← ((×⊑d) ⊑ ⟨hbeam‿hbeam‿xbeam‿xbeam , vbeam‿xbeam‿vbeam‿xbeam⟩) + # and beam direction Horizontal | Vertical + cTile⊏cBeam + }⌾(w⊸⊑)x; + + # When the beam touches a mirror: + d←⌽d×-⊸¬lmirror=⊑w⊑x # calculate the mirror bounce direction + ⟨w+d,d⟩S x # and recurse to the next position + } } # We find each laser machine and shoot a beam in its direction # Shoot 𝕩 | 𝕩: map | calculates the bounces for each laser Shoot←{𝕩 {𝕨Bounce´⌽𝕩} ∾⟨<0‿¯1,<0‿1,<¯1‿0,<1‿0⟩(⊣⋈˜¨+)¨ FindIdx⟜(⊑¨𝕩)¨ lasers} + # --- Rule 2: ------------------------------------------------------------------- # - The Player wins when all machines are powered: Win←{¬∨´∨˝machine=⊑¨Shoot 𝕩}# 𝕩: level | Win condition, no unpowered machines after shooting laser