Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sokoban levels #1269

Merged
merged 3 commits into from
May 19, 2023
Merged

sokoban levels #1269

merged 3 commits into from
May 19, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented May 19, 2023

Three simple (demonstration) levels plus one serious challenge, foresight.yaml.

image

@kostmo kostmo marked this pull request as ready for review May 19, 2023 07:33
@kostmo kostmo requested a review from byorgey May 19, 2023 07:34
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it! Below is my foresight solution (written without looking at your solution or doing --autoplay). Note I decided to simply not bother with the crates --- you can just go through the spiral thing instead of going through the crates. I don't know if you want to require going through the crates.

def while : cmd bool -> cmd unit -> cmd unit = \test. \body.
  b <- test;
  if b {body; while test body} {}
end

def opposite : dir -> dir = \d. if (d == left) {right} {left} end

def pushUntilBlocked : cmd unit = try {push; pushUntilBlocked} {} end

def goToNook : dir -> int -> cmd unit = \d. \n.
  if (n == 0) {
    turn (opposite d); move; turn back
  } {
    turn d; pushUntilBlocked; goToNook d (n-1)
  }
end

def center : cmd unit =
  turn right; move; turn left; move; turn right; move; move
end

def assistant : int -> cmd unit = \n.
  goToNook left n;
  watch forward; wait 2048;
  if (n == 4)
    {push; push}
    { pushUntilBlocked; wait 2; try {move} {};
      goToNook left (3-n); move; move
    };
  center;
  goToNook right n;
  watch forward; wait 2048;
  pushUntilBlocked
end

def x : int -> cmd unit -> cmd unit = \n. \c.
  if (n == 0) {} {c ; x (n-1) c}
end

def for : int -> (int -> cmd unit) -> cmd unit = \n. \c.
  if (n == 0) {} {c n; for (n-1) c}
end

def solution : cmd unit =
  turn left; x 3 move; turn right;
  x 6 (pushUntilBlocked; turn back; move; turn right);
  x 6 (pushUntilBlocked; turn back; move; turn left);
  turn left; move; turn right;
  pushUntilBlocked;
  turn right; x 18 move; grab; equip "3D printer";
  turn back;
  pushUntilBlocked; turn left;
  pushUntilBlocked; turn back; x 2 move; turn right; pushUntilBlocked;
  for 5 (\k. build {assistant (k-1)}; return ());
  turn back; pushUntilBlocked; turn right; x 12 move; turn right; move; turn right;
  pushUntilBlocked;
  turn right; move; turn left; move; turn left; pushUntilBlocked;
  wait 10;
  x 5 (pushUntilBlocked; turn left);
  move; turn right; move; turn left; x 2 move; turn left; x 2 move; turn left; move; turn left;
  pushUntilBlocked;
  wait 10;
  x 6 (pushUntilBlocked; turn right);
  move; turn left; move; turn left; x 3 push
end

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label May 19, 2023
@mergify mergify bot merged commit 39ae4ae into main May 19, 2023
@mergify mergify bot deleted the sokoban-levels branch May 19, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants