packages feed

swarm-0.7.0.0: data/scenarios/Challenges/Ranching/gated-paddock.yaml

version: 1
name: Pastoral Island
author: Karl Ostmo
description: |
  Start a wool industry from the local fauna.
creative: false
objectives:
  - id: enclose_sheep
    teaser: Paddock sheep
    goal:
      - |
        You've homesteaded on a small island in the ocean.
        It's time to gather resources to trade.
      - |
        You encounter some feral sheep (**@**). They slowly wander the island and eat grass.
        Your mind wanders to textiles...
      - |
        First, paddock at least one sheep so they don't drown.
        Make sure there are no gaps in the fence!
      - |
        Note that you can use the `drill` command (by way of the `post puller`{=entity} tool)
        to demolish a `fence`{=entity} that has been `place`d.
    condition: |-
      def isBlockedOrFenced =
          b <- blocked;
          pure b;
          end;

      def checkIsEnclosed =
          maybePath <- path (inL ()) (inR "water");
          case maybePath (\_. pure True) (\_. pure False);
          end;

      def boolToInt = \b. if (b) {pure 1} {pure 0}; end;

      def countAdjacentBlockages =

          turn left;
          b1 <- isBlockedOrFenced;
          c1 <- boolToInt b1;

          turn left;
          b2 <- isBlockedOrFenced;
          c2 <- boolToInt b2;

          turn left;
          b3 <- isBlockedOrFenced;
          c3 <- boolToInt b3;

          turn left;
          b4 <- isBlockedOrFenced;
          c4 <- boolToInt b4;

          pure $ c1 + c2 + c3 + c4;
          end;

      // Step forward, observing left and right.
      def observeLeftAndRight =
          move;
          turn left;
          amBlockedLeft <- isBlockedOrFenced;
          val1 <- boolToInt amBlockedLeft;

          turn back;
          amBlockedRight <- isBlockedOrFenced;
          val2 <- boolToInt amBlockedRight;

          turn right;
          move;
          pure $ val1 + val2;
          end;


      /** If the four cardinal directions have at most
      one blockage, then there will exist an orientation
      where both that direction and its opposite direction
      are clear.
      So we can step that direction, check to the left and
      right of us, then step in the opposite direction
      and do the same. This allows us to check the 4
      blocks that touch the corners of the center block.
      */
      def countDiagonalBlockages =
          // First, orient to the clear front-to-back path
          amBlocked <- isBlockedOrFenced;
          if amBlocked {turn left;} {};

          // Second, step to both sides
          fwdCount <- observeLeftAndRight;
          backCount <- observeLeftAndRight;
          pure $ fwdCount + backCount;
          end;

      def isStandingOnBridge =
          onFence <- ishere "fence";
          onGate <- ishere "gate";
          if (onFence || onGate) {
              adjCount <- countAdjacentBlockages;
              if (adjCount > 1) {
                  pure true;
              } {
                  diagCount <- countDiagonalBlockages;
                  pure $ (adjCount + diagCount) > 1;
              };
          } {pure false};
          end;

      def getValForSheepIndex = \predicateCmd. \i.
          try {
              // This will throw an exception if
              // the sheep has already drowned.
              r <- robotnumbered i;
              didSucceed <- as r {predicateCmd};

              boolToInt didSucceed;
          } {
              pure 0;
          }
          end;

      def countSheepWith = \predicateCmd.
          val1 <- getValForSheepIndex predicateCmd 1;
          val2 <- getValForSheepIndex predicateCmd 2;
          val3 <- getValForSheepIndex predicateCmd 3;
          pure $ val1 + val2 + val3;
          end;

      justFilledGap <- as base {
          isStandingOnBridge;
      };

      if (justFilledGap) {
          enclosedCount <- countSheepWith checkIsEnclosed;
          pure $ enclosedCount >= 1;
      } {
          pure false;
      }
  - id: feed_sheep
    teaser: Feed sheep
    goal:
      - |
        Safe! Your sheep are now hungry.
        Offer them something tasty and you may be rewarded.
      - |
        The sheep will move toward something edible on
        an adjacent tile and will eat it if they walk over it.
      - |
        You may want to add a `gate`{=entity} to the fence
        to give yourself easier access.
    condition: |-
      def getTruthForSheepIndex = \predicateCmd. \i.
          try {
              // This will throw an exception if
              // the sheep has already drowned.
              r <- robotnumbered i;
              as r {predicateCmd};
          } {
              pure false;
          };
          end;

      def anySheep = \predicateCmd. \i.

          if (i > 0) {
              didSucceed <- getTruthForSheepIndex predicateCmd i;
              if didSucceed {
                  pure true;
              } {
                  anySheep predicateCmd $ i - 1;
              };
          } {
              pure false;
          };
          end;

      anySheep (has "clover") 3;
    prerequisite: enclose_sheep
  - teaser: Knit sweater
    goal:
      - |
        Yum! Contented, well-fed sheep may drop `wool`{=entity}.
      - |
        Winter is coming! Collect three wool bundles to make a `sweater`{=entity}.
      - |
        Each sheep drops a finite amount over
        their lifetime.
    condition: |-
      as base {
        has "sweater";
      };
    prerequisite: feed_sheep
