
Minesweeper in Clojure - tosh
http://sneakycode.net/minesweeper-in-clojure
======
weavejester
As an alternative design, I'd have gone with a data structure more like:

    
    
        #:minesweeper{:size    [w h]
                      :bombs   #{[x y] ...}
                      :flags   #{[x y] ...}
                      :guesses ([x y] ...)}

~~~
pgt
I wrote Snake in 100 lines of ClojureScript for a talk at UCT a few years ago
and used that shape of data structure: [http://theronic.github.io/cljs-
snake/](http://theronic.github.io/cljs-snake/)

For anything more complex, I immediately reach for DataScript as a client-side
Datalog DB.

~~~
sneakypeet
Ha. I made a similar thing trying out p5 for the first time.
[https://sneakypeet.github.io/data-snake/](https://sneakypeet.github.io/data-
snake/)

------
lilactown
I did the same exercise a few months ago! Using a little React wrapper I wrote
for myself:

[https://github.com/Lokeh/lilac.town/blob/master/src/lilactow...](https://github.com/Lokeh/lilac.town/blob/master/src/lilactown/client/sweeper.cljs)

[https://lilac.town/games/sweeper](https://lilac.town/games/sweeper)

~~~
sneakypeet
the dots between squares are trippy

~~~
lilactown
Lol, design is not my forte. I tried!

Btw, really great write up - I think you did a great job explaining the
process of solving problems in Clojure.

~~~
sneakypeet
Thank you. I think your design is stellar. I'm keen to go through your code
too. Since moving to clojure I have found myself reading much more source code

------
aardvark179
As a next challenge, can you ensure the board is solvable without guessing?
You have to delay generating it until the user has done that first click, but
there are some other constraints as well.

Also, you probably want to stop clicks on marked squares from exploding the
mine.

~~~
sneakypeet
oh yes. I did not think of that. generating on first click should not be to
difficult. what are the other constraints?

~~~
simcop2387
A convinent source of information about this is going to be Simon Tatham's
excellent puzzle suite. Most the puzzles are built to ensure a solution
without guessing.

[https://www.chiark.greenend.org.uk/~sgtatham/puzzles/doc/min...](https://www.chiark.greenend.org.uk/~sgtatham/puzzles/doc/mines.html#mines)

[https://www.chiark.greenend.org.uk/~sgtatham/puzzles/](https://www.chiark.greenend.org.uk/~sgtatham/puzzles/)

They're all open source and I believe available on iOS as well as android for
free for mobile users too.

------
pbhjpbhj
Long-press to flag would be handy on mobile.

~~~
rajangdavis
I second this, otherwise the approach is really cool!

------
verymelo_
Do you reccomened Clojure over Haskell to learn ?

~~~
Royalaid
My personal experience is that most programmers either like or don't like type
systems. If you don't I would highly recommend Clojure, if you do I would
highly recommend Haskell.

~~~
stingraycharles
And then there's this bunch of us that are not as dogmatic and appreciate
both.

And there's also Typed Clojure, but that might not be the best experience
starting out.

