Compucolor.org – Virtual Media

Listing of file='NIM.BAS;01' on disk='vmedia/games2-sector.ccvf'

90 PLOT 12
100 REM  THIS PROGRAM PLAYS 3-PILE NIM.
110 REM  RANDOM NUMBERS IN EACH PILE.
120 REM  PLAYER WHO CLEARS BOARD WINS/
122 PRINT "
124 FOR X= 1TO 8:PRINT
126 NEXT X
127 PRINT "           WELCOME  TO  NIM           "
130 REM  INITIALIZE
140 FOR P= 1TO 3
150 N(P)= INT (10* RND (1))+ 6
160 NEXT P
170 PRINT "INITIAL CONFIGURATION:"
180 PRINT
190 GOSUB 900
210 REM  PLAYERS MOVE
220 PRINT "PILE, NUMBER TAKEN";
230 INPUT P,N
240 IF N< = N(P)THEN 270
250 PRINT "ILLEGAL MOVE"
255 PRINT
260 GOTO 220
270 N(P)= N(P)- N
280 IF N(1)+ N(2)+ N(3)> 0THEN 370
290 PRINT
300 PRINT "YOU WIN *****"
310 PRINT
320 PRINT
330 GOTO 140
370 REM  SET-UP BIT PATTERN TABLE
380 FOR P= 1TO 3
390 X= N(P)
400 FOR C= 4TO 1STEP - 1
410 Y= INT (X/ 2)
420 B(P,C)= X- 2* Y
430 X= Y
440 NEXT C
450 NEXT P
470 REM  SET-UP COLUMN PARITY LIST S
480 FOR C= 1TO 4
490 X= B(1,C)+ B(2,C)+ B(3,C)
500 S(C)= X- 2* INT (X/ 2)
510 NEXT C
530 REM  IF ALL EVEN, MAKE RANDOM MOVE
540 IF S(1)+ S(2)+ S(3)+ S(4)> 0THEN 615
550 FOR P= 1TO 3
560 IF N(P)= 0THEN 590
570 N= INT (N(P)* RND (1)+ 1)
580 GOTO 770
590 NEXT P
605 REM  MAKE OPTIMAL MOVE
615 REM  FIND FIRST ODD COLUMN
620 FOR C= 1TO 4
630 IF S(C)> 0THEN 650
640 NEXT C
645 REM  FIND FIRST ODD COLUMN
650 FOR P= 1TO 3
660 IF B(P,C)= 1THEN 680
670 NEXT P
677 REM  CALCULATE CORRECT NUMBER
680 N= 0
690 FOR C= CTO 4
700 IF S(C)= 0THEN 750
710 X= 2^ (4- C)
720 IF B(P,C)= 0THEN 740
730 N= N+ X
735 GOTO 750
740 N= N- X
750 NEXT C
770 REM  CARRY OUT MOVE
780 PRINT
790 PRINT "MY MOVE:";P;",";N
800 PRINT
810 N(P)= N(P)- N
820 IF N(1)+ N(2)+ N(3)> 0THEN 850
830 PRINT "         I  WIN  AGAIN            ***********    "
840 GOTO 310
850 PRINT "NEW CONFIGURATION"
860 PRINT
870 GOSUB 900
880 GOTO 210
900 REM  SUBROUTINE -- PRINT CONFIGURATION
910 FOR P= 1TO 3
920 PRINT "PILE";P,N(P)
930 NEXT P
940 PRINT
950 PRINT
960 RETURN
999 END