Simon Sings -- brain in a box

Everybody knows that computers are smart. But did you know that very small and very smart computer chips are making many of our toys, our appliances, our educational systems, and even our cars more intelligent? This program takes you inside the microchip and shows you how your computer can be used to program a game that is smart enough to adjust automatically as you play it.


Simon Sings -- instructions for running the program

One of the first really popular hand-held computer games was a simple box with buttons and flashing lights. The game played a tune, starting with one note and adding a note each cycle. Your task was to try to match the tune and the flashing lights. As the game progressed, the tune got longer and more difficult to remember.

If you play well, my version will make the game more difficult and more challenging. Fail to get the tune right and the tune you guess next time will be shorter and easier. After only a few rounds the game will adjust itself to your skill level, allowing you to win about two-thirds of the time.

This self-adjusting feature means that I don't have to decide once and for all how difficult to make the game. By writing a program that lets the computer decide how easy or hard the game will be, I can create a game that many different people with many different skill levels can enjoy.

Our version uses the number keypad as the buttons and the image on the screen. Run the Simon Sings program, then press any key to start it with the first note in the song you are trying to guess. Try to match the tune and the buttons as the computer continues to challenge your memory and dexterity.


Run the Simon Sings program.

After you've finished running the program, press the Esc key to stop and return to this page.


See how it runs -- the flowchart

You can see right away that there are three program loops and two ways to restart the program in this software design. The possible endings are easy to recognize. You can either win the game by guessing all the notes correctly or you can lose by making three errors in a row. Either way, the program will restart with a new tune for you to guess.

The three program loops regulate the difficulty and make this game either fun or frustrating. The inner loop that includes the keyboard is the section of the program that inputs each note you type on the keypad, compares it with the next note in the computer's tune, and decides if you have made a mistake or not. If you have made an error, the next decision is based on how many errors you have made in a row.

Less that four errors and the computer plays the song again, giving you another chance. Make more than four errors and the program plays a "dribble" sound effect before it restarts with a new tune for you to guess.

When you have finished copying all the notes in the current song correctly, the computer makes another key decision. If there are more notes to be added, the computer loops back, adds the next note, plays the new song, and lets you try to copy it correctly. If there are no more notes, then you have solved the tune correctly. The You Win! box plays a victory tune before starting over with another series for you to guess.

In the Restart section, the computer makes an important decision that is not shown in detail in this flowchart. If you guess the tune correctly, the next tune is longer and more difficult. End with an error and the next tune will be slightly shorter and easier for you to guess. In this way, the program is adjusting the difficulty as you play.


Computer magic -- feedback programming

Perhaps "magic" is too fancy a word to describe the way this program adjusts to match the person who is playing the game. But the effect of this simple change can make all the difference in how this game feels to everyone who plays it. By simply changing the length of the tune, the program changes the difficulty and the challenge you face. In this way, the "same" program pays attention to who is using it and will adjust itself to match each person.

If you are really good at playing Simon Sings, the game will continue to expand and match your skill level, giving you a game that stays challenging and interesting. For people who are less skillful, the game adjusts the length of the tune to match their abilities as well. The net result of these adjustments is that the game, like the best of the three bears, is not too hard, not too easy, but just right.

I call this technique of adjusting the software to match the user feedback programming. This is a technique I use in many programs to model or change them to match each individual. In the original Typing Tutor program, for example, I used feedback programming to adjust the typing lessons automatically to match each person's skill level. In this way, each person could advance at his or her optimum pace and not be bored by having to repeat lessons that had been mastered, or pushed ahead too fast.

Feedback programming is one of the ways we create software that adjusts to match each person using it. While some methods are as easy as changing the length of the tune in Simon Sings, other programs require more complex analysis in order to decide how to modify the experience so that each user feels that this program is just right.


Computer chips -- brains in a box

Many of our more interesting toys and tools contain computers that give them many new features or allow them to respond to you and the environment in new ways. If you are wearing a digital watch, for example, you have a computer on your wrist. No, it isn't as large and as expensive as the computer you are looking at right now, but the computer chip in your watch is a real computer with a central processor, a memory, and a stored written program that tells it what to do.

Many of today's cameras also use computer chips to focus automatically and adjust the shutter and lens opening for the correct exposure. When I began using a camera, I chose a model without a computer or even a built-in light meter because I wanted the highest quality possible and I didn't mind figuring out how to adjust all the camera settings myself to get the exact effects I wanted. Later I switched to a highly computerized camera that included three separate computers for adjusting the focusing, adjusting the exposure, and operating the other automatic controls. At first, I missed handling all the details myself, but I soon realized that the computers in the camera actually improved my photographic vision because I could concentrate more on the creativity and less on the process.

Computer chips in cars add both economy and safety to today's models. Engines are more efficient and cause less pollution because computers measure many factors and adjust the air and fuel mixture precisely for all driving conditions. The automatic braking systems rely on computer technology to sense when the tires are locked and instantly adjust the brake pressure so that the car can stop safely in a shorter distance.

Television as we know it today is dependent on a wide assortment of computers, from digital processing of the TV station's signals and computer-generated weather maps to the all-important remote control. We will soon have an additional computer in our TV sets. The V-Chip will automatically respond to coded signals included in the television broadcast and can be used to block certain types of programs that parents may feel are not suitable for younger children to watch.

As computer chips continue to get smaller and less expensive, you will see more and more items that are "intelligent" in one way or another. In each case, however, the computer inside will be running a stored program that somebody wrote. The only functional difference between the computer on your desk and the computer chip in your watch, your TV, or some other gadget is that your desk or laptop computer's program can be changed easily. In the computer chips, the stored program is permanent. In fact, computers like yours are used to create and test programs that will eventually become part of the computer chips in tomorrow's products.

If you were designing a computer toy based on Simon Sings, what changes or improvements would you program that could make the game more fun, more interesting, or more likely to become popular? You can try out your ideas and see if they work by making changes to the BASIC program that's actually running when you play this game. Here are some suggestions you might want to try...


More ideas -- fine tuning the fun

There are several variables you might want to adjust to see if you can make your version of Simon Sings even more fun. For example, how do you like the idea of the length of the tune changing as you play the game? Should the tune expand and get longer at a faster rate if you are winning? How quickly should it go back to a shorter tune if you miss? The program contains the variable MaxNotes that controls the length of the tune each time it restarts. At the beginning of the program it looks like this:

MaxNotes = 5

After you win, the computer reads this instruction:

MaxNotes = MaxNotes + 2

And if you lose, this instruction shortens the tune if it is longer than five notes:

IF MaxNotes > 5 THEN MaxNotes = MaxNotes - 1

As you can see, I have made it easier for the program to expand and get more difficult than to contract and get easier. If you would like to change this idea, or insert your own plan for matching the program to the user, just run BASIC, add your changes to my SIMON.BAS program, and try your version on your friends to see if you are right.


How to treat a loser

Another important thing for you to decide is how you want the program to treat people if they make errors. The "dribble" sound effect you hear when you miss a note was carefully written so that it would let you know what happened without sounding harsh or awful. I also decided that allowing four tries or mistakes would be generous enough, but you might have different ideas on this. The number is set at the beginning of the program and easily changed.

How do you feel about consequences? If you're too easy and give a person endless tries to get the tune right, the game will be boring. If you decide that you want to be really tough on losers, that won't work either. Consider how the program would feel if you end the game after even one mistake and then make a really loud sound, flash a message like "Boy are you dumb!" on the screen, turn off the computer, and just leave the screen black. It's a sure bet that you will have better luck with your design if you treat people a little more gently than this.

How people are treated, by the way, is a very important point. When you are selecting or buying software, notice how the program feels when you use it. And if you design your own programs, pay attention to how you treat people.

Unfortunately, many people think that computers are cold, difficult, and not much fun simply because some programmers who are cold, difficult, and not much fun have created software that treats people badly. How computers are seen in the future will depend a lot on the kinds of programs writers are creating today. You can help by looking carefully at any software you intend to buy, and only supporting the work of writers who create products that you really like.

More about cars and computers -- a story about the way it was.


Programmer's toolkit

Simon Sings uses many of the subs we have already talked about. In addition, I've added a simple method for getting a word or phrase from the keyboard. There are several ways of doing this, but I prefer my own sub that makes it easy to input anything that can be typed.

Using the program TOOLKIT1.BAS

If you have been following the Programmer's Toolkit in the previous examples, you will have seen several subroutines that I use to make programming easier. Simon Sings simply combines several of the things you have already seen with some unique instructions to create a complete game.

To see the complete toolkit in action, load and run TOOLKIT1.BAS program in QuickBASIC or run the TOOLKIT1.EXE program from your desktop. This short program uses all the subs and special techniques in a simple demonstration. To use these examples in your programs, just load TOOLKIT1.BAS first. This places all the subs in QuickBASIC automatically. You can also use the copy command to simply copy lines of code that you wish to use or modify. For more information on using the toolkit, check out more information on using the toolkit.

As you write your own programs, you will probably expand the toolkit and create your own set of special subs and words that you use again and again. If you discover something that you wish to share with other writers, you may want to send it to me. Please read sending stuff to Ainsworth before you send stuff to Ainsworth. And good luck with your writing.


Seminar homewww.qwerty.com