/* プログラム開発用対戦プログラム Takahiro Inoue 2025/3/24 */ /*-------------------------------------------------------------------------------*/ /*対戦者1*/ %let _m1 = tester1 ; /*対戦者2*/ %let _m2 = tester2 ; /*-------------------------------------------------------------------------------*/ %let issue = 0 ; proc format ; value circle -1 = '●' 1 = '○' ; run ; data _info ; length Turn Y X1 - X8 8. ; Turn = 1 ; input Y X1 - X8 ; cards ; 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 4 0 0 0 -1 1 0 0 0 5 0 0 0 1 -1 0 0 0 6 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 ; run ; proc transpose data = _info out = _info1 ; var X1 - X8 ; by Turn Y ; run ; data _info2 ; set _info1 ; id = 'COL' || trim(compress(upcase(_name_), 'X')) || '_' || put(Y, 1.) ; keep Turn col1 id ; run ; proc transpose data = _info2 out = _info3(drop = _name_) ; var COL1 ; id id ; by Turn ; run ; data _hist ; delete ; run ; %macro platform ; data _null_ ; if ranbin(0,1,0.5) then do ; call symput('_black', "&_m1.") ; call symput('_white', "&_m2.") ; end ; else do ; call symput('_black', "&_m2.") ; call symput('_white', "&_m1.") ; end ; run ; %do _no = 1 %to 61 ; %if &_no ne 1 %then %do ; data _info3; length No Turn 8. xy $3. name $10. start end time 8. ; set _info4 ; xy = "&_xy" ; if Turn = -1 then name = "_black" ; else if Turn = 1 then name = "_white" ; start = &_start ; end = &_end ; time = end - start ; format start end E8601DT. ; run ; data _hist ; set _hist _info3 ; run ; %end ; data _info4 ; set _info3 ; No = &_no. ; array col(8,8) col1_1 - col1_8 col2_1 - col2_8 col3_1 - col3_8 col4_1 - col4_8 col5_1 - col5_8 col6_1 - col6_8 col7_1 - col7_8 col8_1 - col8_8 ; if no ne 1 then do; x = input(scan(xy, 1, ','), best.) ; y = input(scan(xy, 2, ','), best.) ; if col(x, y) = 99 then col(x, y) = Turn ; else do ; put 'ER' 'ROR: 選択ミス' no = xy = ; call symput('Issue', '1') ; goto exit ; end ; end ; do i = 1 to 8 ; do k = 1 to 8 ; if col(i, k) = 99 then col(i, k) = 0 ; if Turn = 1 then col(i, k) = col(i, k) * -1 ; end ; end ; /*反転処理*/ if no ne 1 then do; /* 横 右方向 */ if x lt 7 then do ; if col(x+1, y) = 1 then do i = 2 to 8 - X ; if col(x+i, y) = -1 then do ; do k = 1 to i - 1 ; col(x+k, y) = -1 ; end ; goto step11 ; end ; else if col(x+i, y) not in(-1, 1) then goto step11 ; end ; step11: end ; /* 横 左方向 */ if 2 lt x then do ; if col(x-1, y) = 1 then do i = 2 to x - 1 ; if col(x-i, y) = -1 then do ; do k = 1 to i - 1 ; col(x-k, y) = -1 ; end ; goto step12 ; end ; else if col(x-i, y) not in(-1, 1) then goto step12 ; end ; step12: end ; /* 縦 下方向 */ if y lt 7 then do ; if col(x, y+1) = 1 then do i = 2 to 8 - y ; if col(x, y+i) = -1 then do ; do k = 1 to i - 1 ; col(x, y+k) = -1 ; end ; goto step13 ; end ; else if col(x, y+i) not in(-1, 1) then goto step13 ; end ; step13: end ; /* 縦 上方向 */ if 2 lt y then do ; if col(x, y-1) = 1 then do i = 2 to y - 1 ; if col(x, y-i) = -1 then do ; do k = 1 to i - 1 ; col(x, y-k) = -1 ; end ; goto step14 ; end ; else if col(x, y-i) not in(-1, 1) then goto step14 ; end ; step14: end ; /* 斜め 右下方向 */ if x lt 7 and y lt 7 then do ; if col(x+1, y+1) = 1 then do i = 2 to 7 ; if 1 le x+i le 8 and 1 le y+i le 8 then do ; if col(x+i, y+i) = -1 then do ; do k = 1 to i - 1 ; col(x+k, y+k) = -1 ; end ; goto step15 ; end ; else if col(x+i, y+i) not in(-1, 1) then goto step15 ; end ; else goto step15 ; end ; step15: end ; /* 斜め 右上方向 */ if x lt 7 and 2 lt y then do ; if col(x+1, y-1) = 1 then do i = 2 to 7 ; if 1 le x+i le 8 and 1 le y-i le 8 then do ; if col(x+i, y-i) = -1 then do ; do k = 1 to i - 1 ; col(x+k, y-k) = -1 ; end ; goto step16 ; end ; else if col(x+i, y-i) not in(-1, 1) then goto step16 ; end ; else goto step16 ; end ; step16: end ; /* 斜め 左下方向 */ if 2 lt x and y lt 7 then do ; if col(x-1, y+1) = 1 then do i = 2 to 7 ; if 1 le x-i le 8 and 1 le y+i le 8 then do ; if col(x-i, y+i) = -1 then do ; do k = 1 to i - 1 ; col(x-k, y+k) = -1 ; end ; goto step17 ; end ; else if col(x-i, y+i) not in(-1, 1) then goto step17 ; end ; else goto step17; end ; step17: end ; /* 斜め 左上方向 */ if 2 lt x and 2 lt y then do ; if col(x-1, y-1) = 1 then do i = 2 to 7 ; if 1 le x-i le 8 and 1 le y-i le 8 then do ; if col(x-i, y-i) = -1 then do ; do k = 1 to i - 1 ; col(x-k, y-k) = -1 ; end ; goto step18 ; end ; else if col(x-i, y-i) not in(-1, 1) then goto step18 ; end ; else goto step18; end ; step18: end ; end ; if Turn = 1 then do i = 1 to 8 ; do k = 1 to 8 ; if col(i, k) in(-1, 1) then col(i, k) = col(i, k) * -1 ; end ; end ; /*選択可能セル判定*/ if no ne 61 then do ; again: Turn = Turn * -1 ; if Turn = 1 then do i = 1 to 8 ; do k = 1 to 8 ; if col(i, k) in(-1, 1) then col(i, k) = col(i, k) * -1 ; end ; end ; do x = 1 to 8 ; do y = 1 to 8 ; if col(x, y) = 0 then do ; /* 横 右方向 */ if x lt 7 then do ; if col(x+1, y) = 1 then do i = 2 to 8 - X ; if col(x+i, y) = -1 then do ; col(x, y) = 99 ; goto step01 ; end ; else if col(x+i, y) not in(-1, 1) then goto step01 ; end ; step01: end ; /* 横 左方向 */ if 2 lt x then do ; if col(x-1, y) = 1 then do i = 2 to x - 1 ; if col(x-i, y) = -1 then do ; col(x, y) = 99 ; goto step02 ; end ; else if col(x-i, y) not in(-1, 1) then goto step02 ; end ; step02: end ; /* 縦 下方向 */ if y lt 7 then do ; if col(x, y+1) = 1 then do i = 2 to 8 - y ; if col(x, y+i) = -1 then do ; col(x, y) = 99 ; goto step03 ; end ; else if col(x, y+i) not in(-1, 1) then goto step03 ; end ; step03: end ; /* 縦 上方向 */ if 2 lt y then do ; if col(x, y-1) = 1 then do i = 2 to y - 1 ; if col(x, y-i) = -1 then do ; col(x, y) = 99 ; goto step04 ; end ; else if col(x, y-i) not in(-1, 1) then goto step04 ; end ; step04: end ; /* 斜め 右下方向 */ if x lt 7 and y lt 7 then do ; if col(x+1, y+1) = 1 then do i = 2 to 7 ; if 1 le x+i le 8 and 1 le y+i le 8 then do ; if col(x+i, y+i) = -1 then do ; col(x, y) = 99 ; goto step05 ; end ; else if col(x+i, y+i) not in(-1, 1) then goto step05 ; end ; else goto step05 ; end ; step05: end ; /* 斜め 右上方向 */ if x lt 7 and 2 lt y then do ; if col(x+1, y-1) = 1 then do i = 2 to 7 ; if 1 le x+i le 8 and 1 le y-i le 8 then do ; if col(x+i, y-i) = -1 then do ; col(x, y) = 99 ; goto step06 ; end ; else if col(x+i, y-i) not in(-1, 1) then goto step06 ; end ; else goto step06 ; end ; step06: end ; /* 斜め 左下方向 */ if 2 lt x and y lt 7 then do ; if col(x-1, y+1) = 1 then do i = 2 to 7 ; if 1 le x-i le 8 and 1 le y+i le 8 then do ; if col(x-i, y+i) = -1 then do ; col(x, y) = 99 ; goto step07 ; end ; else if col(x-i, y+i) not in(-1, 1) then goto step07 ; end ; else goto step07; end ; step07: end ; /* 斜め 左上方向 */ if 2 lt x and 2 lt y then do ; if col(x-1, y-1) = 1 then do i = 2 to 7 ; if 1 le x-i le 8 and 1 le y-i le 8 then do ; if col(x-i, y-i) = -1 then do ; col(x, y) = 99 ; goto step08 ; end ; else if col(x-i, y-i) not in(-1, 1) then goto step08 ; end ; else goto step08; end ; step08: end ; end ; end ; end ; if Turn = 1 then do i = 1 to 8 ; do k = 1 to 8 ; if col(i, k) in(-1, 1) then col(i, k) = col(i, k) * -1 ; end ; end ; if max(of col(*)) ne 99 and fr = 1 then do ; call symput('Issue', '2') ; goto exit ; end ; else if max(of col(*)) ne 99 then do ; fr = 1 ; goto again ; end ; fr = . ; end ; exit: drop i k x y xy ; run ; data _null_ ; set _info4(keep = turn) ; call symput('_turn', trim(put(turn, best. -L))) ; run ; proc transpose data = _info4 out = _info5 ; var col: ; by No Turn ; run ; data _info6 ; set _info5 ; y = input(substr(_name_, 6, 1), best.) ; id = 'X' || substr(_name_, 4, 1) ; proc sort ; by No Turn Y ; run ; proc transpose data = _info6 out = _info(drop = _name_) ; var col1 ; by No Turn Y ; id id ; run ; data _null_ ; call symput('_start', trim(put(input(put(today(), yymmdd10.) || 'T' || put(time(), tod8.), E8601DT.), best. -L))) ; run ; %if &_turn = -1 %then %do ; %&_black. ; %end ; %if &_turn = 1 %then %do ; %&_white. ; %end ; data _null_ ; call symput('_end', trim(put(input(put(today(), yymmdd10.) || 'T' || put(time(), tod8.), E8601DT.), best. -L))) ; run ; %end ; /*結果出力*/ title "黒(-1): &_black. / 白(1): &_white." ; proc print data = _info width = min noobs ; var y x1 - X8 ; format x: circle. ; run ; proc transpose data = _info out = _wk010 ; var X1 - X8 ; by No Turn Y ; run ; proc freq data = _wk010 ; table col1 / nocum ; format col1 circle. ; run ; proc means data = _hist n mean min q1 median q3 max ; var time ; class turn ; run ; /*履歴*/ proc transpose data = _hist out = _hist1 ; var col: ; by No xy name Turn ; run ; data _hist2 ; set _hist1 ; y = input(substr(_name_, 6, 1), best.) ; id = 'X' || substr(_name_, 4, 1) ; proc sort ; by No Turn name xy Y ; run ; proc transpose data = _hist2 out = _hista(drop = _name_) ; var col1 ; by No Turn xy Y ; id id ; run ; proc print width = min noobs ; by No Turn xy ; run ; %mend ; %platform ; * eof ;