A NIM Game for 2K

Authors

Publication

Pub Details

Date

Pages

See all articles from SyncWare News v1

An important consideration in programming personal computers is memory economy. Unlike the big main-frames that offer virtually unlimited storage, you have only a limited RAM space at your ready disposal. Anyone who’s tackled a large project knows just how small 16K can seem.

Fortunately, there are a few relatively “mechanical” techniques you can use to appreciably reduce the memory required by a program. Keeping your programming efficient is another step to getting the most out of (or rather into) your available RAM. We’ll be running a “Byte-Pynchers” column on a semi-regular basis to show you some of these tips and techniques.

Meanwhile, here is a listing of a game which occupied about 4K of RAM as originally written, and was subsequently streamlined using several of these techniques. The result runs fine in an unexpanded 2K machine. The program will give you an idea of what can be accomplished in limited memory if you give some care to using your RAM space as efficiently as possible.

If you’re an experienced programmer, some of this will be old hat, but look it over! There’s a possibility that there’s something you can use. If you’re a relative newcomer, some of this might look awkward and hard to read. This is the price we pay for byte-pynching. Future installments of “BytePynchers” will hopefully help make sense of this stuff.

The game itself is quite simple; you and another player take turns removing as many “stones” as desired from any row. The point is to make your opponent take the last stone. It is OK to use RUN and CLEAR in this program.

If you’re using and expanded machine (3.25 up), you should first fool the computer into thinking it has only 2K of memory by first entering POKE 16389,72 and then entering NEW. In 2K machines this is not necessary.

Lower-case letters indicate reverse video, except in lines 110 and 180 (see below.) As a last note, this is a game, unlike most, that pits you against another human instead of the computer’s logic and randomizing function. The computer just provides the playing field and “referree” services. Have fun!

GRAPHICS NOTES:

Line 110: “gr. 5, gr.5, inv, *, space, inv. N, inv. I, inv. M, space, inv. *, gr. 8, gr. 8”

Line 180: “gr. T, gr. Y, gr. T *, period, space” (change as desired.)

16K machines: To make the program run in 16K without changing RAMTOP (POKEing 16389) change line 320 to:

200 LET L=DF+66*H+N2*I+3

This takes into account the difference in the way the display file is handled with full memory.

10 SLOW
20 LET N0=VAL "0"
30 LET N1=VAL "1"
40 LET N2=VAL "2"
50 LET N7=VAL "7"
60 LET O7=VAL "17"
70 LET P1=VAL "21"
80 LET DF=PEEK 16396+256*PEEK 16397
90 LET T=N0
100 DIM N$(N2,N7)
110 PRINT AT N7,N7;"@@@ nim @@@",,,,"BY F.NACHBAUR",,,,
120 GOSUB VAL "250"
130 FOR A=N1 TO N2
140 PRINT "NAME-PLAYER ";A;"?"
150 INPUT N$(A)
170 NEXT A
180 LET B$="@@@*. "
190 GOTO VAL "300"
200 LET L=DF+38*H+N2*I+N1
210 RETURN
220 INPUT A
230 IF A<N1 OR A>N7 THEN GOTO VAL "220"
240 RETURN
250 FOR A=N0 TO N7*O7
255 IF INKEY$<>"" THEN RETURN
260 NEXT A
270 RETURN
300 CLS
340 LET X$="1111111"
350 LET N=N7*N7
360 PRINT "row"
370 FOR A=N1 TO N7
380 PRINT ,,," ";A;" ";"O O O O O O O";
390 NEXT A
500 PRINT AT O7,N0;"YOUR TURN,";N$(T+N1);AT P1,N0;"WHICH ROW? "
510 GOSUB 220
520 IF X$(A)="1" THEN GOTO 560
530 PRINT AT P1,N0;" row empty."
540 GOSUB VAL "250"
550 GOTO VAL "500"
560 LET H=A
570 PRINT AT P1,N0;"HOW MANY? "
580 GOSUB 220
590 LET S=A
600 FOR I=N7 TO N1 STEP -N1
610 GOSUB 200
620 IF PEEK L=N0 THEN NEXT I
630 IF S>I THEN GOTO 790
640 FOR I=I TO I-S+N1 STEP -N1
650 GOSUB 200
660 FOR A=N1 TO LEN B$
670 POKE L,CODE B$(A)
680 NEXT A
720 NEXT I
730 IF I=N0 THEN LET X$(H)="0"
740 LET N=N-S
750 IF N=N0 THEN GOTO 820
760 IF N=N1 THEN GOTO 840
770 LET T=NOT T
780 GOTO 500
790 PRINT AT P1,N0;"too many. "
800 GOSUB VAL "250"
810 GOTO 500
820 PRINT AT O7,N0;"YOU""RE A FOOL,";N$(T+N1)
830 GOTO VAL "850"
840 PRINT AT O7,N0;"YOU WIN, ";N$(T+N1)
850 PRINT AT P1,N0;"AGAIN? Y/N"
860 IF INKEY$="Y" THEN GOTO 890
870 IF INKEY$="N" THEN STOP
880 GOTO 860
890 PRINT AT P1,N0;N$(N2);" STARTS?"
900 IF INKEY$<>"" THEN GOTO VAL "900"
910 LET T=(INKEY$="Y")
930 IF INKEY$<>"Y" AND INKEY$<>"N" THEN GOTO 910
940 GOTO VAL "300"
1000 SAVE "NIm"
1010 RUN

Products

 

Downloadable Media

 
Scroll to Top