23 ms·
NandGame – Build a Computer from Scratch
- carls 6y agoI've done the Coursera course, Nand2Tetris, that inspired this website [1] and found it deeply intellectually satisfying and engaging. If anyone is interested in learning about the logical primitives that build up to a computer, and how they're implemented using logic gates, I would deeply recommend the course! ----------- [1] https://www.nand2tetris.org/ https://www.nand2tetris.org/
- phaemon 6y agoSeconded. And a quick note that this course is based on the book "The Elements of Computing Systems: Building a Modern Computer from First Principles (The MIT Press)"
- brian_cunnie 6y agoSeconded a second time. Very hard, and very worthwhile.
- avmich 6y agoCourse materials (projects) seem to contain only slides, with bullet points, not real explanations. Am I missing something? Should I buy the book to actually have the course?
- fuyu 6y agoYou are probably looking for the videos on coursera [1]. [1] https://www.coursera.org/learn/build-a-computer https://www.coursera.org/learn/build-a-computer
- ngcc_hk 6y agoThanks. Even though I am not the op
- Jtsummers 6y agohttps://www.nand2tetris.org/course https://www.nand2tetris.org/course There are PDFs of each chapter for each project. The icons are (left to right): project, slides, chapter.
- avmich 6y agoGot it, thanks! The whole rectangular felt like a single object, and I always clicked in the center, so missed the other parts.
- wrycoder 6y agoYou don’t really need the book for the first half of the course, but I found it very helpful for the second half. More so than the vids, which got boring due to repetition.
- userbinator 6y agoFor a more accessible yet also very comprehensive book, see Petzold's Code: http://www.charlespetzold.com/code/ http://www.charlespetzold.com/code/
- JamesSwift 6y agoWhenever someone asks me how a computer works, this is what I tell them to read. No need to qualify the recommendation on their background, the book is accessible to anyone because it starts from first principles and builds layers on top.
- trungdq88 6y agoThis is an incredible course to learn about low level stuff like computer architecture, micro OP codes, machine language, assembly code, virtual machine... I implemented the course[1] in Logism[2] but unfortunately the simulation is too slow to run Teris! [1] https://github.com/trungdq88/16-bit-computer https://github.com/trungdq88/16-bit-computer [2] https://sourceforge.net/projects/circuit/ https://sourceforge.net/projects/circuit/
- evangow 6y agoAwesome! I've always thought it would be interesting to port Nand2Tetris to the web to make it more easily accessible. Glad someone finally ported the virtual computer building part!
- blackrock 6y agoI wonder when we can start 3D printing our own resistors and transistors.
- artemonster 6y agoThey already are. Most lithography processes are additive, including making the active components themselves (is some applications, not in general)
- ducktective 6y agoI'm no expert in this field but I think the challenging part in IC design is the light-based lithography process that makes integrating large numbers of transistors possible...so I guess the 3d printing part is not the limiting factor.
- bobsmooth 6y agoYou can do photo-lithography at home. Applied Science has a few videos on the subject.
- deleted 6y ago[deleted]
- djmips 6y agoThis might be of interest although quite an investment in both knowledge and equipment. Home built IC. http://sam.zeloof.xyz/first-ic/ http://sam.zeloof.xyz/first-ic/
- berkserbet 6y agoReally cool, curious to see how hard it gets. Reminds me of college.
- libria 6y agoSame, specifically the Patterson and Hennessy course. Good to see this material being accessible for younger minds though.
- dkersten 6y agoI find that it actually gets easier as you get further along, because you start using higher and higher level components. The hardest (to optimise, not to implement) for me were the components just after the basic gates (counters, latches, etc).
- linkdd 6y agoThis looks a bit like MHRD [1] but with a GUI :) ---- [1] https://store.steampowered.com/app/576030/MHRD/ https://store.steampowered.com/app/576030/MHRD/
- Nullabillity 6y agoSilicon Zeroes[0] is also a pretty good next step if you enjoy these games. Doesn't quite get down to the NAND level, but gets into a lot of fun performance optimizations instead. [0]: https://store.steampowered.com/app/684270/Silicon_Zeroes/ https://store.steampowered.com/app/684270/Silicon_Zeroes/
- linkdd 6y agoI'm currently wasting my time on screeps, but I'll take a look, thanks :)
- zn44 6y agoI was just going to post the same link here ;) Great game highly recommended
- simonbarker87 6y agoSome of my favourite courses of undergrad were Digital Electronics 1 and 2. How you can build everything up from nand gates is so satisfying, I’ve forgotten much of it now but this is bookmarked to come back to for posterity
- IIAOPSW 6y agoThere was this ancient Flash game called "Engineer of the People" that was all about designing IC circuits (NPN and PNP junctions) in the Soviet Union for some secretive reason. I never beat the game and got to the reveal. IIRC it was by Zachtronics, the same guy that did Shenzhen I/O and infiniminer (the inspiration for Minecraft).
- Jorge1o1 6y agoI also played his chemistry/alchemy games SpaceChem and Codex of Alchemical Engineering. Highly recommended.
- qq4 6y agoOh man, I was hooked the moment I played SpaceChem. I think that game and Kerbal Space Program are responsible for reigniting my interest in math and computers.
- justQandA 6y agoAny links as to where one can play this game?
- etcet 6y agoIt's on http://www.zachtronics.com/kohctpyktop-engineer-of-the-people/ http://www.zachtronics.com/kohctpyktop-engineer-of-the-peopl... Also available to play using Flashpoint (https://bluemaxima.org/flashpoint/ https://bluemaxima.org/flashpoint/) if you don't want to try to install flash on your regular browser.
- krallja 6y agohttp://www.zachtronics.com/kohctpyktop-engineer-of-the-people/ http://www.zachtronics.com/kohctpyktop-engineer-of-the-peopl... It’s also part of the “ZACH-LIKE” anthology on Steam.
- thuongleit 6y ago
- ducktective 6y agoFor anyone interested, also check out this computer designed in Powder Toy game! https://www.youtube.com/watch?v=h4eHgnLFk9k https://www.youtube.com/watch?v=h4eHgnLFk9k
- BitwiseFool 6y agoThis was so much fun! It brings me back to my first class in digial logic.
- gdcohen 6y agoThis is really cool. You've done a tremendous job in making this very usable (I love your yellow sticky note instructions).
- Sniffnoy 6y agoBuilding circuits is neat, but I think this has some problems as a game: 1. It seems to only let you save one solution for each level, even though there are two optimization goals. It should let you save one for fewest components and one for fewest NAND gates. 2. It's not really clear how NAND gate counts work in later levels where you're using potentially non-optimal components you've built? Like does it count each one as the number of gates that you used, or the number of gates that is optimal, or what? Someone else told me it was the latter, but it seems like XOR counts as 6 even though there's apparently a way to do it with fewer? 3. Why do some levels give me the message "This is optimal!" while others say "This is the simplest solution!"? What's going on here? What do these messages mean specifically? It's not clear. All this adds up making attempts at optimization a bit frustrating and as such I just don't really want to play it very far. If you're not worried about optimization it seems fine, but if you are the interface really kind of works against you.
- rustyminnow 6y ago> it seems like XOR counts as 6 even though there's apparently a way to do it with fewer? This is a great game and tbh I think you're just butthurt because you couldn't figure out any of the optimal solutions. Xor is the first one and it sounds like you didn't solve it. (fwiw I haven't figured it out yet either) 1. It does only save one solution for each level but if you can do it in fewer nands, why do you need to keep the fewest components? Most puzzle games like this work this way 2. In later levels it uses your best solution from previous levels. The basic (non-optimal) xor solution has 3 compents with 6 nand. The first time I did half-adder, it told me my solution was 2 components/8 nand (a 2-nand AND plus a 6-nand XOR). After trying for optimal xor again (and failing), solving half-adder shows "2 components used. Mission XOR is not completed, so the total number of gates could not be counted." So it uses YOUR best solutions. 3. I mean it's pretty obvious. optimal == fewest nand, simplest == fewest components. If you optimize for nands, your solution is going to be less simple/more complicated. I think it's a really great game. You should give it another try
- magnostherobot 6y ago> Most puzzle games like this work this way As far as Zachtronics games go, you've been able to save multiple solutions since IIRC Infinifactory, and those games all have two or three optimisation goals. I think Silicon Zeroes only remembers one solution per puzzle, however in most of its levels its goals are quite closely related. OCTOPTICOM also only saves one solution per level, but only has one optimisation goal, I believe. I don't believe your assertion is true; at the least, it is not true in my experience.
- hnick 6y agoThank you for showing me how much I have forgotten in 15 years :)
- bstrong 6y agoVery cool! Reminds me of all the fun I had with Rocky's Boots on Apple II: https://en.wikipedia.org/wiki/Rocky%27s_Boots https://en.wikipedia.org/wiki/Rocky%27s_Boots
- cadr 6y agoI wish there was a reboot of that on ios.
- rzach 6y agoLove this - I actually started implementing these circuits in C [0] a while back but never got past combined memory. [0]: https://news.ycombinator.com/item?id=23672470 https://news.ycombinator.com/item?id=23672470
- ElHacker 6y agoI got excited when I saw the title, then checked the URL and it is a software simulation / game of building a computer. I'm not denying this can be interesting, but I've been thinking for a while to get my hands dirty with hardware as a side project. (I'm a software eng by profession). I haven't really done a lot of research on this yet, but does anyone have any recommended guides/books/tutorials on how to get started designing and building my own computer? (extra points it it's a mobile/embedded computer)
- dghlsakjg 6y agoCheck out Ben Eater on YT. He has a series where he builds an 8 bit CPU from components. And another where he builds a 6502 based computer from scratch. He sells kits to follow along, and explains everything along the way
- chrisdalke 6y agoRecommended the exact same thing -- I'm glad I'm not the only one who immediately thought of his channel.
- chrisdalke 6y agoIf you're a visual learner, check out Ben Eater's channel: https://www.youtube.com/user/eaterbc https://www.youtube.com/user/eaterbc He has a really great video series where he builds a small computer from scratch on breadboards. Also some other highlights: Reliable data transmission, more educational: https://www.youtube.com/watch?v=eq5YpKHXJDM https://www.youtube.com/watch?v=eq5YpKHXJDM DIY VGA "video card": https://www.youtube.com/watch?v=uqY3FMuMuRo https://www.youtube.com/watch?v=uqY3FMuMuRo Super educational, but if you want to get into more embedded hardware hacking, I would say that building a homemade computer like he does is probably not a super exciting place to start. I'd recommend picking up some Teensy 4.0 microcontrollers and build some small hardware projects with the microcontroller before diving into lower-level circuitry.
- amelius 6y agoThe first question you'll need to answer is if you want to build a computer from discrete gates, or if you'd rather glue large existing IP blocks together. In the former approach, you won't get anything in a mobile form factor, as your computer would simply be too big. But you might learn more than in the latter approach.
- zug_zug 6y agoThere's a very similar game(text-based) called MHRD
- LeonB 6y agoShould start from physics building up and up until you have subatomic particles, rising through many layers of abstraction until you are doping P and N type semiconductors .... starting with such a high level concept as “nand gates” is far too easy. /sarcasm.parody
- dane-pgp 6y agoSeriously, though, having a few (optional) levels covering from chemistry up to nand gates would really add depth to the game.
- signaru 6y agothis would be good material for a book, where in the end, the reader gets to output "hello world".
- LeonB 6y agoOk I’ve added it to my list of possible book ideas. But it’s already a list that’s grown far beyond a lifetime’s output. (“From Higgs Boson to Hello World” as working title.)
- imtringued 6y agoReal men invent the laws of physics from scratch.
- ghostDancer 6y agoIn the style of the famous Carl Sagan's apple pie recipe. "First you create an universe ..
- the_only_law 6y agoNot gonna lie, I wanted to do something like this, but then remembered how bad at math and physics I was. On a random note, I find it disappointed the tiny of amount of physics material on MOOC sites and such.
- sergex 6y agoAuthor here - I would love to do a few layers below the nand gate.
- radicalriddler 6y agoI did logic gates as part one of my first uni courses in I.T. The assignment was actually so fun, I hated when I finished it.
- newman8r 6y agothis is fun. When I got to the multi-bit-adder I think the half adder was removed from the toolbox though and replaced with the full adder - would be nice to keep it there.
- iKlsR 6y agoIf you like this or want to get into it a bit more, this recent video is lovely https://www.youtube.com/watch?v=QZwneRb-zqA https://www.youtube.com/watch?v=QZwneRb-zqA
- Koshkin 6y agoI find using an FPGA for this an ideal middle point. Building a functional computer from discrete components is fun but the result may not be worth the effort, to be honest. At the other extreme, modeling it in software may leave a weird feeling of not having achieved anything. With an FPGA, on the other hand, you can create something of a usable computer, even one you could run Linux on.
- mikewarot 6y agoThat was a fun diversion, thanks!
- deleted 6y ago[deleted]
- kayson 6y agoNot that this will ever matter for someone who isn't a circuit designer, but the "optimal" solution for the latch is actually really bad. If you use a "select" block (which should really be called "mux") and tie the output to the input, you create a race condition. If the data input is 1, and you change set from 1 to 0, the output can actually glitch to 0 for a very short period of time, which is a big no-no. (If you draw the equivalent circuit out with just nand gates and assume they all have some delay between input and output, you'll see why). A safer solution would be to cross couple two nand gates into an SR latch [0], use another two nand gates to control the Set and Reset signals, and an inverter to create NOT(data). Of course in reality, a latch is usually custom built out of transistors rather than logic gates, but there are some cases where I've used logic-gate-latches to make things easier. </pedanticism> [0] http://electronics-course.com/sr-nand-latch http://electronics-course.com/sr-nand-latch
- sitzkrieg 6y agoin the yearly reposting of this on hn i always am annoyed to remember some of the best-on-paper isms of the book
- jsmith45 6y agoSince the latch is only used as a component of the flip-flip and edge sensitive logic does not care about glitches except on the clock line or any asynchronous set/resets (which are not used in this design) I find that rather unimportant. Especially because the d-flipflops found in standard cell libraries are frequently implemented as what amounts to two muxes and some inverters. For a design that uses latches as stand-alone components the glitch considerations become a lot more important.
- kayson 6y agoIn practical designs, flip flop outputs are regularly used as clock inputs and asynchronous set/reset inputs. If you used this latch as the output latch in a flip flop, it would glitch on the falling edge of the flip flop clock. I didn't go through the entire game, so its entirely possible that it would not affect this particular "design". But as its far more educational than practical, I think its still worth mentioning. > Especially because the d-flipflops found in standard cell libraries are frequently implemented as what amounts to two muxes and some inverters. I'm curious where you've seen that implementation because I've never seen anything like that. Most of what I've seen uses two tri-state inverter latches.
- tunesmith 6y agoNicely done! If the author is reading, care to share any details on what stack or libraries were used?
- sergex 6y agoAuthor here - It uses TypeScript and the Angular framework. Not because I prefer Angular in particular but because I had to learn it anyway for a work-related project. I think TypeScript is great.
- tunesmith 6y agoIt looks like it is more canvas than svg, yes? Was there a particular canvas library that you used? I ask because I'm working on a side project that feels like it mostly pulls me in an svg direction, so I'm been prototyping with dagrejs and cytoscape.js, but it also has elements of creating (or dragging, like yours) new elements into a graph and connecting them, so I'm regularly torn when deciding on the basic architecture of it.
- sergex 6y agoI'm not using canvas. SVG is used for the connections, the rest is HTML. I'm not using any particular library for the diagrams, since I couldn't find anything suiting my purpose unfortunately. I would definitely like to improve the look of the wires.
- tunesmith 6y agoThanks for replying! Continued good luck with the project.
- userbinator 6y agoI know digital logic, yet was perplexed by the odd definition of D flip-flop this game uses with both "store" and "clock" inputs, which matches none of the standard variants of DFFs: https://en.wikipedia.org/wiki/Flip-flop_(electronics)#D_flip-flop https://en.wikipedia.org/wiki/Flip-flop_(electronics)#D_flip... Edit: this continues on with the counter level, where you can use the register but it does not behave like the typical set of edge-triggered flip-flops (or transparent latches) that one would normally use. My best attempt at coming up with an explanation is that it's like two-phase edge-triggered logic.
- jsmith45 6y agoYeah. The flip flop, and its corresponding register version would be a DFF with enable pin. That is not actually too abnormal. The traditional implementation is taking a normal DFF and adding the enable feature either by gating the clock or by adding a mux in the input path, that uses the enable signal to select between the input or the existing output.
- userbinator 6y agoEverything started making sense after I thought of "store" as "enable", and I made it to the end pretty quickly after that --- except for the "bonus" multiplier level, which is definitely possible but seems like it would take about 10x as much space as the canvas allows.
- signaru 6y agoit would be cool (ambitious) if at some point there is also a programming language/compiler down the line. perhaps it can would also be able to run tetris or even another nandgame.
- yellowapple 6y agoSo I'm a bit confused with how this is measuring the number of NANDs; for example, with the first adder problem, I solved it with exactly two gates, neither of which were NAND, and yet while it's recognized as the lowest number of gates, it insists that it can be done with fewer NANDs (than zero, apparently). Is it counting the NANDs that may or may not be used to implement those two gates? And if so, is that based on how I solved the previous problems? Or is it based on the lowest possible number of NANDs that would be required to solve those problems / produce those gates? If it is indeed counting the NANDs used to make the gates I actually used, it'd be useful to have a clear indication of exactly how many NANDs each gate uses so I can chase after a game of NAND Golf. In any case, this is fun :)
- noncoml 6y ago> If it is indeed counting the NANDs used to make the gates I actually used This > it'd be useful to have a clear indication of exactly how many NANDs each gate uses You learned that as part of your first section exercises. At the end of the day everything is made of NAND gates. That’s what the first section teaches you.
- Turing_Machine 6y agoIt would be nice if that information were available in later stages, without having to take notes. I'd like to see the ability to "unbundle" the composite components. Maybe an intermediate pin in (say) the XOR or half-adder has exactly the signal you need to save a component in a later stage.
- sergex 6y ago> I'd like to see the ability to "unbundle" the composite components. This is a great idea, and you are not the first to suggest it. I just haven't gotten around to implement it.
- jzer0cool 6y agoWhat might be some logical next steps to do, learn, or make (preferred) after learning some basic circuit logic?
- MaxikCZ 6y agoBuilding 8 bit computer from scratch? Ben Eater has amazing way to teach and walk you trough it. https://eater.net/8bit https://eater.net/8bit
- jzer0cool 6y agoI began this a few years back. Agree with the teaching style, it's amazing. I felt getting a good grasp at the inner workings of some of this chips!
- noncoml 6y agoThere are 10 kind of people. Those who like to drag from the input back to the output and those who prefer to drag from the output to the input.
- mkl95 6y agoI have fond memories from reading this book and doing the exercises. I never got past building RAM memory though :-) It's worth mentioning that the book is getting a extensively revised (sic) 2nd edition in July 2021. * https://www.amazon.com/Elements-Computing-Systems-second-Principles/dp/0262539802 https://www.amazon.com/Elements-Computing-Systems-second-Pri...
- Hitton 6y agoI love this game. And was the UI improved since the last time it was posted on HN or am I misremembering it?
- sergex 6y agoYes it has improved a lot. Still more improvements to come!
- AQXt 6y agoThat's the coolest thing I have seen today. Thanks! :) Suggestion: replace the blue button text ("I have completed the level") with something simpler, like "Run", "Check", "Test" or "Go".
- pteraspidomorph 6y agoThis isn't working very well for me on firefox. The components don't seem to want to be dragged.
- ColinWright 6y agoIt probably sounds petty, but I found it disturbing that inputs are at the bottom ... I was constantly having to readjust my thinking, and have become sufficiently frustrated to give up.
- herghost 6y agoI was able to get as far as building the half-adder, but then didn't have the means of figuring out the full adder as that seemed massively more complex.
- vishnuharidas 6y agoReminds me of Ben Eater's Youtube videos where he builds everything using basic gates on a breadboard. He made a video-card using ICs on a breadboard that fascinated me: https://www.youtube.com/watch?v=l7rce6IQDWs https://www.youtube.com/watch?v=l7rce6IQDWs
- mathattack 6y agoI used this with several elementary school kids who enjoyed it very much.
- dusted 6y agoThis is fun! But, the first few told me "this is the optimal solution", then I hit the xor gate, and I can get either "this uses the fewest nand gates but it can be done with fewer components" or "this uses the fewest components, but it can be done with fewer nand gates".. Does this imply that there is no optimal solution, or just that I've not yet found it?
- DNied 6y agoI wish Pure Data had a GUI like that. Hats off to the author.
- mtoner23 6y agoI'm a simple man. i see NandGame i upvote
- h_anna_h 6y agoThe test in the opcodes level is incomplete as for X-Y it accepts ~(X&Y)
- rkagerer 6y agoNeat! My only complaint is I feel like it would be more intuitive to be able to drag connections from output to input. I understand why it's the other way around (each input can only have one source, while outputs can go to multiple chips) but it still feels backwards - like reading right to left.
- wolfgke 6y agoA quite similar game in Steam: MHRD https://store.steampowered.com/app/576030/MHRD/ https://store.steampowered.com/app/576030/MHRD/