つづき
EXTERNAL SUB try(i, piece(,),nam$(), shape(,), M,N,board$(,), row,col) !試行 FOR j=2 TO PIECE_COUNT !残りの片を使って ※ IF piece(j,1)=0 THEN LET nm$=UCASE$(nam$(j)) FOR t=1 TO 8 !回転や裏返しを試す IF nm$="Z" AND MOD(t-1,4)>=2 THEN !点対称は除く ELSE LET shp=get_piece(j,t) !形状を得る CALL fit_piece(shp,row,col, row2,col2, shape) !位置補正 CALL check_site(shp,row2,col2, K, shape, M,N,board$) !うまく置ければ IF K>PIECE_SIZE THEN LET piece(j,1)=t !向き ※使用中 LET piece(j,2)=col2 !位置 LET piece(j,3)=row2 CALL put_piece(nam$(j),shp,row2,col2, shape, board$) !片を置く !!!CALL display_board(M,N,board$) !debug IF i=PIECE_COUNT THEN !すべて並んだら LET ANSWER_COUNT=ANSWER_COUNT+1 PRINT ANSWER_COUNT CALL display_board(M,N,board$) !配置の表示 ELSE !途中なら SET DRAW mode hidden !配置アニメーション CLEAR FOR k=1 TO PIECE_COUNT IF piece(k,1)>0 THEN SET AREA COLOR k+1 DRAW display_piece(k,piece(k,1),shape) WITH SHIFT(piece(k,2),piece(k,3)) END IF NEXT k DRAW grid SET DRAW mode explicit CALL search_site(M,N,board$, row,col, rr,cc) !次の空きマスを探す !!!PRINT rr;cc CALL try(i+1, piece,nam$, shape, M,N,board$, rr,cc) !次の片へ END IF CALL put_piece(".",shp,row2,col2, shape, board$) !元に戻す END IF IF POS("XO",nm$)>0 THEN EXIT FOR !片面型は除く IF POS("TUVW",nm$)>0 AND t>=4 THEN EXIT FOR IF nm$="I" AND t>=2 THEN EXIT FOR END IF NEXT t LET piece(j,1)=0 !未使用 END IF NEXT j END SUB
|