Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here we go again. Someone says "minesweeper". I shamelessly plug my js implementation: http://www.ronilan.com/bugsweeper/ Don't ask me why.

P.S - it's with bugs instead of mines just because fontawesome didn't have mines. No puns intended.



I've got one too [1]. Your's looks much nicer than mine. I'm just an occasional dabbler in JavaScript, so it is not surprising that mine is crude.

I wrote that after reading this HN discussion [2] where someone was describing how they interview. They set the candidate up with a good JS development/test environment that the candidate is comfortable with, and ask them to implement as much of Minesweeper as they can in one hour. They also said no one has ever finished in that one hour.

As expected, I did not come anywhere near doing it in an hour. Wall time was about 7 hours, but I was doing other things during that, so it was about 4 hours working on Minesweeper. About an hour of that was testing and stumbling around the Mac character viewer trying to find good characters for bombs, flags, and such.

I'm kind of surprised no one has done it for the interviewer in an hour.

As I said I'm only a JS dabbler. Basically, every couple of years or so I'll have to do a little bit of basic JavaScript to do some simple DOM manipulation or form validation. That's just enough to keep me sufficiently aware of JS that I can at least do some reasonable guessing and googling.

I'd expect an actual JS programmer to be much faster than me.

[1] https://github.com/tzs/interview_minesweeper

[2] https://news.ycombinator.com/item?id=10752564


I just tried a version of this as a test for myself. I was able to create a very serviceable minesweeper clone in pygame, finishing up at almost exactly the 1 hour mark.

I didn't have time to include a game-over animation, an in-game timer, or a way to select different settings, but the core mechanics were all there.

Pygame is a very nice environment for games programming when you want to do something fairly simple.


I think I'd panic if I got that question in an interview. Where do you start with that? What are the first steps? How did you know what to Google?


It sounds like a test of your ability to abstract, componentize, and prioritize. Here's a possible approach to this sort of problem:

Read a brief summary of whatever you are implementing, even if you are already familiar. This will help you understand the breadth of the problem.

Try to list in very broad terms the data structures you will need to store the state of the problem (e.g. for Minesweeper, a grid of tiles, and for each tile some status). Don't worry about whether you are using a list or a vector/array or sparse or dense matrices, just be as generic as possible.

List in very broad terms the logic of the problem. What states exist, what are the beginning/ending conditions (start/playing/win/loss), very roughly how states transition, etc. Again, avoid detail.

Identify the inputs and outputs of the problem, very broadly (e.g. user input, display for game board -- no mention of mouse, keyboard, HTML, or whatever).

Cycle through these phases a few times until they seem to agree.

From there, go wherever your brain takes you, progressively filling in details of your design. You probably still shouldn't start coding.

For a 1hr exercise, let's assume you've used 15 minutes for the design phase. Now you can begin coding. Start with the very core of the problem, writing data structures and logic around those data structures. Then get some way of displaying them and manipulating them so you can debug with feedback.

With a roughly functioning core, start filling in the rest of the design. Focus on what makes the biggest functional difference with the least effort first, if at all possible, but again, follow your brain. Try not to pick fonts before you've got everything running. Go piece by piece, until time is up.

--

As for what to Google, you'll need to know how to interface with your problem's input and output systems (like a browser), and maybe how to run timers or store your particular data structure, but most of the work is design, not research.

--

For a personal story, several years ago I failed a similar test in an interview. They asked, "How would you make an elevator?" I got lost in the details like what type of screw terminal to use for electrical contacts, and only later realized the value of prioritizing layers of abstraction. Breadth-first search, not depth-first, if you think of a problem space as a graph.


I pointed this out before the last time you plugged your implementation.

It has a bug in it. If you right click (place a flag) then right click (remove that flag) then left click, it places a flag instead of revealing.


I fixed it. Now, there are no known bugs.


I'm the same way with my solitaire game!

https://solitaire.gg

We should build a collection of web remakes of the built-in OS games.


This was my first try: http://imgur.com/a/EQsm8

I guess I should not buy lottery tickets today


I got a bomb on my 2nd random click.


Just an interesting tidbit - you can't bomb (bug) on first click. If you hit one, the board is reshuffled so that your first click is good. Apparently this fantastic UX feature was part of the original game. When someone pointed that out first time I posted it here - I just had to add it.


You ratbag, you just cost me 10 minutes. :P

Nice implementation though. :)


The delay in the click sound is so annoying.

Edit: only delayed in Safari.


Every time I read a minesweeper article I let my browser autocomplete "mines" to go to your program. Thanks for making it!


Hmm, I seem to hit corner bugs a lot but in minesweeper the corners never had mines (which was like the whole initial strategy)


Corners in minesweeper always had the same chance as any other square to be a bad choice even the example in the main article shows a corner mine


Nice :) - FYI though with Chrome on macOS marking a flag works, but also opens the context menu.


Looking into it I'm guessing you had console open and in mobile mode (pointer is a dot). Right? In that case there is no "right-click" event in the document context. If you want console open and desktop mode, there is a little icon there to "Toggle device toolbar". Digging into Chrome tools, what a way to spend Sunday night!


Nope, console was closed. But going back to it, it's fine now! Very strange.

(The game state saved in local storage, very nice :))


that page is blank unless you allow ajax.google.com....


That's like half of the internet these days.


Probably not half, but way too much. I'm hoping that the recent Amazon downtime will help put the breaks to this trend.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: