7 ' Source:  Printed copy offered in
8 '          PC Magazine, Vol. 1, No. 2, pp. 85-87
9 ' (all comments omitted)
10 '                          RUBIK'S CUBE SIMULATOR
20 '                                 PC MAGAZINE
30 '                                 march, 1982
40 '                                 karl koessel
50 SCREEN 0,1,0,0
60 COLOR 7,0,1
70 CLS
80 KEY OFF
90 CLEAR,,2000
100 DEFINT A-Z
110 DIM HOLD(20)
120 GOSUB 3240
130 GOSUB 3620
140 GOSUB 3680
150 GOSUB 3770
160 GOSUB 600
190 GOSUB 2760
200 COLOR 23
210 PRINT "Enter ";
220 COLOR 7
230 INPUT "a twist or command: ",TWIST$
240 IF TWIST$="" THEN 190
250 GOSUB 1860
260 REQ$=TWIST$
270 GOSUB 820
280 IF D THEN 190
290 GOSUB 910
300 GOTO 190
320 GOSUB 2760
330 PRINT "Press [RETURN] to twist the ";
340 IF CLRMON THEN COLOR BR(F) ELSE COLOR 1
350 PRINT PLACE$(1,F);
360 COLOR 7
370 PRINT " face ";
380 IF CLRMON THEN COLOR BR(F) ELSE COLOR 1
390 PRINT DIRECTION$(OSO)
400 COLOR 7
410 IF CLRMON AND BIG THEN 430
420 PRINT SPC(13)
430 PRINT "or enter a new twist or command: ";
440 INPUT "",GO$
450 GOSUB 1860
460 IF GO$="" THEN 530
470 REQ$=,GO$
480 GOSUB 820
490 ON D GOTO 320,320,320,320,510,320,320,320,530
500 GOSUB 910
510 RETURN
530 GOSUB 2360
540 GOSUB 2520
550 GOSUB 1900
560 GOSUB 2000
570 GOSUB 1590
580 RETURN
600 GOSUB 1900
610 IF CLRMON THEN WIDTH 40:BIG=-1
620 IF NOT BIG AND D=8 THEN RETURN
630 GOSUB 2790
640 IF D<>8 THEN GOSUB 2610
650 IF NOT BIG THEN 690
660 GOSUB 3020
670 CLS
680 GOSUB 3040
690 GOSUB 1290
700 RETURN
720 RQ$=""
730 FOR K=1 TO LEN(REQ$)
740     RK$=MID$(REQ$,K,1)
750     IF RK$="'" THEN 770
760     RK$=CHR$((ASC(RK$) AND 95))
770     RQ$=RQ$+RK$
780 NEXT
790 REQ$=RQ$
800 RETURN
820 GOSUB 720
830 D=0
840 FOR DMI=1 TO 9
850     IF LEFT$(REQ$,LEN(DM$(DMI)))=DM$(DMI) THEN D=DMI
860 NEXT
870 IF D>0 AND D<4 THEN DM=D-1
880 ON D GOSUB 1590,1590,1590,1380,600,1210,2040,610,1350
890 RETURN
910 GOSUB 1900
930 IF MID$(REQ$,2,1)=""OR MID$(REQ$,2,1)="'"AND LEN(REQ$)<3 THEN 960
940 GOTO 1020
960 F=0
970 FOR W=1 TO LEN(T$)
980     IF LEFT$(REQ$,1)=MID$(T$,W,1) THEN F=W:TWIST$=REQ$
990 NEXT
1000 IF F THEN 1100
1020 GOSUB 2760
1030 PRINT "Input ";:COLOR 23:PRINT "NOT";:COLOR 7:PRINT " recognized"
1040 PRINT "    One moment please..."
1050 GOSUB 1590
1060 GOSUB 1860
1070 RETURN
1100 IF MID$(REQ$,2,1)="'" THEN OSO=2:OSI=1 ELSE OSO=0:OSI=5
1120 GOSUB 2200
1130 GOSUB 2260
1150 GOSUB 2460
1170 IF SKIP THEN 530
1180 GOSUB 1590
1190 GOTO 320
1210 IF NOT CLRMON THEN 1330
1220 BIG=NOT BIG
1230 IF BIG THEN WIDTH 40:GOTO 1260
1240 WIDTH 80
1250 GOSUB 2790
1260 GOSUB 1290
1270 RETURN
1290 IF BIG THEN GOSUB 3060
1300 GOSUB 1390
1310 GOSUB 1590
1320 IF NOT BIG THEN GOSUB 2040
1330 RETURN
1350 SKIP=NOT SKIP
1360 RETURN
1380 LABEL = NOT LABEL
1390 FOR FA=1 TO 6
1400     IF BIG THEN LOCATE XBL(FA),YBL(FA):GOTO 1420
1410     LOCATE X(FA)+2,Y(FA)-1
1420     IF NOT LABEL GOTO 1460
1430     IF CLRMON THEN COLOR BR(FA) ELSE COLOR 1
1440     PRINT PLACE$(1,FA);
1450     GOTO 1470
1460     PRINT SPC(5);
1470 NEXT
1480 IF NOT BIG THEN 1570
1490 FOR XBL=1 TO 2
1500     LOCATE XBL+4,19-XBL
1510     IF NOT LABEL THEN GOTO 1540
1520     COLOR BR(3)
1530     PRINT "/";
1540     PRINT " "
1550 NEXT
1560 COLOR 7
1570 RETURN
1590 DB=1:DUB=0
1600 IF BIG THEN DB=2
1610 FOR FA=1 TO 6
1620 FOR P=0 TO 8
1630 IF BIG THEN FOR DUB=0 TO 1
1640     LOCATE X(FA)+XOF(P)*DB+DUB-REL(FA)*BIG,Y(FA)+YOF(P)+RELY(FA)*BIG
1650     BR=BR(FIX(CUBIE(FA,P,1)\10))
1660     IF BR THEN COLOR CUBIE(FA,P,2)*-16,BR:GOTO 1680
1670     IF CUBIE(FA,P,2) THEN COLOR 0,7 ELSE COLOR 7,0
1680     IF DUB THEN PRINT "  ";:GOTO 1710
1690     IF DM THEN PRINT USING "\\"; CUBIE$(FA,P,DM);                                         ELSE PRINT USING "**"; CUBIE(FA,P,1);
1710     ON P+1 GOTO 1730,1720,1720,1800,1800,1800,1740,1740,1730
1720     ND=1:GOTO 1760
1730     ND=4:GOTO 1760
1740     ND=-1:GOTO 1760
1760     IF BR THEN COLOR BR,BR(FIX(CUBIE(FA,(P+ND) MOD 12,1)\10)) ELSE 1780
1770     PRINT CHR$(221);:GOTO 1800
1780     IF CUBIE(FA,P,2)=CUBIE(FA,(P+ND) MOD 12,2) THEN 1790 ELSE COLOR 7,0
1790     PRINT " ";
1800 IF BIG THEN NEXT
1810 NEXT
1820 NEXT
1830 COLOR 7,0
1840 RETURN
1860 GOSUB 2760
1870 PRINT "One moment, please..."SPC(79)SPC(39)SPC(21)
1880 RETURN
1900 FOR J=1 TO 4
1910     FOR K=1 TO 3
1920         CUBIE(FACE(J),((POSITION(J)+K-2) MOD 8)+1,2)=0
1930     NEXT
1940 NEXT
1950 FOR P=1 TO 8
1960     CUBIE(F,P,2)=0
1970 NEXT
1980 RETURN
2000 TWISTSSOFAR$(AT)=TWISTSSOFAR$(AT)+TWIST$+" "
2010 IF LEN(TWISTSSOFAR$(AT))>36 THEN AT=AT+1
2020 IF BIG THEN RETURN
2040 LOCATE 18,1
2050 IF BIG THEN PRINT
2060 COLOR 1
2070 PRINT TWISTSSOFAR$(0);
2080 COLOR 7
2090 PRINT SPC(13)
2100 FOR K=1 TO AT
2110     PRINT TWISTSSOFAR$(K);
2120     IF NOT BIG THEN PRINT TWISTSSOFAR$(K+1);:K=K+1
2130     PRINT
2140 NEXT
2150 IF NOT BIG THEN RETURN
2160 GOSUB 3020
2170 GOSUB 1860
2180 RETURN
2200 FOR J=1 TO 4
2210     FACE(J)=VAL(MID$(OC$(F),J*2-1,1))
2220     POSITION(J)=VAL(MID$(OC$(F),J*2,1))
2230 NEXT
2240 RETURN
2260 FOR J=1 TO 4
2270     FOR K=1 TO 3
2290         HOLD((J-1)*3+K)=CUBIE(FACE(J),((POSITION(J)+K-2) MOD 8)+1,1)
2310         CUBIE(FACE(J),((POSITION(J)+K-2) MOD 8)+1,2)=-1
2320     NEXT
2330 NEXT
2340 RETURN
2360 FOR J=1 TO 4
2370     FOR K=1 TO 3
2380         CUBIE(FACE(((J+OSO) MOD 4)+1),((POSITION(((J+OSO) MOD 4)+1)+K-2)                MOD 8)+1,1)=HOLD((J-1)*3+K)
2390         FOR DMI=1 TO 2
2400             CUBIE$(FACE(((J+OSO) MOD 4)+1),((POSITION(((J+OSO) MOD 4)+1)                    +K-2) MOD 8)+1,DMI)=PLACE$(DMI,FIX((HOLD((J-1)*3+K)\10)))
2410         NEXT
2420     NEXT
2430 NEXT
2440 RETURN
2460 FOR P=1 TO 8
2470     HOLD(12+P)=CUBIE(F,P,1)
2480     CUBIE(F,P,2)=-1
2490 NEXT
2500 RETURN
2520 FOR P=1 TO 8
2530     CUBIE(F,P,1)=HOLD(13+((P+OSI)MOD 8))
2540     FOR DMI=1 TO 2
2550         CUBIE$(F,P,DMI)=PLACE$(DMI,FIX(CUBIE(F,P,1)\10))
2560     NEXT
2570 NEXT
2580 RETURN
2610 FOR F = 1 TO 6
2620     FOR P = 0 TO 9
2630         CUBIE(F,P,1)=F*10+P
2640         FOR DMI=1 TO 2
2650             CUBIE$(F,P,DMI)=LEFT$(PLACE$(DMI,F),2)
2660         NEXT
2670     NEXT
2680 NEXT
2700 FOR K=1 TO AT
2710     TWISTSSOFAR$(K)=""
2720 NEXT
2730 AT=1
2740 RETURN
2760 IF BIG THEN LOCATE 19,1 ELSE LOCATE 15,1
2770 RETURN
2790 IF BIG THEN COLOR ,4:BG=3 ELSE BG=43
2800 CLS
2810 LOCATE 1,1+BG:COLOR 1:PRINT TITLE$
2820 LOCATE 3,3+BG:COLOR 7:PRINT"Each twist is called by the first"
2830 LOCATE 4,BG:PRINT"letter of the face you wish to twist:"
2840 LOCATE 5,BG:COLOR 1:PRINT"U";:COLOR 7:PRINT" for the upper face, ";             :COLOR 1:PRINT"L";:COLOR 7:PRINT" for the left"
2850 LOCATE 6,BG:PRINT"face, ";:COLOR 1:PRINT"F";:COLOR 7:                           :PRINT" for the front face, ";:COLOR 1:PRINT"R";:COLOR 7:PRINT" for the"
2860 LOCATE 7,BG:PRINT"right face, ";:COLOR 1:PRINT"B";:COLOR 7                      :PRINT" for the back face and ";:COLOR 1:PRINT"D":COLOR 7
2870 LOCATE 8,BG:PRINT"for the downward face. The twists will"
2880 LOCATE 9,BG:PRINT"be clockwise. To make a counterclock-"
2890 LOCATE 10,BG:PRINT"wise twist, the letter is followed by"
2900 LOCATE 11,BG:PRINT"a ";:COLOR 1:PRINT"'";:COLOR 7:PRINT" (e.g. ";               :COLOR 1:PRINT"L'";:COLOR 7:PRINT" ). To change the display,"
2910 LOCATE 12,BG:PRINT"enter either the word ";:COLOR 1:PRINT"Labels";              :COLOR 7:PRINT" or ";:COLOR 1:PRINT"Colors";:COLOR 7
2920 IF CLRMON THEN LOCATE 12,BG:PRINT"enter the word ";:COLOR 1:PRINT "Big";:                      COLOR 7:PRINT" or ";
2930 LOCATE 13,BG:PRINT"or ";:COLOR 1:PRINT"Faces";:COLOR 7:PRINT" or ";             :COLOR 1:PRINT"Codes";:COLOR 7:PRINT". Use ";:COLOR 1:PRINT"Skip";:COLOR 7      :PRINT" to resume/"
2940 LOCATE 14,BG:PRINT"skip verification. Use ";:COLOR 1:PRINT"New";:COLOR 7        :PRINT" to restart."
2950 IF NOT BIG THEN RETURN
2960 LOCATE 15,3:PRINT "To accommodate those using television ";
2970 PRINT "  sets (i.e. confined to WIDTH 40), the ";
2980 PRINT "  commands ";:COLOR 1:PRINT "List";:COLOR 7:PRINT " & ";:COLOR 1
2990 PRINT "Help";:COLOR 7:PRINT " have been added."
3000 RETURN
3020 LOCATE 25,9:PRINT "Press the spacebar to continue";
3030 IF INKEY$<>" " THEN 3030
3040 LOCATE 25,3:COLOR 1,4:PRINT TITLE$;:COLOR 7,0:RETURN
3060 LOCATE 1,19:COLOR BR(2),,BR(4):PRINT "Twists: ";
3070 FOR LI=1 TO 2:LOCATE LI,25+LI
3080     FOR TI=1 TO 3
3090         FOR DI=0 TO 1
3100             COLOR BR((LI-1)*3+TI)
3110             IF DI THEN PU$="!' " ELSE PU$="! "
3120             PRINT USING PU$;MID$(T$,(LI-1)*3+TI);
3130         NEXT
3140     NEXT
3150 NEXT
3160 LOCATE 4,31:COLOR BR(6):PRINT "Commands:";
3170 FOR CM=1 TO 9
3180     LOCATE 5+CM,35
3190     COLOR BR(CM MOD 6+1)
3200     PRINT DM$(CM)
3210 NEXT
3220 COLOR 7:RETURN
3240 FOR FACE=1 TO 6
3250     READ PLACE$(1,FACE)
3260 NEXT
3270 DATA"upper","left","front","right","back","down"
3280 FOR FACE=1 TO 6
3290     READ YOURS$(FACE)
3300 NEXT
3310 DATA"white","orange","blue","red","green","yellow"
3320 FOR P=1 TO 8
3330     READ XOF(P),YOF(P)
3340 NEXT
3350 DATA -1,-3,-1,0,-1,3,0,3,1,3,1,0,1,-3,0,-3
3360 FOR FA=1 TO 6
3370     READ XBL(FA),YBL(FA)
3380 NEXT
3390 DATA 2,4,13,3,4,19,13,19,13,27,17,17
3400 FOR FA=1 TO 6
3410     READ REL(FA),RELY(FA)
3420 NEXT
3430 DATA 1,2,3,0,3,2,3,4,3,6,5,2
3440 FOR F=1 TO 6
3450     READ X(F),Y(F)
3460 NEXT
3470 DATA 2,14,6,4,6,14,6,24,6,34,10,14
3480 FOR F=1 TO 6
3490     READ OC$(F)
3500 NEXT
3510 DATA "21514131","17376753","15476123","13576333","11276543","25354555"
3520 FOR DMI=1 TO 9
3530     READ DM$(DMI)
3540 NEXT
3550 DATA CODE,FACE,COLOR,LABEL,NEW,BIG,LIST,HELP,SKIP
3560 DIRECTION$(0)="clockwise":DIRECTION$(2)="counterclockwise"
3570 T$="ULFRBD"
3580 TWISTSSOFAR$(0)="The list of twists so far :"
3590 TITLE$=SPACE$(7)+"RUBIK'S CUBE SIMULATOR"+SPACE$(7)
3600 RETURN
3620 DEF SEG=0
3630 IF (PEEK(&H410) AND &H30)<>&H30 THEN CLRMON=-1
3640 DM=1
3650 LABEL=-1
3660 RETURN
3680 IF CLRMON THEN COLOR 1,4:WIDTH 40:K=1 ELSE WIDTH 80:K=21
3690 CLS:LOCATE 3,2+K:PRINT TITLE$
3700 LOCATE 6,15+K:PRINT"PC MAGAZINE"
3710 LOCATE ,15+K:COLOR 7:PRINT"march, 1982"
3720 LOCATE 24,19+K:PRINT"press the spacebar";
3730 IF INKEY$<>" " THEN 3730
3740 COLOR 7,0
3750 RETURN
3770 CLS
3780 LOCATE 2,7+K
3790 K$="*** COLORING THE CUBE ***"
3810 IF CLRMON THEN 3880
3830 PRINT K$
3840 LOCATE 9,K+6
3850 PRINT"(The name of each color":PRINT SPC(11+K)"should begin with a":
3860 PRINT SPC(16+K)"different letter.)":GOTO 4080
3880 FOR L=1 TO 25
3890     COLOR (L MOD 7)+1
3900     PRINT MID$(K$,L,1);
3910 NEXT
3920 LOCATE 4,4
3930 FOR C=1 TO 7
3940     COLOR ,C
3950     PRINT "     ";
3960     COLOR C,0
3970     PRINT "---";C;
3980     PRINT SPC(10)
3990 NEXT
4000 LOCATE 9,1
4010 COLOR 1,4
4020 PRINT "Choose each face's color by entering the";
4030 PRINT "appropriate number from the list above, ";
4040 COLOR 0,2
4050 PRINT "or just press [RETURN] for each face and";
4060 PRINT "the computer will choose the colors.    "
4080 LOCATE 15,K
4090 COLOR 23,0:PRINT"Enter";
4100 COLOR 7:PRINT" a color for each face:"
4110 PRINT
4120 FOR FACE = 1 TO 6
4130     LOCATE FACE+16,15+K:COLOR 0,7:PRINT USING" \    \";PLACE$(1,FACE);
4140     COLOR 7,0:INPUT;" ";PLACE$(2,FACE)
4150     IF CLRMON THEN 4190
4160     IF PLACE$(2,FACE)="" THEN PLACE$(2,FACE)=YOURS$(FACE)
4170     GOTO 4240
4190     IF PLACE$(2,FACE)="" THEN BR(FACE)=FACE:GOTO 4220                               ELSE BR(FACE)=VAL(PLACE$(2,FACE))
4200     IF BR(FACE)<1 OR BR(FACE)>7 THEN LOCATE ,26:PRINT SPC(14):GOTO 4130
4210     IF ASC(PLACE$(2,FACE))<56 THEN PLACE$(2,FACE)=MID$(PLACE$(2,FACE),2)
4220     COLOR 7,0:LOCATE ,24:PRINT "= ";
4230     COLOR 0,BR(FACE):PRINT PLACE$(2,FACE)+"     "
4240 NEXT
4260 COLOR 7,0
4270 LOCATE 15,K:PRINT "*Chosen ";
4280 LOCATE 9,K
4290 COLOR 1,4
4300 PRINT "  Check each face and its chosen color. ";
4310 COLOR 7,0
4320 PRINT SPC(79)" ";
4330 LOCATE 11,K
4340 COLOR 5,2
4350 PRINT "Press the spacebar to start over...  or,";
4360 COLOR ,0
4370 PRINT SPC(79)" ";
4380 LOCATE 13,K
4390 COLOR 4,6
4400 PRINT "if everything is okay press the `G' key."
4410 COLOR 7,0
4420 G$=INKEY$
4430 IF G$=" " THEN 3770
4440 IF G$<>"G" AND G$<>"g" THEN 4420
4450 RETURN
4460 END
key."
4410 COLOR 7,0
4420 G$=INKEY$
44