Sokoban clone in Eve

153 views
Skip to first unread message

Frankie Robertson

unread,
Oct 8, 2016, 5:31:39 AM10/8/16
to Eve talk
Hey again Evers,

I made another simple turn-based single-player game in Eve. This time it's a Sokoban clone: https://github.com/frankier/eve-experiments/blob/master/sokoban.eve

You need to bring your own levels if you want to try: just paste a level in into the textbox and hit load. I've not included any levels because I'm unclear about their copyright status but you can find levels in various places around the Internet such as here: http://www.sourcecode.se/sokoban/levels

Here's a really small level for anyone just looking to try it out quickly:

####
#@.#
#$ #
#  #
# $#
#. #
#  #
####

Again I had trouble implementing resetting for the game. Here are two attempts I made:

 * Trying to delete records by adding an extra #deleted tag and guarding against that elsewhere https://github.com/frankier/eve-experiments/blob/77596180e7257f0522c9004c0a65427ebd75ccb9/osute.eve

Note that (I think) I have to make a state machine to reset and load in response to a single click. This is because I have to do two things in response to a click: first remove all the records (or rather mark them as removed) and then insert a bunch of new ones. I think if I didn't add in some sort of explicit state tracking the steps, the program would fail to converge. In the cases I do have to do this Eve feels very heavyweight (it feels a lot like writing Verilog). I wonder if there might be a way to add some syntactic sugar for sequencing actions? (Which could just generate a state machine behind the scenes.)

Perhaps something like "match after previous" or "label: match...bind...match after label". I'm a bit fuzzy on exactly how it'd work so maybe something as simple as I'm suggesting isn't possible. Do you think it might be too complicated or encourage bad style or that perhaps it's worth considering down the road?

Anyway, perhaps once the ":= none" syntax is implemented I'll have an easier time getting resetting to work.

I originally wrote the win condition as:

match
  box = [#box x y]
  not([#goal x y])
  count[given: box] = 0
bind
  [#won]

I think understand why that doesn't work: there is no x and y matching that condition so it won't fire at all. I think that means that count[...] can never return 0. I wonder if Eve could give a warning whenever count[...] = 0 (or != 0) is encountered since it must be a mistake.

One thing you might find a bit odd in this implementation is the [#cell] entities. My original plan was to count the largest row index and the largest column index and then use range[] in the drawing block but since there is no max[...] aggregate so it was easier to do it this way.

One thing I found interesting while writing this was thinking about how code reuse and abstractions might work out in Eve. In the program one area I highlighted as a possible area for reuse is the decoding of presses of the directional keys into a 2d vector. Another possible abstraction would be actual operations on vectors. Yet another would be a grid display component - possibly something that could be shared between this program and Minesweeper. These abstractions might be useful for sharing between many of these type of games. I wonder if Eve will lend itself to these types of tiny abstractions better than other programming environments. Is there a plan for how importing and sharing code might work?

Cheers,
Frankie

Michael

unread,
Oct 8, 2016, 6:03:11 AM10/8/16
to Eve talk
Thanks alot Frankie for your example - it's helpful for newcomers like me.


On Saturday, 8 October 2016 19:31:39 UTC+10, Frankie Robertson wrote:

Anyway, perhaps once the ":= none" syntax is implemented I'll have an easier time getting resetting to work.

I'm brand new to the language, but I was just reading ":= none" in https://witheve.github.io/docs/handbook/set/ Is it what you needed?

Regards

Michael.

Frankie Robertson

unread,
Oct 8, 2016, 7:08:57 AM10/8/16
to Eve talk
On Saturday, 8 October 2016 19:03:11 UTC+9, Michael wrote:
Thanks alot Frankie for your example - it's helpful for newcomers like me.

Cheers. I do hope it's helpful. I'm not sure if the style I used is the best, but please do ask if you have any questions about it.


On Saturday, 8 October 2016 19:31:39 UTC+10, Frankie Robertson wrote:

Anyway, perhaps once the ":= none" syntax is implemented I'll have an easier time getting resetting to work.

I'm brand new to the language, but I was just reading ":= none" in https://witheve.github.io/docs/handbook/set/ Is it what you needed?

I think the handbook is still a bit out of sync with the implementation available in master. See this issue https://github.com/witheve/Eve/issues/431 . Possibly it's working in in versions which include this commit: https://github.com/witheve/Eve/commit/8a06aff5c3913aa110a3e3008d9faffaff83612b I guess. I think I'm just going to wait until it's in master before trying it out though since I don't really know the state of the other branches. 
 

Regards

Michael.

P.S. One thing I just realised is that for the level parsing to work 100% correctly you need to wait for this to be merged: https://github.com/witheve/Eve/pull/460 , use my fork https://github.com/frankier/Eve or insert an extra newline after the last line of the level.

Alexey Shamrin

unread,
Oct 8, 2016, 5:16:34 PM10/8/16
to Eve talk
Hello,

I've played with ts-merge branch a little today. And indeed, := none and max[value, given] are implemented in the new TypeScript version of Eve.

My simple experiment uses max and := none successfully:

By the way, here's how I was running the ts-merge branch:

git checkout dc92d55
npm install
npm run build
env PORT=8123 npm run server


Why I'm using dc92d55 above and not ts-merge? That's because the latest ts-merge commit didn't work for me. I don't know why. Something happened in the next commit after dc92d55.

Alexey

Frankie Robertson:

Ravil Bayramgalin

unread,
Oct 10, 2016, 4:40:06 PM10/10/16
to Eve talk
Alexey, you also need to run "node build/scripts/package-examples.js" (after the build step) to have the latest ts-merge commit working.

воскресенье, 9 октября 2016 г., 0:16:34 UTC+3 пользователь Alexey Shamrin написал:

Ravil Bayramgalin

unread,
Oct 10, 2016, 4:42:00 PM10/10/16
to Eve talk
Oh, a even better "tsc scripts/package-examples.ts" :)

Chris Granger

unread,
Oct 10, 2016, 5:05:51 PM10/10/16
to Eve talk
Added that to npm run build :)
Reply all
Reply to author
Forward
0 new messages