Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-01 - 43,50110/gamnim.gam
There are 2 other files named gamnim.gam in the archive. Click here to see a list.
100'  NAME--GAMNIM
110'
120'  DESCRIPTION--PLAYS GAME OF NIM
130'
140'  SOURCE--UNKNOWN
150'
160'  INSTRUCTIONS--TYPE "RUN" AND FOLLOW INSTRUCTIONS
170'
180'
190'  *  *  *  *  *  *  *   MAIN PROGRAM  *  *  *  *  *  *  *  *  *  *  *  *
200'
210 DIM A(100),B(100,10),D(2)
220 PRINT "THIS IS THE GAME OF NIM."
230 PRINT "DO YOU WANT INSTRUCTIONS";
240 INPUT Z$
250 IF Z$="NO" THEN 390
260 IF Z$="YES" THEN 290
270 PRINT "INCORRECT ANSWER.  PLEASE TYPE 'YES' OR 'NO'";
280 GOTO 240
290 PRINT "THE GAME IS PLAYED WITH A NUMBER OF PILES OF OBJECTS."
300 PRINT "ANY NUMBER OF OBJECTS  ARE REMOVED FROM ONE PILE BY YOU AND"
310 PRINT "THE MACHINE ALTERNATELY.  YOU MUST SPECIFY WHETHER WINNING"
320 PRINT "IS DEFINED AS TAKING OR NOT TAKING THE LAST OBJECT, THE"
330 PRINT "NUMBER OF PILES IN THE GAME, AND HOW MANY OBJECTS ARE"
340 PRINT "ORIGINALLY IN EACH PILE.  EACH PILE MAY CONTAIN A"
350 PRINT "DIFFERENT NUMBER OF OBJECTS."
360 PRINT "THE MACHINE WILL SHOW ITS MOVE BY LISTING EACH PILE AND THE"
370 PRINT "NUMBER OF OBJECTS REMAINING IN THE PILES AFTER  EACH OF ITS"
380 PRINT "MOVES."
390 PRINT
400 PRINT "ENTER WIN OPTION - 1 TO TAKE LAST, 2 TO AVOID LAST";
410 INPUT W
420 IF W=1 THEN 440
430 IF W<>2 THEN 400
440 PRINT "ENTER NUMBER OF PILES";
450 INPUT N
460 IF N>100 THEN 440
470 IF N<1 THEN 440
480 IF N<>INT(N) THEN 440
490 PRINT "ENTER PILE SIZES"
500 FOR I=1 TO N
510 PRINT I;
520 INPUT A(I)
530 IF A(I)>2000 THEN 510
540 IF A(I)<1 THEN 510
550 IF A(I)<>INT(A(I)) THEN 510
560 NEXT I
570 IF W=1 THEN 810
580 LET C=0
590 FOR I=1 TO N
600 IF A(I)=0 THEN 640
610 LET C=C+1
620 IF C=3 THEN 710
630 LET D(C)=I
640 NEXT I
650 IF C=2 THEN 790
660 IF A(D(1))>1 THEN 690
670 PRINT "MACHINE LOSES"
680 STOP
690 PRINT "MACHINE WINS"
700 STOP
710 LET C=0
720 FOR I=1 TO N
730 IF A(I)>1 THEN 810
740 IF A(I)=0 THEN 760
750 LET C=C+1
760 NEXT I
770 IF C/2<>INT(C/2) THEN 670
780 GOTO 810
790 IF A(D(1))=1 THEN 690
800 IF A(D(2))=1 THEN 690
810 FOR I=1 TO N
820 LET E=A(I)
830 FOR J=0 TO 10
840 LET F=E/2
850 LET B(I,J)=2*(F-INT(F))
860 LET E=INT(F)
870 NEXT J
880 NEXT I
890 FOR J=10 TO 0 STEP -1
900 LET C=0
910 LET H=0
920 FOR I=1 TO N
930 IF B(I,J)=0 THEN 980
940 LET C=C+1
950 IF A(I)<=H THEN 980
960 LET H=A(I)
970 LET G=I
980 NEXT I
990 IF C/2<>INT(C/2) THEN 1060
1000 NEXT J
1010 LET E=INT(N*RND+1)
1020 IF A(E)=0 THEN 1010
1030 LET F=INT(A(E)*RND+1)
1040 LET A(E)=A(E)-F
1050 GO TO 1250
1060 LET A(G)=0
1070 FOR J=0 TO 10
1080 LET B(G,J)=0
1090 LET C=0
1100 FOR I=1 TO N
1110 IF B(I,J)=0 THEN 1130
1120 LET C=C+1
1130 NEXT I
1140 LET A(G)=A(G)+2*(C/2-INT(C/2))*2^J
1150 NEXT J
1160 IF W=1 THEN 1250
1170 LET C=0
1180 FOR I=1 TO N
1190 IF A(I)>1 THEN 1250
1200 IF A(I)=0 THEN 1220
1210 LET C=C+1
1220 NEXT I
1230 IF C/2<>INT(C/2) THEN 1250
1240 LET A(G)=1-A(G)
1250 PRINT "PILE  SIZE"
1260 FOR I=1 TO N
1270 PRINT I;A(I)
1280 NEXT I
1290 IF W=2 THEN 1320
1300 GOSUB 1440
1310 IF Z=1 THEN 690
1320 PRINT "YOUR MOVE - PILE,NUMBER TO BE REMOVED";
1330 INPUT X,Y
1340 IF X>N THEN 1320
1350 IF X<1 THEN 1320
1360 IF X<>INT(X) THEN 1320
1370 IF Y>A(X) THEN 1320
1380 IF Y<1 THEN 1320
1390 IF Y<>INT(Y) THEN 1320
1400 LET A(X)=A(X)-Y
1410 GOSUB 1440
1420 IF Z=1 THEN 670
1430 GO TO 570
1440 LET Z=0
1450 FOR I=1 TO N
1460 IF A(I)=0 THEN 1480
1470 RETURN
1480 NEXT I
1490 LET Z=1
1500 RETURN
1510 END