gl2
コマンドと特殊ルールのはさみ将棋
慶應義塾大学大学院 理工学研究科 開放環境科学専攻
修士
1
年 塩谷 昌典
1 J
らしさ
アプリケーションを開発するときにどのような言語を用いるかは,その作る人がどのような言語
を得意とするかによると思う。また,要求仕様がある場合には,その要求に対応した言語を用いる
ことになる。最近では最も一般的であると思われるのは,やはり
Java
ではないかと思う。また,
C
や
C++
なども,まだまだ根強いであろう。もちろんほかにも言語は存在するし,開発する場面
や状況によって選択されると思われる。
一方,
J
というのは,
APL
周辺ならばともかく,一般に周知の言語だとは言いがたいと思う。そ
れは,書店に赴き関連図書の数を見れば明らかであろう。
それでも,
J
でアプリケーションを作ろうと思ったのは,現時点では他の言語よりも
J
の方が
自分身近だったからである。今回のプログラムは,
J
らしさといわれるものや,
J
の特徴をうまく
使ったとは言いがたいが,
J
を用いてアプリケーションと呼べるものがどこまでできるかを探る意
味でも,今回の開発は興味深いものとなった。
ここで紹介するプログラムは
J 5.01a for Windows
で動作確認をしている。
2 gl2
コマンド
最近の
J
には,ウィンドウドライバコマンドの中に
gl2
コマンドというものがある。これは,
isigraph
という領域を操作するコマンドで,ウィンドウの中にこの
isigraph
の部分を割り当
て,グラフィカルな操作を行うものである。これらを使えば,将棋の盤面をグラフィカルに表示す
ることができる。実行画面の左側の背景が白の部分が
isigraph
の領域となっている。直線などの
描画に関するものは
gl2
コマンドを使えばよい。
gl2
は比較的簡単で,
J
の
Help
を参照すればわ
かるものがほとんどだと思われる。
また,
Mapping Mode
は,
gl2
コマンドの論理的な単位がどのようにディスプレイ表面上に写像
されるかに影響するものであり,
isigraph Event
は,キーボードおよびマウスによる
isigraph
コントロールを,反映させるものである。
2.1 Mapping Mode
Mapping Mode
は,
J 5.01a for Windows
ではバージョン
4
と大きく異なる。したがって,プ
ログラムによっては互換性がなくなる恐れがある。実際,ここで紹介するはさみ将棋のプログラム
は,バージョン
4
では表示がおかしくなってしまう。
バージョン
5
での
Mapping Mode
は,次の
4
種類がある。
MM DEFAULT
左下
0 0
,右上
1000 1000
MM RIGHTDOWN
左上
0 0,
右下
1000 1000
MM RAW
左上
0 0,
単位はピクセル
MM TWIPS
左上
0 0, twip (win32
のみ
)
Mapping Mode
は,
gl2
コマンドである
glmap
によって設定する。
MM DEFAULT Mapping Mode
のデフォルトである。左下が
(0, 0)
で,右上が
(1000, 1000)
と
なっている。
x
軸は水平方向右に増え,
y
軸は垂直方向上に増える。また,
glclear ’’
が
実行されたときもこのデフォルトに戻る。
MM RIGHTDOWN y
軸方向が下向きなこと以外は
MM_DEFAULT
と同じである。
MM RAW x
軸,
y
軸の方向は
MM_RIGHTDOWN
と同じだが,数値の単位がピクセルである。
MM TWIPS x
軸,
y
軸の方向は
MM_RIGHTDOWN
と同じだが,数値の単位が
twip
である。
twip
とは,
1/20pt
ことで,
1pt
は,
1/72
インチである。したがって,
1twip
は,
1/1440
インチ
である。
2.2 isigraph Event
マウスの動きやキー入力に対応させるためには,
isigraph Event
を用いる。
isigraph
ではマウス操作を感知できるので,それにあわせてプログラムが動くようにすれば,
マウスによって駒を動かすことができる。
マウス操作に用いるものは,
mmove
マウス移動
mbldbl
左ボタンダブルクリック
mbldown
左ボタンクリック
mblup
左ボタンクリック解除(ボタンを離したとき)
mbrdbl
右ボタンダブルクリック
mbrdown
右ボタンクリック
mbrup
右ボタンクリック解除(ボタンを離したとき)
の
7
つである。これらを使えば,マウスの動作に合わせて何かをさせることができる。
例えば,
aaa
ウィンドウ内の
bbb
という
isigraph
領域でマウスを押したときに動作させる動
詞は,
aaa_bbb_mbldown=: 3 : 0
...
)
という風に記述する。
3
特殊なはさみ将棋のルール
今回のプログラムに使った題材ははさみ将棋であるが,ルールは単なるはさみ将棋ではなく,か
なり特殊なものである。また,アプリケーションを作るうえでも,こういったルールはしっかりと
確認しておく必要がある。そのルールは以下のようになっている。
1.
ゲーム盤面
•
盤面のマス数は『
6
×
6
』
2.
駒の移動
•
駒は縦方向(前後)
,横方向(左右)のいずれかに,いくらでも移動可能
•
縦方向,横方向に自分の駒が二つ以上になっても構わない
•
自分の駒を飛び越えて進むことはできない
•
相手の駒は
1
つまでは飛び越えて進むことが可能(
2
つ以上は禁止)
3.
駒のはさみ方(取り方)
•
相手の駒を自分の駒で縦方向または横方向に挟めば,その駒を取ることができる
•
相手の駒の間に自分の駒を移動させた場合,挟まれたことにはならない(自分の駒の間
に相手の駒が移動した場合も同様)
•
盤の四隅にいる駒は
2
方向を囲むことで取ることができる
•
挟む駒の数はいくつでも構わない(複数の駒を同時に挟むことも可能)ただし,四隅の
駒は
1
つしか挟めない(複数挟んだ状態でも駒は取れない)
4.
取った駒の扱い
•
ゲームの中で
1
回だけ,取った駒を自由な場所に打つことが可能(打たなくてもよい)
•
打った駒によって相手の駒を挟んでも構わない
•
相手の駒の間に自分の駒を打っても,挟まれたことにはならない
5.
勝敗決定方法
•
先に相手の駒を
1
個以下にした方が勝ち(まだ打っていない駒
1
つも含めて
1
個以下)
•
駒を移動することができなくなった場合は負け
•
相互の総手数が
70
手になった時点で勝負がついていない場合,残り駒の多い方が勝ち
4
スクリプトの説明
4.1
グローバル変数
はさみ将棋のゲームに関する変数は以下のとおりである。
vs
対戦モード
mouse
マウスの状態 左ボタン正常クリックで
1
game
ゲームの状態 試合中は
1
tesuu
試合中の総手数
KomaSente,KomaGote
盤面上のコマの数
MochiSente,MochiGote
持っているコマの数
Banmen
盤面の状態の行列
moji
打った手の記録
w,h
isiBanmen
のサイズ(ピクセル)
x1,y1,x2,y2
動かすコマの座標
ko
動かすコマの情報
1, 1
4.2
主な動詞
HasamiShogi run
実行関数。引数,戻り値なし。
Shokika
変数を初期化するもの。引数,戻り値なし。
IdoHantei
左引数に盤面の行列,右引数に移動元,移動先の座標,動かすコマ情報をとる。そ
のコマが移動可能なら
1
を返す。移動できないときは
0
を返す。
IdoShori
右引数にコマの座標をとり,移動させる。この際,
Banmen
が書き換えられる。
KieruHantei
左引数に盤面の行列,右引数に移動したコマの座標をとり,その移動によってコ
マが消えるかを判定する。戻り値として,消えるこまの座標を返す。
KieruShori
右引数に消えるコマの座標を取り,
Banmen
を書き換える。
ShobuHantei
引数,戻り値なしで,その時点での勝負判定をする。
DrawBanmen
右引数に
Banmen
をとり,それに従って,
isiBanmen
を描画する。
computer
対戦モードの場合,この関数によって
com
側の手を考える。
TorareruHantei computer
から呼び出され,仮に移動したとして取られる可能性があるかどう
かを判定する。
5
スクリプト
NB. 6*6 Hasami ShogiNB. Programed by Masanori Shioya NB. Last modified 2002/12/05
path=:’e:\HasamiShogi\’ NB. Files’ Fullpath bmppath=:’default\’ NB. Bmp Directory coinsert ’jgl2’ NB. Load gl2 Command load ’gl2’
HASAMISHOGI=: 0 : 0 NB. Settings of Window pc HasamiShogi;
xywh 233 112 14 14;cc isiSente isipicture ws_border; xywh 73 12 14 14;cc isiGote isipicture ws_border; xywh 100 10 120 120;cc isiBanmen isigraph ws_border; xywh 260 8 40 8;cc mc radiobutton;cn "man vs com"; xywh 260 16 40 8;cc cm radiobutton group;cn "com vs man"; xywh 260 24 40 8;cc mm radiobutton group;cn "man vs man"; xywh 260 40 40 10;cc btnStart button;cn "Start";
xywh 260 55 40 10;cc btnReset button;cn "Reset"; xywh 260 132 40 10;cc btnEnd button;cn "E N D"; xywh 10 10 50 132;cc te editm ws_vscroll es_readonly; setfont te "Courier New" 11;
xywh 104 132 10 10;cc yoko1 static ss_center;cn "A"; xywh 124 132 10 10;cc yoko2 static ss_center;cn "B"; xywh 144 132 10 10;cc yoko3 static ss_center;cn "C"; xywh 164 132 10 10;cc yoko4 static ss_center;cn "D"; xywh 184 132 10 10;cc yoko5 static ss_center;cn "E"; xywh 204 132 10 10;cc yoko6 static ss_center;cn "F"; xywh 90 116 10 10;cc tate1 static ss_center;cn "1"; xywh 90 96 10 10;cc tate2 static ss_center;cn "2"; xywh 90 76 10 10;cc tate3 static ss_center;cn "3"; xywh 90 56 10 10;cc tate4 static ss_center;cn "4"; xywh 90 36 10 10;cc tate5 static ss_center;cn "5"; xywh 90 16 10 10;cc tate6 static ss_center;cn "6"; xywh 260 110 40 10;cc lblSente static;cn "Sente="; xywh 260 100 40 10;cc lblGote static;cn "Gote ="; xywh 260 85 40 10;cc lblTesuu static;cn "Tesuu="; xywh 260 70 40 10;cc msg static;cn "";
pas 10 10;pcenter; )
HasamiShogi_run=: 3 : 0 NB. Run Verb wd HASAMISHOGI vs=:1 glclear ’’ glmap MM_RAW Shokika ’’ wd ’pshow;ptop 1’ )
Shokika=: 3 : 0 NB. Initialize Verb mouse=: game=: tesuu=: 0
KomaSente =:KomaGote =: 6 MochiSente=:MochiGote=: 0 Banmen=:(-b),(4 6$0),b=.6#1 moji=:’’
wd ’set lblSente "’,’Sente= ’,(":KomaSente),’"’ wd ’set lblGote "’ ,’Gote = ’,(":KomaGote) ,’"’ wd ’set te "’,moji,’"’ glsel isiBanmen glmap MM_RAW ’w h’=:glqwh ’’ DrawBanmen Banmen )
HasamiShogi_btnStart_button=: 3 : 0 NB. Start Button if. game=1 do. return. end.
HasamiShogi_btnReset_button ’’ game=:1
wd ’set msg "sente ban"’ if. _1=vs do. computer ’’ end. )
HasamiShogi_btnReset_button=: 3 : 0 NB. Reset Button Shokika ’’
wd ’set lblTesuu "’,’Tesuu= ’,(":tesuu),’"’ wd ’set msg ""’
)
HasamiShogi_close=: 3 : 0 glclear ’’
wd’pclose’ )
HasamiShogi_mc_button=: 3 : 0 NB. Radio Button Shori if. game=1 do. radio ’’ else. vs=:1 end.
)
HasamiShogi_cm_button=: 3 : 0
if. game=1 do. radio ’’ else. vs=:_1 end. )
HasamiShogi_mm_button=: 3 : 0
if. game=1 do. radio ’’ else. vs=:0 end. )
radio=: 3 : 0 select. vs
case. 1 do. wd ’set mc 1’ case. _1 do. wd ’set cm 1’ case. 0 do. wd ’set mm 1’ end.
)
IdoHantei=: 4 : 0 NB.Ido Hantei t=.0
if. 0=game do. t=.0 end. ’tx1 ty1 tx2 ty2 k’=.y. ban=.|.x.
if. (tx1~:tx2)*.(ty1=ty2) do.
if. 1>+/k=tempx=.(>:tx1<.tx2)}.(tx1>.tx2){.ty1{ban do. if. 2>+/(-k)=tempx do. t=.1 end.
end.
elseif. (tx1=tx2)*.(ty1~:ty2) do.
if. 1>+/k=tempy=.(>:ty1<.ty2)}.(ty1>.ty2){.tx1{|:ban do. if. 2>+/(-k)=tempy do. t=.1 end.
end. end. t )
IdoShori=: 3 : 0 NB. Ido Shori ’x1 y1 x2 y2’=:y.
if. -.*/(x1,y1)=(x2,y2) do. Banmen=:|.0 (<y1,x1)} |.Banmen end. Banmen=:|.ko (<y2,x2)} |.Banmen
tesuu=:>:tesuu
moji=:({.x1}.’ABCDEF’),(":>:y1),’ --> ’,({.x2}.’ABCDEF’),(":>:y2),CRLF,moji wd ’set lblTesuu "’,’Tesuu= ’,(":tesuu),’"’
wd ’set te "’,moji,’"’ )
KieruHantei=: 4 : 0 NB. Kieru Hantei ban=.|.x.
’tx2 ty2 k’=.y. m=.’’
tempx=.tx2
if. 0<tempx=.<:tempx do. NB. Check left while. (-k)=tempx{ty2{ban do.
if. 1>tempx do. break. end. tempx=.<:tempx
end.
if. k=tempx{ty2{ban do. m=.m,<"1 ty2,"0 >:tempx+i.<:tx2-tempx end. end.
tempx=.tx2
if. 5>tempx=.>:tempx do. NB. Check right while. (-k)=tempx{ty2{ban do.
if. 4<tempx do. break. end. tempx=.>:tempx
end.
if. k=tempx{ty2{ban do. m=.m,<"1 ty2,"0 >:tx2+i.<:tempx-tx2 end. end.
tempx=.tx2 tempy=.ty2
if. 5>tempy=.>:tempy do. NB. Check up while. (-k)=tx2{tempy{ban do.
if. 4<tempy do. break. end. tempy=.>:tempy
end.
if. k=tx2{tempy{ban do. m=.m,<"1 (>:ty2+i.<:tempy-ty2) ,"0 tx2 end. end.
tempy=.ty2
if. 0<tempy=.<:tempy do. NB. Check down while. (-k)=tx2{tempy{ban do.
if. 1>tempy do. break. end. tempy=.<:tempy
end.
if. k=tx2{tempy{ban do. m=.m,<"1 (>:tempy+i.<:ty2-tempy) ,"0 tx2 end. end.
if. (*/4 5=tx2,ty2)*.(k=5{4{ban)*.((-k)=5{5{ban) do. m=.m,(<5 5) end. if. (*/5 4=tx2,ty2)*.(k=4{5{ban)*.((-k)=5{5{ban) do. m=.m,(<5 5) end. if. (*/0 4=tx2,ty2)*.(k=1{5{ban)*.((-k)=0{5{ban) do. m=.m,(<5 0) end. if. (*/1 5=tx2,ty2)*.(k=0{4{ban)*.((-k)=0{5{ban) do. m=.m,(<5 0) end. if. (*/4 0=tx2,ty2)*.(k=5{1{ban)*.((-k)=5{0{ban) do. m=.m,(<0 5) end. if. (*/5 1=tx2,ty2)*.(k=4{0{ban)*.((-k)=5{0{ban) do. m=.m,(<0 5) end. if. (*/0 1=tx2,ty2)*.(k=1{0{ban)*.((-k)=0{0{ban) do. m=.m,(<0 0) end. if. (*/1 0=tx2,ty2)*.(k=0{1{ban)*.((-k)=0{0{ban) do. m=.m,(<0 0) end. m
)
KieruShori=: 3 : 0 NB. Kieru Shori Banmen=:|.0 y.} |.Banmen
KomaSente=:+/(,Banmen)e.1 KomaGote =:+/(,Banmen)e._1 select. ko
case. 1 do.
if. (0=MochiSente)*.(KomaGote<6+(|MochiGote)) do. MochiSente=:1 end. case. _1 do.
if. (0=MochiGote)*.(KomaSente<6+(|MochiSente)) do. MochiGote=:1 end. end.
if. 1=MochiSente do. temps=.(":KomaSente),’ + 1’ else. temps=.":KomaSente end. if. 1=MochiGote do. tempg=.(":KomaGote) ,’ + 1’ else. tempg=.":KomaGote end. wd ’set lblSente "’,’Sente= ’,temps,’"’
wd ’set lblGote "’ ,’Gote = ’,tempg,’"’ )
ShobuHantei=: 3 : 0 NB. Shobu Hantei
if. (2>KomaGote+0<MochiGote)+.temp=.(2>KomaSente+0<MochiSente) do. game=:0
wd ’set msg "’,(,>(<:+:temp){.’gote win!’;’sente win!’),’"’ wd ’beep 1’
elseif. 70<:tesuu do. game=:0
if. (KomaGote+0<MochiGote)>(KomaSente+0<MochiSente) do. temp=.’gote win!’
elseif. (KomaGote+0<MochiGote)<(KomaSente+0<MochiSente) do. temp=.’sente win!’ elseif. 1 do. temp=.’draw game’ end. wd ’set msg "’,temp,’"’ wd ’beep 1’ end. )
HasamiShogi_isiBanmen_mbldown=: 3 : 0 NB. Mouse Button Left Down if. game=0 do. return. end.
’x y’=.2{.".sysdata
if. 0=2|tesuu do. ko=:1 else. ko=:_1 end. i=.<.6*x%w
j=.<.6*y%h
if. ko=i{j{|.Banmen do. mdx1=:i
mdy1=:j mouse=:1 end. )
HasamiShogi_isiBanmen_mmove=: 3 : 0 NB. Mouse Move if. mouse=0 do. return. end.
’x y’=.2{.".sysdata
DrawBanmen |. 0 (<mdy1,mdx1)} |.Banmen glbmpxywh (x-10),(h-y+10),<.(w%9),h%9
glbmp path,bmppath,(,>ko{.’sente.bmp’;’gote.bmp’) glshow ’’
)
HasamiShogi_isiBanmen_mblup=: 3 : 0 NB. Mouse Button Left Up if. mouse=0 do. return. end.
mouse=:0
’x y’=:2{.".sysdata mdx2=.<.6*x%w mdy2=.<.6*y%h temp=.0
if. (0=mdx2{mdy2{|.Banmen)*.(Banmen IdoHantei mdx1,mdy1,mdx2,mdy2,ko) do. IdoShori mdx1,mdy1,mdx2,mdy2
temp=.1
if. 0<#m=.(Banmen KieruHantei x2,y2,ko) do. KieruShori m end. else. wd ’beep 1’
end.
DrawBanmen Banmen ShobuHantei ’’
if. temp*.|vs do. computer ’’ end. )
if. 0=game do. return. end.
if. 0>:ko{.MochiSente,MochiGote do. return. end. if. 0=2|tesuu do. ko=:1 else. ko=:_1 end. ’x y’=.2{.".sysdata
i=.<.6*x%w j=.<.6*y%h ban=.|.Banmen temp=.0
if. 0=i{j{ban do.
".,>ko{.’MochiSente=:_1’;’MochiGote=:_1’ Banmen=:|.ko (<j,i)} |.Banmen
tesuu=:>:tesuu
moji=:’mochi> ’,({.i}.’ABCDEF’),(":>:j),CRLF,moji wd ’set lblTesuu "’,’Tesuu= ’,(":tesuu),’"’ wd ’set te "’,moji,’"’
KomaSente=:+/(,Banmen)e.1 KomaGote =:+/(,Banmen)e._1
wd ’set lblSente "’,’Sente= ’,(":KomaSente),’"’ wd ’set lblGote "’ ,’Gote = ’,(":KomaGote) ,’"’ x1=:x2=:i
y2=:y2=:j
if. 0<#m=.(Banmen KieruHantei x2,y2,ko) do. KieruShori m end. temp=.1
else. wd ’beep 1’ end.
DrawBanmen Banmen ShobuHantei ’’
if. temp*.|vs do. computer ’’ end. )
DrawBanmen=: 3 : 0 NB. Banmen wo byouga suru glsel isiBanmen
glrect 0 0,w,h
gllines "1 (>. 0 ,. ((>:i.5)*h%6) ,. w ,. (>:i.5)*h%6 ) gllines "1 (>. ((>:i.5)*w%6) ,. 0 ,. ((>:i.5)*w%6) ,. h ) i=.0
while. i<6 do. j=.0 while. j<6 do. select. (i{j{y.) case. 1 do. glbmpxywh (<.7+i*w%6),(<.5+<:j*h%6),<.(w%9),h%9 glbmp path,bmppath,’sente.bmp’ case. _1 do. glbmpxywh (<.7+i*w%6),(<.5+<:j*h%6),<.(w%9),h%9 glbmp path,bmppath,’gote.bmp’ end. j=.>:j end. i=.>:i end. glshow ’’
wd ’set msg "’,(,>(<:+:2|tesuu){.’gote ban’;’sente ban’),’"’ if. 1=MochiSente do. wd ’set isiSente ’,path,bmppath,’sentes.bmp’ else. wd ’set isiSente ’,’""’ end.
if. 1=MochiGote do. wd ’set isiGote ’ ,path,bmppath,’gotes.bmp’ else. wd ’set isiGote ’ ,’""’ end.
)
NB. Computer Algorithm
NB. Sente Gote wo handannshite 1 te utsu NB. Com ha x1 y1 x2 y2 wo kimete
NB. Ido sase egaku. Sonogo ShobuHantei shite kaesu. computer=: 3 : 0
if. game=0 do. return. end.
if. 0=2|tesuu do. ko=:1 else. ko=:_1 end. if. 16>:tesuu do.
’toru idomae idogo utsu’ =:100 85 45 45
’to1you to1me to2you to2me nayou name kado’=:30 15 _5 20 _5 10 15 else.
if. 0<ko*(KomaSente+MochiSente)-(KomaGote+MochiGote) do. ’toru idomae idogo utsu’ =:100 85 85 65
’to1you to1me to2you to2me nayou name kado’=:15 15 _5 15 _5 15 5 else.
’toru idomae idogo utsu’ =:100 65 65 80
’to1you to1me to2you to2me nayou name kado’=: 5 15 0 15 0 15 5 if. 0>:ko{.MochiGote,MochiSente do. to1you =:_5 end.
end. end. table1=:a:
cx1=.cy1=.cx2=.cy2=.0 for. i.6 do.
for. i.6 do. for. i.6 do.
for. i.6 do.
if. (ko=cx1{cy1{|.Banmen)*.(0=cx2{cy2{|.Banmen) do. if. Banmen IdoHantei cx1,cy1,cx2,cy2,ko do.
table1=:table1,(<cx1,cy1,cx2,cy2,0) end. end. cy2=.>:cy2 end. cy2=.0 cx2=.>:cx2 end. cx2=.0 cy1=.>:cy1 end. cy1=.0 cx1=.>:cx1 end. table1=:}."1 table1 if. 0>:#table1 do.
game=:0 goto_end. end. i=.0
for. i.#table1 do. ten=.0
’cx1 cy1 cx2 cy2’=.}:,>i{table1
Ban2=.|.0 (<cy1,cx1)} ko (<cy2,cx2)} |.Banmen m=.Ban2 KieruHantei cx2,cy2,ko
if. #m do. Ban2=.|.0 m} |.Ban2 end. ten=.toru*#m NB. kona ga toreru ka?
ten=.ten +idomae* Banmen TorareruHantei cx1,cy1,-ko NB. koma ga torareru ka? ten=.ten - idogo* Ban2 TorareruHantei cx2,cy2,-ko NB. koma ga torareru ka? ten=.ten - Banmen Tonari cx1,cy1,ko NB. tonari no yousu
ten=.ten + Ban2 Tonari cx2,cy2,ko NB. tonari no yousu table1=:(<cx1,cy1,cx2,cy2,ten) i } table1 i=.>:i end. table1=:((# i.@$)(>./{:"1>table1)={:"1>table1){table1 ’cx1 cy1 cx2 cy2’=.}:,>(?#table1){table1 t=.0
if. 1=".>ko{.’MochiSente’;’MochiGote’ do.
if. 2>ko*(KomaSente+MochiSente)-(KomaGote+MochiGote) do. table2=.a:
mx=.my=.0 for. i.6 do.
for. i.6 do.
if. 0=mx{my{|.Banmen do.
if. 0<temp=.#Banmen KieruHantei mx,my,ko do. table2=.table2,(<mx,my,utsu*temp) end. end. my=.>:my end. my=.0 mx=.>:mx end.
if. 0<#}.table2 do.
if. ({:,>{.table1\:{:"1>table1) < {:t2=.,>{.table2\:{:"1>table2 do. ’cx1 cy1’=.’cx2 cy2’=.}:t2 ".>ko{.’MochiSente=:_1’;’MochiGote=:_1’ t=.1 end. end. end. end. IdoShori cx1,cy1,cx2,cy2
if. t do. wd ’set te "’,(moji=:’mochi’,5}.moji),’"’ end. if. 0<#m=.(Banmen KieruHantei x2,y2,ko) do. KieruShori m end. label_end. DrawBanmen Banmen ShobuHantei ’’ ) TorareruHantei=: 4 : 0 ban=.|.x. ’tx ty k’=.y. line=.temp=.1 4$0 if. (0<:<:tx)*.(5>:>:tx) do.
if. (k=(<:tx){ty{ban)*.(0=(>:tx){ty{ban) do. if. 0<+/k=(>:tx){"1 ban do.
temp=.temp, ((>:tx),.(# i.@$)k=(>:tx){"1 ban),"1(>:tx),ty end.
if. 0<+/k=(tx-4){.ty{ban do.
temp=.temp, (((# i.@$)k=ty{ban),.ty),"1(>:tx),ty end.
end.
if. (k=(>:tx){ty{ban)*.(0=(<:tx){ty{ban) do. if. 0<+/k=(<:tx){"1 ban do.
temp=.temp, ((<:tx),.(# i.@$)k=(<:tx){"1 ban),"1(<:tx),ty end.
if. 0<+/k=(tx-1){.ty{ban do.
temp=.temp, (((# i.@$)k=ty{ban),.ty),"1(<:tx),ty end.
end. end.
if. (0<:<:ty)*.(5>:>:ty) do.
if. (k=tx{(<:ty){ban)*.(0=tx{(>:ty){ban) do. if. 0<+/k=(>:ty){ban do.
temp=.temp, (((# i.@$)k=(>:ty){ban),.(>:ty)),"1 tx,(>:ty) end.
if. 0<+/k=(ty-4){.tx{"1 ban do.
temp=.temp, (tx,. (# i.@$)k=tx{"1 ban),"1 tx,(>:ty) end.
end.
if. (k=tx{(>:ty){ban)*.(0=tx{(<:ty){ban) do. if. 0<+/k=(<:ty){ban do.
temp=.temp, (((# i.@$)k=(<:ty){ban),.(<:ty)),"1 tx,(<:ty) end.
if. 0<+/k=(ty-1){.tx{"1 ban do.
temp=.temp, (tx,. (# i.@$)k=tx{"1 ban),"1 tx,(<:ty) end.
end. end.
if. */0 0=tx,ty do.
if. (k=0{1{ban)*.(0=1{0{ban) do. if. 0<+/k=1{"1 ban do.
temp=.temp,(1,.(# i.@$)k=1{"1 ban),"1 (1 0) end.
if. 0<+/k=_4{.0{"1 ban do.
temp=.temp,(((# i.@$)k=_4{.0{"1 ban),.0),"1 (1 0) end.
end.
if. (k=1{0{ban)*.(0=0{1{ban) do. if. 0<+/k=1{ ban do.
temp=.temp,(((# i.@$)k=1{ ban),.1),"1 (0 1) end.
if. 0<+/k=_4{.0{ban do.
temp=.temp,(((# i.@$)k=_4{.0{ban),.0),"1 (0 1) end.
end. end.
if. */5 0=tx,ty do.
if. (k=5{1{ban)*.(0=4{0{ban) do. if. 0<+/k=4{"1 ban do.
temp=.temp,(4,.(# i.@$)k=4{"1 ban),"1 (4 0) end.
if. 0<+/k=4{.0{"1 ban do.
temp=.temp,(((# i.@$)k=4{.0{"1 ban),.0),"1 (4 0) end.
end.
if. (k=4{0{ban)*.(0=5{1{ban) do. if. 0<+/k=1{ ban do.
temp=.temp,(((# i.@$)k=1{ ban),.1),"1 (5 1) end.
if. 0<+/k=_4{.5{ban do.
temp=.temp,(5,.((# i.@$)k=_4{.5{"1 ban)),"1 (5 1) end.
end. end.
if. */0 5=tx,ty do.
if. (k=0{4{ban)*.(0=1{5{ban) do. if. 0<+/k=1{"1 ban do.
temp=.temp,(1,.(# i.@$)k=1{"1 ban),"1 (1 5) end.
if. 0<+/k=_4{.5{"1 ban do.
temp=.temp,(((# i.@$)k=_4{.5{"1 ban),.5),"1 (1 5) end.
end.
if. (k=1{5{ban)*.(0=0{4{ban) do. if. 0<+/k=4{ ban do.
temp=.temp,(((# i.@$)k=4{ban),.4),"1 (0 4) end.
if. 0<+/k=_4{.5{ban do.
temp=.temp,(0,.((# i.@$)k=4{.0{"1 ban)),"1 (0 4) end.
end. end.
if. */5 5=tx,ty do.
if. (k=5{4{ban)*.(0=4{5{ban) do. if. 0<+/k=1{"1 ban do.
temp=.temp,(4,.(# i.@$)k=4{"1 ban),"1 (4 5) end.
if. 0<+/k=_4{.5{"1 ban do.
temp=.temp,(((# i.@$)k=4{.5{"1 ban),.5),"1 (4 5) end.
end.
if. (k=4{5{ban)*.(0=5{4{ban) do. if. 0<+/k=4{ ban do.
temp=.temp,(((# i.@$)k=4{ ban),.4),"1 (5 4) end.
if. 0<+/k=_4{.5{ban do.
temp=.temp,(5,.((# i.@$)k=4{.5{"1 ban)),"1 (5 4) end.
end. end.
if. 0<#temp=.}.temp do. i=.0
for. i.#temp do.
if. x. IdoHantei (i{temp),k do. line=.line,i{temp end. i=.>:i end. end. 0<#}.line ) Tonari=: 4 : 0 t=.0 ban=.|.x. ’tx ty k’=.y. if. 5>:>:tx do.
if. (-k)=(>:tx){ty{ban do. t=.t-to1you end. if. k=(>:tx){ty{ban do. t=.t-to1me end. if. 5>:>:>:tx do.
if. (-k)=(>:>:tx){ty{ban do. t=.t-to2you end. if. k=(>:>:tx){ty{ban do. t=.t-to2me end. end.
if. 0<:<:ty do.
if. (-k)=(>:tx){(<:ty){ban do. t=.t-nayou end. if. k=(>:tx){(<:ty){ban do. t=.t-name end. end.
end.
if. 0<:<:tx do.
if. (-k)=(<:tx){ty{ban do. t=.t-to1you end. if. k=(<:tx){ty{ban do. t=t-to1me end. if. 0<:<:<:tx do.
if. (-k)=(<:<:tx){ty{ban do. t=.t-to2you end. if. k=(<:<:tx){ty{ban do. t=.t-to2me end. end.
if. 5>:>:ty do.
if. (-k)=(<:tx){(>:ty){ban do. t=.t-nayou end. if. k=(<:tx){(>:ty){ban do. t=.t-name end. end.
end.
if. 5>:>:ty do.
if. (-k)=tx{(>:ty){ban do. t=.t-to1you end. if. k=tx{(>:ty){ban do. t=.t-to1me end. if. 5>:>:>:ty do.
if. (-k)=tx{(>:>:ty){ban do. t=.t-to2you end. if. k=tx{(>:>:ty){ban do. t=.t-to2me end. end.
if. 5>:>:tx do.
if. (-k)=(>:tx){(>:ty){ban do. t=.t-nayou end. if. k=(>:tx){(>:ty){ban do. t=.t-name end. end.
end.
if. 0<:<:ty do.
if. (-k)=tx{(<:ty){ban do. t=.t-to1you end. if. k=tx{(<:ty){ban do. t=.t-to1me end. if. 0<:<:<:ty do.
if. (-k)=tx{(<:<:ty){ban do. t=.t-to2you end. if. k=tx{(<:<:ty){ban do. t=.t-to2me end. end.
if. 0<:<:tx do.
if. (-k)=(<:tx){(<:ty){ban do. t=.t-nayou end. if. k=(<:tx){(<:ty){ban do. t=.t-name end. end.
end.
if. 0 0 = tx,ty do. t=.t-kado end. if. 0 5 = tx,ty do. t=.t-kado end. if. 5 0 = tx,ty do. t=.t-kado end. if. 5 5 = tx,ty do. t=.t-kado end. t
)