4 ms·
Minesweeper in Clojure
- aardvark179 8y agoAs 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.
- degenerate 8y agoI kept right-clicking to flag the mines and didn't understand what was happening. edit: [Shift] + Click to flag.
- lilactown 8y agoShift-click flags the mines according to the description
- sneakypeet 8y agoYeah shift click should do the trick
- sneakypeet 8y agooh yes. I did not think of that. generating on first click should not be to difficult. what are the other constraints?
- pbhjpbhj 8y agoNot parent: if you click a square and it says 7/6 then sometimes (next to a corner) you can only guess, you can't deduce the correct square to flag. There are others.
- aardvark179 8y agoYou can’t have enclosed areas that contain mines, there’s probably a few others. The easiest thing to do is to write a solver which will iteratively mark squares it knows to contain a mine, or knows don’t contain a mine. If the solver can find all the mines the board is solvable. Only present the user with boards that your solver can solve.
- simcop2387 8y agoA 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/mines.html#mines https://www.chiark.greenend.org.uk/~sgtatham/puzzles/doc/min... 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.
- verymelo_ 8y agoDo you reccomened Clojure over Haskell to learn ?
- Royalaid 8y agoMy 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 8y agoAnd 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.
- shaunxcode 8y agoLearn both. If you have no functional programming experience then learning clojure first should help you get comfortable with higher order functions and other functional paradigms before diving into the type theory side of things with Haskell.
- sdegutis 8y agoI wrote a little comparison of Haskell and Clojure a few years ago here: https://sdegutis.com/blog/2015-02-10-haskell https://sdegutis.com/blog/2015-02-10-haskell And some of the cons of Haskell in that article may be addressed by these extensions: https://sdegutis.com/blog/2015-03-17-haskell-extensions https://sdegutis.com/blog/2015-03-17-haskell-extensions
- moocowtruck 8y ago>Compared to Clojure Rich borrowed almost all of Clojure’s standard library from Haskell. Destructuring in Clojure also looks like it came directly from Haskell. wat? is this really true?
- 8y ago
- pbhjpbhj 8y agoLong-press to flag would be handy on mobile.
- rajangdavis 8y agoI second this, otherwise the approach is really cool!
- lilactown 8y agoI 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/lilactown/client/sweeper.cljs https://github.com/Lokeh/lilac.town/blob/master/src/lilactow... https://lilac.town/games/sweeper https://lilac.town/games/sweeper
- sneakypeet 8y agothe dots between squares are trippy
- lilactown 8y agoLol, 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 8y agoThank 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
- weavejester 8y agoAs 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] ...)}
- sneakypeet 8y agoYes that is pretty smart. One of my game design friends mentioned the same thing after I showed him the code. I sometimes feel I am still living in that oo mindset
- pgt 8y agoI 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 8y agoHa. I made a similar thing trying out p5 for the first time. https://sneakypeet.github.io/data-snake/ https://sneakypeet.github.io/data-snake/