News for hackers. Stuff that matters.
Re:Show HN: Simple JavaScript Tetris by jstimpfle on Wednesday November 02, 2016 @12:47PM (#12856742)
EDIT: Better URL https://github.com/jstimpfle/tetris-on-a-plane/

I had fun building this and experiencing the joyful side of JS (or at least the browser ecosystem). Boarding a plane I'd had the idea of finishing a simple tetris before arrival. The game was in a working state after ~2 hours, even though I had made a few bad decisions. (it was subsequently polished, investing another few hours).

It was made with a "get things done" mindset, and the experience from dabbling with purely functional programming in Haskell was very helpful (mostly the "pure", as in "non-destructive", part).

It's nice that in Javascript we have an environment where we can code a fun game in <400 lines, without any library dependencies (not even internet connection needed) or build systems. On the downside, if it had stronger dynamic types and errors (like Python) that would have saved maybe 25% of my debugging time, probably without coding overhead.

Re:Show HN: Simple JavaScript Tetris by zzguy on Wednesday November 02, 2016 @02:46PM (#12857975)
Had you made Tetris before? Or used an external resource to see any pseudocode? Reason I'm asking is, I was doing a similar thing with Snake and it took me a bit longer (probably 4 hours) because I messed up the basic mechanics in the beginning (I didn't think of how to structure the growing body as a linked list). I want to gauge how much I suck (at least at games programming) lol.
Re:Show HN: Simple JavaScript Tetris by jstimpfle on Wednesday November 02, 2016 @03:00PM (#12858143)
I once spoke about it with a friend who had to do it in C. However C is a dangerous trap here, I think it gets you in the wrong mindset.

Data representation is pretty universally one of the most important things (basically the "design" part to me). Four hours is pretty quick I guess. Snake might be more difficult (but an array or llist + snake direction + board map should be straightforward). I'd done chess that week and the representation is also doable unless thinking about AI or history or... which is when I quickly go bikeshedding. Multiple different representations for different tasks (and transforming in between) might be a way to go.

Re:Show HN: Simple JavaScript Tetris by pgt on Wednesday November 02, 2016 @05:43PM (#12859607)
I made Snake in 103 lines of ClojureScript for a talk once: https://github.com/pate/cljs-snake (LOC excludes whitespace and links to repo). Comes in under 100 LOC if you strip out the aesthetics.
Re:Show HN: Simple JavaScript Tetris by jstimpfle on Wednesday November 02, 2016 @06:55PM (#12860136)
Very nice!
Re:Show HN: Simple JavaScript Tetris by rbirkby on Wednesday November 02, 2016 @06:34PM (#12860018)
Check out the encoding of the tetrominoes in this implementation: https://github.com/jakesgordon/javascript-tetris

My subsequent port to C and Arduino was very natural: http://youtu.be/t3QOeQbEHVs

Re:Show HN: Simple JavaScript Tetris by electrum on Wednesday November 02, 2016 @08:16PM (#12860570)
Here's one I wrote a long time ago in Z80 assembly for the TI-86 graphing calculator: https://gist.github.com/electrum/76ac88de2e1d6c9254deaba003a...
Re:Show HN: Simple JavaScript Tetris by bbcbasic on Wednesday November 02, 2016 @08:43PM (#12860693)
The "Random" subroutine looks surprisingly simple
Re:Show HN: Simple JavaScript Tetris by agentultra on Wednesday November 02, 2016 @02:37PM (#12857889)
It is pretty cool. Feels very much like a smalltalk-ish environment. A WebGL context is a single HTML tag and a couple of lines of code away. However you can still get the productivity boosts from an ML-like language... there are options. And ES6 supports some patterns of FP out of the box (though it is made better with small library support).

Maybe checkout Bucklescript, Purescript, or Elm for the next one :)

One of my rituals of taking a long trip is to finish a small coding project before I land. Sudoku, minesweeper, tetris, forward-propagating constraint solvers... it's a nice practice. Thanks for sharing yours!