|
!'変形数独
PUBLIC NUMERIC N,AREA(0 TO 24,0 TO 24),IX(25,25),IY(25,25),RR(0 TO 15),GG(0 TO 15),BB(0 TO 15)
FOR I=0 TO 15
READ GG(I),RR(I),BB(I)
NEXT I
DATA 255 , 255 , 255
DATA 0 , 0 , 0
DATA 0 , 0 , 255
DATA 0 , 255 , 0
DATA 255 , 0 , 0
DATA 0 , 255 , 255
DATA 255 , 255 , 0
DATA 255 , 0 , 255
DATA 128 , 128 , 128
DATA 0 , 0 , 128
DATA 0 , 128 , 0
DATA 0 , 128 , 128
DATA 128 , 0 , 0
DATA 128 , 128 , 0
DATA 128 , 0 , 128
DATA 191 , 191 , 191
!'RESTORE 1
RESTORE 2
!'RESTORE 3
!'RESTORE 4
READ N
DIM M(0 TO N-1,0 TO N-1),P(N)
FOR I=0 TO N-1
FOR J=0 TO N-1
READ AREA(I,J)
NEXT J
NEXT I
MAT READ M
1 DATA 9
!'ブロックデータ(各々のマスは9マスずつ)
DATA 1,1,1,2,2,2,3,3,3
DATA 1,1,1,2,2,2,3,3,3
DATA 1,1,1,2,2,2,3,3,3
DATA 4,4,4,5,5,5,6,6,6
DATA 4,4,4,5,5,5,6,6,6
DATA 4,4,4,5,5,5,6,6,6
DATA 7,7,7,8,8,8,9,9,9
DATA 7,7,7,8,8,8,9,9,9
DATA 7,7,7,8,8,8,9,9,9
!'初期データ
DATA 0,0,4,0,0,0,0,5,0
DATA 0,0,8,0,0,0,2,0,9
DATA 0,0,3,0,0,4,0,0,0
DATA 0,0,0,0,2,0,3,8,7
DATA 0,0,0,5,0,7,0,0,0
DATA 7,4,6,0,3,0,0,0,0
DATA 0,0,0,2,0,0,4,0,0
DATA 3,0,7,0,0,0,9,0,0
DATA 0,9,0,0,0,0,5,0,0
2 DATA 9
!'ブロックデータ(各々のマスは9マスずつ)
DATA 1,1,2,2,2,2,2,3,3
DATA 1,1,2,2,2,3,3,3,3
DATA 1,1,2,4,4,4,3,3,3
DATA 1,1,1,4,5,5,5,5,5
DATA 6,6,6,4,4,4,5,5,7
DATA 6,6,8,4,9,9,5,5,7
DATA 6,6,8,4,9,9,7,7,7
DATA 6,8,8,8,9,9,7,7,7
DATA 6,8,8,8,8,9,9,9,7
!'初期データ
DATA 6,0,8,7,5,0,1,3,9
DATA 3,0,0,9,0,7,8,0,0
DATA 2,9,3,0,0,0,4,1,6
DATA 0,0,0,0,1,0,3,0,2
DATA 1,0,2,0,0,0,5,0,0
DATA 5,0,0,0,2,0,0,0,4
DATA 7,3,5,0,8,0,9,0,1
DATA 0,0,0,3,0,0,0,0,0
DATA 9,2,1,0,4,5,0,7,3
3 DATA 6
!'ブロックデータ(各々のマスは6マスずつ)
DATA 1,1,1,2,2,2
DATA 1,1,1,2,2,2
DATA 3,3,3,4,4,4
DATA 3,3,3,4,4,4
DATA 5,5,5,6,6,6
DATA 5,5,5,6,6,6
!'初期データ
DATA 0,0,0,5,6,0
DATA 4,5,0,0,2,0
DATA 2,0,0,0,0,0
DATA 0,0,0,0,0,5
DATA 0,2,0,0,3,6
DATA 0,1,3,0,0,0
4 DATA 12
!'ブロックデータ(各々のマスは12マスずつ)
DATA 1,1,1,1,2,2,2,2,3,3,3,3
DATA 1,1,1,1,2,2,2,2,3,3,3,3
DATA 1,1,1,1,2,2,2,2,3,3,3,3
DATA 4,4,4,4,5,5,5,5,6,6,6,6
DATA 4,4,4,4,5,5,5,5,6,6,6,6
DATA 4,4,4,4,5,5,5,5,6,6,6,6
DATA 7,7,7,7,8,8,8,8,9,9,9,9
DATA 7,7,7,7,8,8,8,8,9,9,9,9
DATA 7,7,7,7,8,8,8,8,9,9,9,9
DATA 10,10,10,10,11,11,11,11,12,12,12,12
DATA 10,10,10,10,11,11,11,11,12,12,12,12
DATA 10,10,10,10,11,11,11,11,12,12,12,12
!'初期データ
DATA 0, 5, 0, 0, 0, 8, 9, 0, 0, 7,10, 0
DATA 7,10, 0, 0, 0, 5, 6, 0, 0, 0, 9, 1
DATA 8, 0, 0, 0, 0, 0, 2, 0, 5, 0, 0, 0
DATA 0, 0,10, 0,11, 2, 0, 5, 0, 0, 0, 0
DATA 0, 0, 0, 5, 0, 0, 1, 0,10, 0, 0, 0
DATA 11, 2, 8, 0,10, 0, 0, 0, 6, 0, 7,12
DATA 9, 8, 0, 3, 0, 0, 0, 2, 0, 4, 6, 5
DATA 0, 0, 0,11, 0, 7, 0, 0, 1, 0, 0, 0
DATA 0, 0, 0, 0, 8, 0, 4,11, 0,12, 0, 0
DATA 0, 0, 0, 8, 0, 1, 0, 0, 0, 0, 0, 4
DATA 5, 6, 0, 0, 0, 4,11, 0, 0, 0, 1, 2
DATA 0, 4, 3, 0, 0,10, 7, 0, 0, 0, 5, 0
FOR J=0 TO N-1
FOR I=0 TO N-1
LET S=AREA(J,I)
LET P(S)=P(S)+1
IF P(S)>N THEN
PRINT "マスの数が異なります!!"
STOP
END IF
LET IX(S,P(S))=I
LET IY(S,P(S))=J
NEXT I
NEXT J
CALL BACKTRACK(M,0)
END
EXTERNAL SUB BACKTRACK(M(,),P)
IF P<N*N THEN
LET ROW=INT(P/N)
LET COL=MOD(P,N)
IF M(ROW,COL)<>0 THEN
CALL BACKTRACK(M,P+1)
ELSE
FOR K=1 TO N
IF CHECKRULE(M,ROW,COL,K)=1 THEN
LET M(ROW,COL)=K
CALL BACKTRACK(M,P+1)
LET M(ROW,COL)=0
END IF
NEXT K
END IF
ELSE
FOR I=0 TO N-1
FOR J=0 TO N-1
LET C=AREA(I,J)
CALL SETCOLOR(RR(C),GG(C),BB(C))
PRINT USING "###":M(I,J);
NEXT J
PRINT
NEXT I
PRINT
END IF
END SUB
EXTERNAL FUNCTION CHECKRULE(M(,),ROW,COL,K)
LET CHECKRULE=0
FOR Y=0 TO N-1 !列
IF M(Y,COL)=K THEN EXIT FUNCTION
NEXT Y
FOR X=0 TO N-1 !行
IF M(ROW,X)=K THEN EXIT FUNCTION
NEXT X
LET C=AREA(ROW,COL)
FOR I=1 TO N
IF M(IY(C,I),IX(C,I))=K THEN EXIT FUNCTION
NEXT I
LET CHECKRULE=1
END FUNCTION
EXTERNAL SUB SetColor(R,G,B)
OPTION CHARACTER Byte
LET EM_SETCHARFORMAT=BVAL("0444",16)
LET CHARFORMAT$=CHR$(60) & REPEAT$(CHR$(0),59)
LET CHARFORMAT$(8:8)=CHR$(64)
LET CHARFORMAT$(21:24)=CHR$(R) & CHR$(G) & CHR$(B) & CHR$(0)
CALL SendMessage(WinHandle("RICHEDIT"),EM_SETCHARFORMAT,1, CHARFORMAT$)
END SUB
EXTERNAL SUB SendMessage(hwnd,msg,wparam,lparam$)
ASSIGN "USER32.DLL","SendMessageA"
END SUB
|
|