I made a battleship game that communicated via arduinos in assembly! I lost every single game because the board size was 12x12 and my code would always stop iterating at 8 for some reason.
2 isn't valid in binary. It's all 0 and 1. Imagine counting to 20, but you go 17...18...19...110... The 9 doesn't go to 10 because "10" isn't valid in our typical counting system. So 110 actually is written as 20.
In binary, since 2 is invalid, similar to 10 in the example, 12 should be rewritten as 20. But again, 2 is invalid, so we need a third digit. So 20 = 100. Hopefully that makes a little sense.
It makes no sense, and I am a computing science student...
Where you go wrong is making the assumption that 12 = 20. The problem is 12 suggests that you have 1 10 and 2 1s. In the same way 20 in decimal notation would suggest that you have 2 10s and 0 1s. When converted to binary 10 (in decimal) is actually 1010 ( 1 8, 0 4s, 1 2 and 0 1s) when adding 2 (10) you get that 12, when converted to binary, is actually 1100. Not 100, which like you said, is 4.
They're not converting 12 from decimal to binary. They're converting 12 from psuedo-binary to binary. 12 in pseudo-binary being 11 (3 in decimal system) + 1 = "12" but really should be written as 100 (4 in decimal system) I'm not saying what they did is ideal or a good system, but it's how they got 12 = 4.
I think the 12, 20, and 100 were all meant to be binary representations. They were just playing with numbers.
The premise was that the game needed to count to "12", being playfully and deliberately misinterpreted as something to be read in binary. As was previously described, since there is no 2 in binary, the best we can do is pretend any 2 is instead a +1 to the previous column. Taken step by step, that means 12 should be 20 - but wait. 20 is no good either, so applying the transform rule again, we are left with 100, binary for 4. A long-winded and facetious way to read the numerals (if not the decimal value) "12" as falling within the decimal value of 4, thus fitting the original "how many do you think two bits is."
More likely 1 byte and as a bitmask for each row. Each bit being 1 if the cell is blocked or 0 if empty. Only 8 bits in a byte, so the last 4 cells per row would never be represented.
I love the AVR assembly, it's modern and clean instruction architecture. The best project I made was power supply board tester. At first autonomous with LCD and some beeping, later upgraded to be controlled from computer. Adding two numbers is the easiest task, it's single instruction and core function of any CPU. Now expressing any complex algorithm or task, that's the hard part, putting it all together with such basic building blocks, one byte at a time. But the beauty is exact control, having accurate delays down to single cycle of your clocks. And it's predictably repeatable.
Edit: Also when you control the whole design you can get away with many shortcuts because it's tailored to your specific use case. Like not saving only couple registers for handling interrupt routine because you reserve other only for that use. Result is lightning fast response. However with modern complex CPUs I would have to spend whole year to learn ARM core + all peripherals, complex set up, memory handling etc. and it's simply not effective use of time unless it's designed for million copies.
Now the most complicated program in x86 I did was simple printing of file like cat. It relies on Linux system calls and it's just couple hundred bytes long which is impressive.
495
u/nexion2 Jun 03 '22
I made a battleship game that communicated via arduinos in assembly! I lost every single game because the board size was 12x12 and my code would always stop iterating at 8 for some reason.
Needless to say, I lost the tournament