Fun exercise! I found that the Ruby in this post resembles modern C# (probably because Ruby is a gold standard in readability, and in the last 5 years or so C# has been making big strides in readability). I've recreated the Ruby code mostly line-for-line in C# and posted it here: <a href="https://gist.github.com/waf/5c6a04899e8250cb9a89406b978c9bcc" rel="nofollow">https://gist.github.com/waf/5c6a04899e8250cb9a89406b978c9bcc</a><p>It mapped from Ruby to C# really well. The only concept I had to add was a `BoardCell` base type for the `Mine` and `Empty` types so we could return either `Mine` or `Empty` in a typesafe way. Everything else matched conceptually 1-1.<p>It's 118 lines total, with 18 lines of whitespace, so 100 lines exactly. I figure the original Ruby code was also not counting whitespace so it's a fair comparison. I tried to not use any "code golf tricks" that would minimize line count. It's a full program; it could be copy/pasted into a modern .NET 8 project and run without any additional setup.<p>Note, I posted this same comment on the original blog post, but I've posted it here too as it might be interesting for HN folks.
I had a go at an implementation of my own in Lil, using an imperative style rather than OOP. I tried to loosely follow the organization as shown here, but opted for a very different board representation, and I included some niceties like displaying board legends to aid in choosing the proper coordinates.<p><a href="https://github.com/JohnEarnest/Decker/blob/main/examples/lilt/mines.lil">https://github.com/JohnEarnest/Decker/blob/main/examples/lil...</a><p>I'm really not convinced that OOP simplifies or clarifies this type of program.
I'm currently implementing my favorite 2 player board game - Raptor - in Ruby, and this article is giving me great ideas for how to structure it better. Thanks so much to the author for writing this up!
Cool! Mine sweeper is a really fun easy game to implement. I did a version in Python a few years ago: <a href="https://github.com/igor47/sweeper">https://github.com/igor47/sweeper</a> but mine is closer to 500 lines
Warning to Mac users: you'll need at least ruby 2.7 to run this because it uses a feature called 'argument forwarding'. Looks like the latest ruby installed on macOS 15 is 2.6.<p>I eventually got it working with a combination of techniques from [this stackoverflow post](<a href="https://stackoverflow.com/questions/8730676/how-can-i-switch-to-ruby-1-9-3-installed-using-homebrew" rel="nofollow">https://stackoverflow.com/questions/8730676/how-can-i-switch...</a>) but it's not left my system in the cleanest of states.
Why are all of radanskoric's replies in this story marked as [dead]? He is replying to people here and all his comments won't show for people who don't have showdead enabled<p>And when I check his profile, almost every comment he's made is also marked as [dead] - but I don't see a good reason why?
Very fun stuff, and nice post.<p>Reminds me of my 2048 game clone in Ruby in about 100 lines (<a href="https://github.com/wkjagt/2048">https://github.com/wkjagt/2048</a>)<p>And I just saw that I did this - oh god - 9 years ago. Time goes way too fast.
This was fun. I saw a post on Pyxel a couple of days ago, and decided to write mine in Python using it.<p><a href="https://github.com/abhishekbasu/minesweeper">https://github.com/abhishekbasu/minesweeper</a>
I raise you 49 lines of typescript<p><a href="https://stackblitz.com/edit/gridgame-minesweeper?file=index.ts" rel="nofollow">https://stackblitz.com/edit/gridgame-minesweeper?file=index....</a>
The stupid thing about object-oriented programming and modern software is that code like this would never make it through code review on an "agile" team.<p>- "Oh, why are you doing procedural case statements? that's a SOLID anti-pattern, please refactor to polymorphism"<p>- "Oh, why is the Ascii Renderer class meddling in cell mine logic? `cell.neighbour_mines.zero? ? "_" : cell.neighbour_mines` should be its own method in a `Mine` class that is properly tested"<p>You're never allowed to just write code that solves a problem. It never ends. Your team has unlimited authority to slow you down with completely useless "feedback" that does not help anyone.