2021年4月4日日曜日

SASで囲碁盤を再現。



ステイホーム中に囲碁を勉強し始めました。

ルールやっと覚えたところで、コンピュータの一番弱い設定のやつに勝ったり負けたりのレベルですが。。強くなって碁盤の上で繰り広げられる熱い戦いを理解できるようになっていきたいです。


てことで、SASで囲碁を再現してみたくなったので勢いで書いてみました。プログラムは勢いで適当に書いたので、ひどい感じです。


/*** 碁石の位置 (y軸は碁盤に合わせて逆に指定[上から1,2,3...]) *******/
data pos;
input black_x black_y_reverse white_x white_y_reverse;
cards;
2 2 8 2
2 8 3 8
3 7 . .
;

/*** 碁盤の線 *********/
data line;
 do line_x=1 to 9;
 do line_y_reverse=1, 9;
   line_grp=10+line_x;
   output;
 end;
 end;
 do line_y_reverse=1 to 9;
 do line_x=1, 9;
   line_grp=20+line_y_reverse;
   output;
 end;
 end;
run;

data igo;
 set line pos;
run;

/*** PLOT *******************/
proc template ;
 define statgraph tmpl_igo ;
   begingraph;

     layout overlay /
        wallcolor=CXFFC864 /* 碁盤の色 */
        aspectratio=1
        xaxisopts=( display=none displaysecondary=(line ticks tickvalues)
                    linearopts=( viewmin=1 viewmax=9
                                 tickvaluesequence=(start=1 end=9 increment=1) ) )
                                  
        yaxisopts=( reverse=true /* y軸の数値の順番を逆 [上から下] にする) */
                    display=(line ticks tickvalues)
                    linearopts=( viewmin=1 viewmax=9
                                 tickvaluesequence=(start=1 end=9 increment=1)
                                 tickdisplaylist=( "一" "二" "三" "四" "五" "六" "七" "八" "九") ) );

        /* 碁盤の線 */
        seriesplot x=line_x y=line_y_reverse / group=line_grp lineattrs=(color=black pattern=solid);
        
        /* 碁石(黒)を配置 */
        scatterplot x=black_x y=black_y_reverse /
                       filledoutlinedmarkers=true
                       markerfillattrs=(color=black) 
                       markeroutlineattrs=(color=black thickness=1)
                       markerattrs=(symbol=circlefilled size=40 )
                       dataskin=matte;

        /* 碁石(白)を配置 */
        scatterplot x=white_x y=white_y_reverse /
                       filledoutlinedmarkers=true
                       markerfillattrs=(color=white) 
                       markeroutlineattrs=(color=gray thickness=1)
                       markerattrs=(symbol=circlefilled size=40 )
                       dataskin=matte;
        
     endlayout;

   endgraph;
 end;
run;

proc sgrender data=igo template=tmpl_igo;
run;