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

[WIP] palanquin scenario #1787

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions data/scenarios/Challenges/_palanquin/emperor.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
def goDir = \f. \r.
let d = fst r in
if (d == down) {
grapesHere <- ishere "grapes";
if grapesHere {
grab; return ()
} {};
return ();
} {
turn d;

// An obstruction might arise after
// navigation direction is determined
// but before we move.
try {
move;
} {};
f;
}
end;

def followRoute = \item.
nextDir <- path (inL ()) (inR item);
case nextDir return $ goDir $ followRoute item;
end;

def getGrapes =
let targetItem = "grapes" in
emperorHasThem <- has targetItem;
if emperorHasThem {
say "Tally ho!";
} {
grapesDropped <- as base {
baseHasThem <- has targetItem;
return $ not baseHasThem;
};

if grapesDropped {
followRoute targetItem;
} {
wait 10;
getGrapes;
};
}
end;

def avoidSides =

toLeft <- scan back;
case toLeft return (\_.
turn right;
);

toRight <- scan back;
case toRight return (\_.
turn left;
);

behind <- scan back;
case behind return (\_.
isBlocked <- blocked;
if isBlocked {} {move;}
);

watch forward;
watch back;
watch left;
watch right;
wait 1000;
end;

def go =
getGrapes;
avoidSides;
go;
end;

go;
118 changes: 118 additions & 0 deletions data/scenarios/Challenges/_palanquin/solution.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def intersperse = \n. \f2. \f1. if (n > 0) {
f1;
if (n > 1) {
f2;
} {};
intersperse (n - 1) f2 f1;
} {};
end;

def shiftRightForPush =
turn back;
move;
turn left;
move;
turn left;
end;

/*
Precondition:
Positioned behind the wall, facing it, on the leftmost cell.
*/
def pushWall =
intersperse 3 shiftRightForPush push;
end;

def moveToBackWall =
turn back;
doN 5 move;
turn right;
doN 2 move;
turn right;
end;

def moveRightSide =
turn right;
push;
turn right;
move;
turn left;
move;
turn left;
doN 5 push;
turn right;
move;
turn left;
move;
turn left;
push;
end;

def moveLeftSide =
doN 4 move;
turn left;
doN 5 move;
turn right;
push;
turn left;
move;
turn right;
move;
turn right;
doN 5 push;
turn left;
move;
turn right;
move;
turn right;
push;
end;

def initialSetup =
turn south;
doN 3 move;
turn right;
move;
turn right;
end;

def waitUntilGrapesGrabbed =
itemHere <- scan forward;
case itemHere return (\_.
watch forward;
wait 1000;
waitUntilGrapesGrabbed;
);
end;

def placeGrapes =

doN 4 move;
place "grapes";
turn back;
move;
doN 2 push;
turn back;
doN 2 move;
waitUntilGrapesGrabbed;

turn back;
doN 4 move;
turn back;
doN 2 push;
end;

def go =
placeGrapes;

// initialSetup;
// pushWall;
// moveToBackWall;
// pushWall;
// moveRightSide;
// moveLeftSide;
end;

go;
Loading
Loading