Squeezing a Sokoban game into 10 lines of Haskell
cole-k.com
cole-k.com
Don't read this, then (from a 2048 game instead of Sokoban, but same principle): https://github.com/darius/cant/blob/master/examples/games/20...
As long as I'm commenting, here are some links to other Sokobans I thought were fun (listed in the source code to mine). The sed one is nuts -- I had no idea it could do that: https://github.com/darius/cant/blob/master/examples/games/so...
So really it is a shame that nothing can be done about golfing this further and I will be content knowing that... is what I'd like to say if not for the several [1] characters [2] I have at my disposal for a last level.
Thank you for sharing though, I also was amazed by the sed one. And just to make it clear since sometimes these things don't communicate well over the internet, I'm being a little facetious here: if you actually want to spell it out for me I'm not going to be upset (but if you don't, I'm also not going to be upset :) ).
[1] https://news.ycombinator.com/item?id=34924577
[2] https://reddit.com/r/haskell/comments/11953ov/squeezing_a_so...
I was thinking along the same line as the parent comment at your link [2] -- really, I was too eager to play know-it-all.
Just to explain the difference that may be unclear because of the language: the move functions I linked to call an `each` function which is like Haskell's `map`, only because these move functions all return a list of board states, for the sake of animating the moves in the 2048 game.
These all work in terms of `left` in my code, vs. `moveRight` in yours. So the function that'd cause trouble is `down` instead of `moveUp`, if I'd tried to organize it exactly the way you did, versus just generally basing it on conjugation. I didn't try to golf this version, and I sure wouldn't bet on being able to as much as you did. Respect.
This is less of a challenge for IOCCC entries like my [1] where I wanted the variables & constants to spell out the language it interprets:
Int L[A],m,b,*D=A,
*c,*a=L,C,*U=L,u;s
as C doesn't care about capitalization, whereas Haskell reserves upper case for types and constructors.This made my morning.
Awesome! Sometimes people allow themselves to use unlimited length lines when shortening the number of lines. But this is good, 80 chars max per line is how it should be when talking about obfuscated code which has been crammed into a low number of lines.
One fact that does not get enough mention though is that, regardless of the code golfing results, Haskell programs have the habit of being exceptionally concise even if you don't try to write short code.
All of which is to say, great work.
Also, a shameless plug, but if you are interested in a Sokoban like game, you might enjoy Pathology (formerly called Psychopath built in 2005). It is a 2d block pushing game where the goal is to go from Point A to Point B in shortest amount of steps. There's a level editor (thousands of levels) multiplayer, and active community (Many folks from the Sokoban online community play too)
Are there good references for how I can make my coworkers hate me?
I don't want to neglect your shameless plug, but I struggle enough to find a solution to some of the puzzles I wrote (hence the undo), so finding the shortest path is a little daunting.
The best I know of are some tools people developed for the tiny game jam to help you minify your code, which you can find here https://github.com/haskell-game/tiny-games-hs#minifying.
Initial readers noted that the code blocks were unreadable for those without dark mode extensions due to black-on-black text. Perhaps I should've kept them that way.
Jokes aside, thank you!