robots:
  - name: base
    dir: north
    devices:
      - treads
      - scanner
      - dictionary
      - branch predictor
      - strange loop
      - clock
      - ADT calculator
      - comparator
      - workbench
      - grabber
      - welder
      - lambda
      - logger
      - hearing aid
      - counter
      - mirror
      - post puller
    inventory:
      - [0, fence]
      - [0, gate]
      - [10, hinge]
  - name: sheep
    description: |
      meandering livestock
    display:
      invisible: false
      char: '@'
    system: true
    dir: north
    inventory:
      - [4, wool]
    walkable:
      never:
        - gate
    program: |
      run "scenarios/Challenges/Ranching/_gated-paddock/meandering-sheep.sw";
entities:
  - name: fence
    display:
      char: '#'
    description:
      - Keeps sheep in. And some other things out.
    properties: [known, pickable, unwalkable]
  - name: post puller
    display:
      char: 'P'
      attr: rock
    capabilities: [drill]
    description:
      - Good for dismantling fences.
    properties: [known, pickable]
  - name: scrap wood
    display:
      char: '\'
    description:
      - Scrap wood. Can be reconditioned into boards.
    properties: [known, pickable]
  - name: sweater
    display:
      attr: gold
      char: 'S'
    description:
      - A warm wool sweater. Just in time for winter!
    properties: [known, pickable]
  - name: clover
    display:
      attr: flower
      char: '%'
    description:
      - A tasty stack for fluffy ruminants.
    properties: [pickable, growable]
    growth: [80, 100]
  - name: gate
    display:
      char: '/'
      attr: rock
    description:
      - A gate permits the player to pass through, but sheep cannot.
    properties: [known]
  - name: hinge
    display:
      char: 'U'
      attr: rock
    description:
      - Facilitates swinging action.
    properties: [known, pickable]
  - name: cabin
    display:
      char: Π
      attr: rock
    description:
      - Home sweet home.
    properties: [known, unwalkable]
  - name: pier
    display:
      char: H
      attr: rock
    description:
      - Docking area for ships
    properties: [known]
  - name: fresh breadcrumb
    display:
      char: '.'
    description:
      - A marker that can be put down and found again. Used only by judge robot.
    properties: [pickable]
  - name: treaded breadcrumb
    display:
      char: 'x'
    description:
      - A marker that can be put down and found again (for a second time). Used only by judge robot.
    properties: [pickable]
  - name: evaporator
    display:
      char: 'E'
    description:
      - A tool that allows clearing a water tile. Used only by judge robot.
    properties: [pickable]
    capabilities: [drill]
  - name: wool
    display:
      char: 'ω'
      attr: gold
    description:
      - A bundle of raw animal fiber.
    properties: [pickable]
  - name: steam
    display:
      char: 'Z'
    description:
      - What's left after evaporating water. Used only by judge robot.
    properties: [pickable]
recipes:
  - in:
      - [2, board]
    out:
      - [1, fence]
  - in:
      - [3, wool]
    out:
      - [1, sweater]
  - in:
      - [1, scrap wood]
    out:
      - [1, board]
  - in:
      - [0, fresh breadcrumb]
    out:
      - [1, fresh breadcrumb]
  - in:
      - [1, fresh breadcrumb]
    out:
      - [1, treaded breadcrumb]
  - in:
      - [1, fence]
    out:
      - [1, scrap wood]
    required:
      - [1, post puller]
  - in:
      - [1, water]
    out:
      - [1, steam]
    required:
      - [1, evaporator]
  - in:
      - [1, hinge]
      - [1, fence]
    out:
      - [1, gate]
known: [mountain, tree, water]
seed: 0
solution: |
  run "scenarios/Challenges/Ranching/_gated-paddock/fence-construction.sw"
world:
  dsl: |
    {dirt, water}
  palette:
    'B': [grass, erase, base]
    '.': [grass, erase]
    't': [dirt, tree]
    'x': [stone, mountain]
    'c': [stone, cabin]
    's': [grass, erase, sheep]
    '%': [grass, clover, null]
    'H': [stone, pier, null]
    '~': [dirt, water]
  upperleft: [-34, 11]
  map: |-
    ~~~~.......~~~~~~~~~~~~~.......................~~~~~~
    ~~.............~~~~.......%.%%%%%%..%%%%%.%.......~~~
    ~........................%%%%%%%%%%%%%..%%%%.......~~
    ~...................................................~
    .............................x.xx........tttttttt...~
    .........................................tttttttt...~
    ..........................xxxxx..........tttttttt...~
    .........................................tttttttt...~
    ...........s.............................tttttttt....
    ....x....................................tttttttt....
    ...xx................................................
    ..xx.....................................B......c....
    ...x.................................................
    ..............................s......................
    .....................................................
    ....................................................~
    ~..............s...................................~~
    ~~.......xxx...........x.........................~~~~
    ~~~............xx............x............~~~~H~~~~~~
    ~~~.....................................~~~~~~H~~~~~~
    ~~.....................................~~~~~~~H~~~~~~
    ~~..............................~~~~~~~~~~~~~~H~~~~~~
    ~~~~...................~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~