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

Challenge scenario requiring the use of a stack #932

Closed
byorgey opened this issue Dec 21, 2022 · 5 comments · Fixed by #1031
Closed

Challenge scenario requiring the use of a stack #932

byorgey opened this issue Dec 21, 2022 · 5 comments · Fixed by #1031
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Design An issue having to do with game design. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-Challenges Involves the challenge scenarios - shorter games with objectives. Z-Feature A new feature to be added to the game.

Comments

@byorgey
Copy link
Member

byorgey commented Dec 21, 2022

I was thinking the other day that it would be really cool to have stacks somehow. Like a physical thing that you could push and pop entities on. This would let you simulate pushdown automata and would probably allow for some cool automated production scenarios.

However, I don't necessarily want to just create a new device or built-in thing. What I really want to think about is, what would you need to be able to program a stack yourself? I'm thinking something like this:

  • We might need recursive types (Recursive types #154) to be able to store the stack itself, though you might be able to get away with a Church-encoded list (but popping would be expensive).
  • You need some way to communicate (Inter-robot communication #94) at close range to be able to "invoke methods" on the stack robot. e.g. I'm imagining to push, you place the item you want to push and then send a push message to the stack robot, which will pick up the item and store it. To pop, you send a pop message, and it will place an item down.

Would be happy to hear about other approaches I haven't thought of.

@byorgey byorgey added the Z-Feature A new feature to be added to the game. label Dec 21, 2022
@kostmo
Copy link
Member

kostmo commented Dec 28, 2022

I think you can emulate a stack within the "environment" of a recursive function1. Have the "state machine" of whatever algorithm you're carrying out exist inside the body of the recursive function. The "top" of the stack is an argument to the function. Recurse again with a new argument to "push" onto the stack, or allow the current layer to exit to "pop" from the stack.

Footnotes

  1. This came to mind from the way I implemented the fence loop detector. The premise of the detector is to find the surrounding water by heading straight in one direction. Along the way, one might encounter walls with arbitrarily many "spiral twists". While following the wall, need to keep track of the turns that were made to eventually "unwind" and continue along the original direction. I use the recursion stack for this bookkeeping.

@kostmo
Copy link
Member

kostmo commented Dec 28, 2022

In parallel, we should contrive a challenge scenario where the player is required to use a stack.

@byorgey
Copy link
Member Author

byorgey commented Dec 31, 2022

Ah, excellent, this got me on the right track. Something like this (pseudocode) should work:

def stackNE : text -> cmd unit =
  while a pop is not requested:
    wait for a signal
    if a push is requested:
      thing2 <- grab
      stackNE thing2
    else if a pop is requested:
      place thing
    end if
  end while
end

def stack : cmd unit =
  while true:
    wait for a "push" signal
    thing <- grab
    stackNE thing
end

@byorgey
Copy link
Member Author

byorgey commented Jan 6, 2023

Hmm, I had a potentially interesting idea for a challenge scenario: there is a line of entities on the ground, and you are required to reverse them, i.e. pick them up and place them down in the same locations but in reversed order. However, you have a limited number of ticks in which to complete the challenge --- so that you have to use an O(n) solution instead of O(n^2). i.e. you can't walk back and forth swapping the items on the ends, then the items one from the ends, and so on. You have to walk down the line and pick them all up, then walk back and somehow place them down in reverse order --- of course the way to do this is to simulate a stack internally with recursion. To solve the challenge you would have to program a solution and run it with --run in order to get it to finish in the time limit. (#927 would be nice for this since when the timer runs out it could pop up a dialog telling you that you can no longer win.)

Of course someone could always cheese it by writing a really tedious program like thing1 <- grab; move; thing2 <- grab; move; thing3 <- grab; move ... but, their loss. (Though that does make me wonder about defining challenges with "secret test scenarios" that your code has to also pass in addition to the "public example scenario"...)

@kostmo
Copy link
Member

kostmo commented Jan 6, 2023

defining challenges with "secret test scenarios" that your code has to also pass in addition to the "public example scenario"

I've been thinking about that, too. I've fleshed out a concept in #967.

Another mitigation to "cheesing" would be scoring the solution based on the AST size (#866).

@kostmo kostmo added the G-Design An issue having to do with game design. label May 30, 2023
@byorgey byorgey added the G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. label May 29, 2024
@byorgey byorgey changed the title Stacks Challenge scenario requiring the use of a stack May 29, 2024
@byorgey byorgey added C-Moderate Effort Should take a moderate amount of time to address. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-Challenges Involves the challenge scenarios - shorter games with objectives. labels May 29, 2024
@mergify mergify bot closed this as completed in #1031 Oct 14, 2024
mergify bot pushed a commit that referenced this issue Oct 14, 2024
A challenge that utilizes a stack.
Closes #932.

Demo:
```
scripts/play.sh --scenario data/scenarios/Challenges/dna.yaml --autoplay
```
![Screenshot from 2024-10-13 17-06-06](https://github.com/user-attachments/assets/678984b0-f83d-4e0d-8958-dfcd33461ce6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Design An issue having to do with game design. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-Challenges Involves the challenge scenarios - shorter games with objectives. Z-Feature A new feature to be added to the game.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants