Electronic geoboard.(part 1)Donald T. Piele.

Electronic Geoboard Part 1

I saw a geoboard for the first time in 1968 as a graduate student in mathematics. The circumstances were a bit unusual. I had volunteered, through a program called SEED, (Special Elementary Education for the Disadvantaged), to help a class of elementary school kids in San Diego discover modern mathematical ideas--"the new math.' Project SEED was a statewide program that grew out of the work that William Johntz had begun in Berkeley, CA. Graduate students in mathematics volunteered for the project, which, in effect, was a substitute for their duties as college teaching assistants.

Instead of helping college freshmen with their calculus, SEED volunteers went into elementary schools and investigated mathematical ideas using the "discovery' method. We were free to investigate any topic in mathematics, since our daily classes were intended to enrich rather than substitute for the regular elementary mathematics curriculum. It was in this setting that I first discovered the geoboard.

All it takes to make a geoboard is a small square piece of wood, 25 nails, and a hammer. Draw five equally spaced vertical lines and five equally spaced horizontal lines. Hammer a nail at each of the 25 intersection points and, you have a geoboard. To use it, however, you need one other item--rubber bands.

What For?

You probably will not find geoboards in many elementary schools today. They are not an essential tool in everyday life, and I doubt that a movement will spring up to push for "geoboard literacy.' But their use in an elementary school classroom has some similarities with the way computers are used today to encourage creative problem solving.

Like a computer, a geoboard is an interactive tool. Students use rubber bands and stretch them around pegs to form polygons of different shapes and sizes. Like a computer, a geoboard does nothing on its own, and, without problems, it is a useless piece of hardware. We used it in our classroom investigations as a "visithink' device and posed "what if' types of questions. Books such as Donald Cohen's Inquiry In Mathematics Via The Geo-Board, were helpful in suggesting many good problems for investigation.

This month, I would like to resurrect the geoboard and bring it back to life in an electronic form. The activities presented here for the electronic version will be different from typical geoboard activities.

Our first problem will deal with creating an electronic geoboard and simulating simple operations. The programs will be written in a structured format with names given to each procedure. This should make it possible for anyone to follow the logic of the programs without having to read code designed for a specific system or written in a specific language. Each procedure will also be worked out in Applesoft Basic. Constructing the programs for other microcomputers with graphics capabilities will be left to the reader.

All of the problems presented in this article are designed for beginning and intermediate programmers and are presented for the purpose of developing computer problem solving skills. I hope that the problem solving spirit of the original geoboard activities will not suffer in the translation.

Electronic Geoboard I

Let's begin with the most basic problem:

Write a program that will display a geoboard.

A standard geoboard has 25 pegs arranged in five rows of five columns. It can be drawn graphically as follows:

The Applesoft program on the right is separated into individual procedures which are given names and listed on the left. The Basic language is not naturally structured, but with a little planning we can at least simulate this quality. Doing so not only helps us read our own programs, it also helps other people translate our programs into a different language.

In the solution to the Electronic Geoboard I, each procedure is carried out in sequential order. In more difficult problems, the same procedure may be needed over and over again. Using Basic, which is not designed to encourage programmers to name and recall procedures by name, we must rewrite the procedure every time we use it, or use confusing branching techniques with dangerous GOTOS.

The only alternative is to construct subroutines. Let's see how the above program would look if we decided to build subroutines first, and then use them to build the program.

To simulate a procedure in Basic using a subroutine, we need to add a RETURN statement to the end of each of the routines already constructed. For example, the procedure SET COLOR in the above program can be modified into an Applesoft subroutine as follows:

Thus, one way to build a structured solution to the Electronic Geoboard I is as follows:

Notice that the first statement in line 1 instructs the program to jump over the subroutines and begin the main program at line 100. It may appear to beginners that all we have done is take an easy problem and make it hard. Indeed, that is true if this is the only program about geoboards that one intends to write. But, by employing subroutines to define procedures, it is much easier for the reader to understand what was done. Let's see how this works with the next problem.

Electronic Geoboard II

Write a program that will choose pegs on a geoboard by allowing the user to input a row number and a column number and then chang the corresponding peg to a different color.

Since we have already constructed the board in the previous problem, we need only add the ability to identify the pegs. Where are the pegs located on the low-resolution graphics screen?

Problem Solving Strategy

Examine the procedure DRAW PEGS. Notice that in the top row the pegs are placed at the following positions:

Look at the pattern of screen position numbers. How do they relate to the ROW and COLUMN numbers? Did you discover the following relationships?

X = COLUMN * 7 - 2

Y = ROW * 7 - 2.

It is a simple matter to extend the previous program to ask the user to identify a row and column from 1 to 5, plot each identified point white, and continue this process as long as the user enters a (ROW, COLUMN) between (1,1) and (5,5). As soon as a point is entered outside of this range, terminate the program. To implement this change, it is sufficient to create three additional procedures and attach them to the previous program.

Notice how much easier it is to read a program if procedures are named.

Let's continue developing the Electronic Geoboard by adding the ability to choose two pegs and shade in the rectangular region that they define.

Electronic Geoboard III

Write a program that asks the user to choose two pegs on the electronic geoboard and then shades in the rectangular region determined by these two pegs. For example, if 2,1 and 5,4 are the two pegs chosen, then the rectangle determined by these pegs is

Notice that this same rectangle could also be identified by the two points 2,4 and 5,1.

Problem Solving Strategy

The problem we must first solve is this: Given two pegs, how do we shade in the rectangular region determined by them?

Let's begin by defining how to do this at the procedure level.

Procedure

Shade rectangle

(Peg1 = R1, C1

Peg2 = R2, C2

From row R1 to R2

Draw horizontal line between columns C1 and C2 Next row)

The SHADE RECTANGLE procedure tells us what to do but it does not tell us how to carry it out in a specific language. It is a blueprint that the architect has designed and left to the builder to create. Here are the critical problems that the builder must solve:

How do row and column numbers relate to screen positions X, Y?

How do you draw the horizontal lines?

How do you loop between row R1 and row R2 if R1 is larger that R2?

The first problem was solved in the previous procedure

X = COLUMN * 7 - 2

Y = ROW * 7 - 2.

The second problem can be solved in Applesoft Basic with one simple statement

HLIN X1, X2 AT Y

The third problem can be solved by adding a direction to the FOR/NEXT loop. If R1 < = R2, then we want to step forward by one row each time we draw a horizontal line. If R1>R2, then we need to step backward one row each time. The expression (R1 < = R2)-(R1 > R2) does the trick. When R1 < = R2, then the logical expression (R1 < R2) is true and hence set to 1, while the second term (R1 > R2) is false and is set to 0. If the reverse is true and R1 > R2, then the values are switched, and we end up with an answer of -1. Thus, we can fill in the rectangular area as follows:

FOR Y = Y1 TO Y2 STEP (R1 <= R2) - (R1 > R2) (DRAW HORIZONTAL LINE)

NEXT Y

Now we are ready to collect our routines and add them to the previous program to solve the third problem.

Exercises

One of the advantages of developing each program in a structured format is the case with which they can be changed. Below is a small list of problems for your investigation. They can all be solved by making minor changes or additions to the subroutines in the programs displayed above.

1. Write a program that will display a 36-peg Electronic Geoboard.

2. Write a program that uses a game paddle to choose points on the Electronic Geoboard. This can be done by taking the output of the game paddle (an integer between 0 and 255) and dividing it into 25 equally likely parts (try Q = INT (PDL (0)/10.5)). Each one of these integers represents a peg on the board.

3. Write a program that allows the user to choose a color and two pegs and then shades the rectangle determined by these two points the color specified. Design the program so that it will allow the user to continue to shade rectangles with different colors on the same screen.

4. Modify the program in exercise 3 to allow the user to either shade the region determined by the two pegs or the complementary region (everything but the rectangle determined by the pegs).

5. Modify the program in exercise 4 to allow the user to shade several rectangles different colors and then fill in the background a final color.

Conclusion

A criticism often made of the Basic language is that it is not structured. As we have seen, imposing a structure is possible, but is not a straightforward task. I could more quickly have written each program independently, not bothering to define separate procedures. In fact, that is how I wrote them originally.

So, why did I bother to do things the hard way? Because programmers of the future will need to know how to write structured programs. Then why didn't I use a structured language? Because Basic comes with most machines; Logo and Pascal do not. Also, the Electronic Geoboard is easier to handle in a coordinate based graphics system as opposed to a turtle graphics system.

Next month, we will continue our investigations of Electronic Geoboard but move into high-resolution graphics.

Table:

Table: Electronic Geoboard II

Table: Electronic Geoboard III

Photo: Figure 1. Electronic Geoboard I.

Photo: Figure 2. Electronic Geoboard II.

Photo: Figure 3. Electronic Geoboard III. Rectangle defined by 2,3 and 5,4.