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

hackman #1135

Merged
merged 3 commits into from
Mar 23, 2023
Merged

hackman #1135

merged 3 commits into from
Mar 23, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Feb 27, 2023

Demo

scripts/play.sh --scenario Challenges/hackman.yaml --autoplay

image

Makes use of both #1058 and #1023.

@kostmo kostmo force-pushed the hackman-scenario branch 2 times, most recently from 9e387d6 to d33d50d Compare March 5, 2023 09:12
@kostmo kostmo force-pushed the hackman-scenario branch from d33d50d to 5ed4f48 Compare March 6, 2023 05:16
@kostmo kostmo force-pushed the hackman-scenario branch 2 times, most recently from 96eab20 to 3aa0127 Compare March 23, 2023 07:26
@kostmo kostmo marked this pull request as ready for review March 23, 2023 07:26
@kostmo kostmo force-pushed the hackman-scenario branch from 3aa0127 to b29bed6 Compare March 23, 2023 07:35
@kostmo kostmo force-pushed the hackman-scenario branch from b29bed6 to 024cebb Compare March 23, 2023 07:36
@kostmo kostmo requested a review from byorgey March 23, 2023 07:48
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.

Nice! I wrote some code to follow and eat pellets + donuts as long as there are any adjacent. But I had to manually move hackman between each string of pellets once it ate a bunch and ended up next to blank spaces. I'm still wondering if there is a less manual way to do it. What about equipping hackman with a bitcoin? Then at the very least you could code it to wander around randomly until encountering more things to eat.

Once we do #102 it could also be fun to equip hackman with whatever device lets you handle input. Then one strategy would be to code up your own key handler so you could actually e.g. drive hackman around with arrow keys.

data/scenarios/Challenges/_hackman/ghost.sw Show resolved Hide resolved
data/scenarios/Challenges/hackman.yaml Outdated Show resolved Hide resolved
@byorgey
Copy link
Member

byorgey commented Mar 23, 2023

I'm proud of this solution I developed, which eventually manages to eat everything (though it takes a while):


def ifC : cmd bool -> {cmd a} -> {cmd a} -> cmd a = \test. \then. \else.
  b <- test; if b then else
end

def while : cmd bool -> {cmd a} -> cmd unit = \test. \body.
  ifC test {force body ; while test body} {}
end

def unless = \test. \then. \else. ifC test else then end

def until = \test. \body.
  ifC test {} {force body ; until test body}
end

def elsif = \p. \then. \else. {if p then else} end
def elsifC = \p. \then. \else. {ifC p then else} end

def forever : cmd a -> cmd b = \c.
  c; forever c
end

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

def isBlocked : dir -> cmd bool = \d.
  turn d;
  b <- blocked;
  turn (inverseDir d);
  return b
end

def followLeft =
  unless (isBlocked left) {turn left}
  { unless (isBlocked forward) {}
    { unless (isBlocked right) {turn right} {turn back} } };
  move
end

def followRight =
  unless (isBlocked right) {turn right}
  { unless (isBlocked forward) {}
    { unless (isBlocked left) {turn left} {turn back} } };
  move
end

def isFood = \x. x == inr "pellet" || x == inr "donut" end

def isFoodTo = \d. res <- scan d; return (isFood res) end

def stepToFood =
  ifC (isFoodTo left) {turn left; move}
  $ elsifC (isFoodTo forward) {move}
  $ elsifC (isFoodTo right) {turn right; move}
  $ elsifC (isFoodTo back) {turn back; move} {}
end

def followFood = while (isFoodTo down) { grab; stepToFood } end

def eatAll =
  forever (
    until (isFoodTo down) { followRight; followLeft; followLeft; stepToFood };
    followFood
  )
end

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Mar 23, 2023
@mergify mergify bot merged commit 51b4bcd into main Mar 23, 2023
@mergify mergify bot deleted the hackman-scenario branch March 23, 2023 19:09
This was referenced Jul 2, 2023
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