The Art of Redundancy

            [oo ]    [oo ]    [oo ]    [oo ]
            <   >    <   >    <   >    <   >

            [ oo]             [ oo]    [ oo]
             > <               > <      > <

            [oo ]    [oo ]    [oo ]
            <   >    <   >    <   >
 
               V
                         V

                                V
                                   ^



                                <_I_>

In 1981 I coded a Space Invaders clone for the Apple ][ Europlus. I knew I should not have used Microsoft’s super slow Applesoft BASIC, but I just did. It was an animated ASCII-art program with a main-loop moving 12 invaders, the defender, the up-bullet and the five down-bullets. The latter two with collision detection and scoring. However it was not fast enough. I then tried, what I now would describe as redundancy. I replaced the code that printed the 12 invaders one at a time with one that would print 4 at a time (i.e., a whole row). I used ON (II%*2+FF%) GOSUB to go to any of the (2^4)*2 “subroutines” that would print the correct row. That made the game totally playable. It taught me that redundancy is not always a bad thing.


  1. John says:

    Loop-unrolling, the old-fashioned way!

    instead of
    do twelve times
    print-alien;
    enddo

    you did
    do three times
    print-alien
    print-alien
    print-alien
    print-alien
    enddo

  2. coder says:

    Yes, but in a supercharged form.

    First I tried loop unrolling like this:

    ? LEFT$(” “, IN%): IF IN%(1) THEN ? “[ oo]” ELSE ? ” ” : ? ” ”
    ? LEFT$(” “, IN%): IF IN%(2) THEN ? “[ oo]” ELSE ? ” ” : ? ” ”
    :
    :
    ? LEFT$(” “, IN%): IF IN%(1) THEN ? “> < " ELSE ? " " : ? " "
    ? LEFT$(" ", IN%): IF IN%(2) THEN ? "> < " ELSE ? " " : ? " "
    :
    :

    But than I realized I could write 16 GOSUB-routines that would print all the invaders of one row. Like so:

    300 ? LEFT$(" ", IN%): ? "[ oo] [ oo] [ oo]"
    302 ? LEFT$(" ", IN%): ? "< > <> <>”
    304 RETURN

    310 ? LEFT$(” “, IN%): ? “[ oo] [ oo] ”
    312 ? LEFT$(” “, IN%): ? “<> <> ”
    314 RETURN

    320 ? LEFT$(” “, IN%): ? “[ oo] [ oo]”
    332 ? LEFT$(” “, IN%): ? “<> <>”
    334 RETURN
    :
    :

    I also had 16 GOSUB-routines for the left looking invaders.

    But you are right. Loop unrolling is a form of redundancy I used, with some other code redundancy.

    Coder

  3. coder says:

    Hummm, the wiki kills my layout. (Never use spaces to do your layouting!)
    Maybe this works?

         [oo ]     [oo ]

  4. coder says:

    Jup, using <pre> works in comments. One other thing learned, only a googel to go. :-)

Leave a Reply